o
    Šågÿ.  ã                   @   s   d dl Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lm	Z	 ddlm
Z
 ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ G dd„ dejƒZG dd„ dejeƒZG dd„ dejƒZdZdS )é    Né   )Útestingé   )Úconfig)Úfixtures)Úutil)Úeq_)Úis_false)Úis_true)Úrequirements)ÚTableé   )ÚCheckConstraint)ÚColumn)ÚForeignKeyConstraint)ÚIndex)Úinspect)ÚInteger©Úschema)ÚString)ÚUniqueConstraintc                   @   s  e Zd ZdZddd„Zdd„ Zddd„Zd	d
„ Zej	e
jdd„ ƒƒZej	eje
jdd„ ƒƒƒZeje
jdd„ ƒƒZej	e
jdd„ ƒƒZeje
jdd„ ƒƒZeje
jdd„ ƒƒZeje
jdd„ ƒƒZeje
jdd„ ƒƒZeje
jdd„ ƒƒZeje
jdd„ ƒƒZdS ) ÚTableDDLTestTNc              	   C   s*   t d| jtdtddd�tdtdƒƒ|d�S )	NÚ
test_tableÚidTF©Úprimary_keyÚautoincrementÚdataé2   r   ©r   Úmetadatar   r   r   )Úselfr   © r#   ú]/var/www/html/flaskapp/venv/lib/python3.10/site-packages/sqlalchemy/testing/suite/test_ddl.pyÚ_simple_fixture"   s   ûzTableDDLTest._simple_fixturec              	   C   s&   t d| jtdtddd�tdtdƒƒƒS )NÚ_test_tabler   TFr   Ú_datar   r    )r"   r#   r#   r$   Ú_underscore_fixture+   s   üz TableDDLTest._underscore_fixturec                 C   s"   | j |d�}td|jjƒ}||fS )Nr   Ú
test_index)r%   r   Úcr   )r"   r   ÚtableÚidxr#   r#   r$   Ú_table_index_fixture3   s   z!TableDDLTest._table_index_fixturec                 C   s`   t j ¡ �!}| | ¡  d¡¡ | | ¡ ¡}t| ¡ dƒ W d   ƒ d S 1 s)w   Y  d S )N)r   z	some data)	r   ÚdbÚbeginÚexecuteÚinsertÚvaluesÚselectr   Úfirst)r"   r+   ÚconnÚresultr#   r#   r$   Ú_simple_roundtrip8   s
   "ýzTableDDLTest._simple_roundtripc                 C   ó&   |   ¡ }|jtjdd� |  |¡ d S ©NF©Ú
checkfirst)r%   Úcreater   r.   r7   ©r"   r+   r#   r#   r$   Útest_create_table>   ó   zTableDDLTest.test_create_tablec                 C   s,   | j tjd�}|jtjdd� |  |¡ d S )Nr   Fr:   )r%   r   Útest_schemar<   r.   r7   r=   r#   r#   r$   Útest_create_table_schemaE   s   z%TableDDLTest.test_create_table_schemac                 C   s,   |   ¡ }|jtjdd� |jtjdd� d S r9   )r%   r<   r   r.   Údropr=   r#   r#   r$   Útest_drop_tableM   s   zTableDDLTest.test_drop_tablec                 C   r8   r9   )r(   r<   r   r.   r7   r=   r#   r#   r$   Útest_underscore_namesT   r?   z"TableDDLTest.test_underscore_namesc                 C   sH   |   ¡ }|j|dd� d|_| t |¡¡ tt|ƒ d¡ddiƒ d S ©NFr:   z	a commentr   Útext)	r%   r<   Úcommentr0   r   ÚSetTableCommentr   r   Úget_table_comment©r"   Ú
connectionr+   r#   r#   r$   Útest_add_table_comment[   s   þz#TableDDLTest.test_add_table_commentc                 C   sX   |   ¡ }|j|dd� d|_| t |¡¡ | t |¡¡ tt|ƒ 	d¡dd iƒ d S rE   )
r%   r<   rG   r0   r   rH   ÚDropTableCommentr   r   rI   rJ   r#   r#   r$   Útest_drop_table_commentg   s   ÿz$TableDDLTest.test_drop_table_commentc                 C   sF   |   ¡ }| tj|dd�¡ tt|ƒ d¡ƒ | tj|dd�¡ d S )NT©Úif_not_existsr   )r%   r0   r   ÚCreateTabler
   r   Ú	has_tablerJ   r#   r#   r$   Útest_create_table_if_not_existss   s   z,TableDDLTest.test_create_table_if_not_existsc                 C   sž   |   ¡ \}}| tj|dd�¡ tt|ƒ d¡ƒ tddd„ t|ƒ d¡D ƒv ƒ | tj	|dd�¡ tddd„ t|ƒ d¡D ƒv ƒ | tj	|dd�¡ d S )NTrO   r   r)   c                 S   ó   g | ]}|d  ‘qS ©Únamer#   ©Ú.0Úixr#   r#   r$   Ú
<listcomp>†   ó    ÿÿz@TableDDLTest.test_create_index_if_not_exists.<locals>.<listcomp>c                 S   rT   rU   r#   rW   r#   r#   r$   rZ   �   r[   )
r-   r0   r   rQ   r
   r   rR   r	   Úget_indexesÚCreateIndex©r"   rK   r+   r,   r#   r#   r$   Útest_create_index_if_not_exists}   s&   þÿÿþÿÿz,TableDDLTest.test_create_index_if_not_existsc                 C   sb   |   ¡ }| |¡ tt|ƒ d¡ƒ | tj|dd�¡ tt|ƒ d¡ƒ | tj|dd�¡ d S )Nr   T©Ú	if_exists)	r%   r<   r
   r   rR   r0   r   Ú	DropTabler	   rJ   r#   r#   r$   Útest_drop_table_if_exists˜   s   
z&TableDDLTest.test_drop_table_if_existsc                 C   s‚   |   ¡ \}}| |¡ tddd„ t|ƒ d¡D ƒv ƒ | tj|dd�¡ tddd„ t|ƒ d¡D ƒv ƒ | tj|dd�¡ d S )Nr)   c                 S   rT   rU   r#   rW   r#   r#   r$   rZ   °   r[   z:TableDDLTest.test_drop_index_if_exists.<locals>.<listcomp>r   Tr`   c                 S   rT   rU   r#   rW   r#   r#   r$   rZ   º   r[   )	r-   r<   r
   r   r\   r0   r   Ú	DropIndexr	   r^   r#   r#   r$   Útest_drop_index_if_exists§   s$   
þÿÿþÿÿz&TableDDLTest.test_drop_index_if_exists)N)Ú__name__Ú
__module__Ú__qualname__Ú__backend__r%   r(   r-   r7   r   Úcreate_tabler   Úprovide_metadatar>   ÚschemasrA   Ú
drop_tablerC   rD   Úcomment_reflectionrL   rN   Útable_ddl_if_existsrS   Úindex_ddl_if_existsr_   rc   re   r#   r#   r#   r$   r      sJ    
	


r   c                   @   s   e Zd ZdS )ÚFutureTableDDLTestN)rf   rg   rh   r#   r#   r#   r$   rq   Ã   s    rq   c                   @   sr   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	e
jdddde
jj ¡ fde
jj ¡ fdd�dd„ ƒZdS )ÚLongNameBlowoutTestzjtest the creation of a variety of DDL structures and ensure
    label length limits pass on backends

    Tc           	      C   s¬   ddd  dd„ tdƒD ƒ¡ i}||_td|tdtd	d
�d	d� tdgdgƒ}td|tdƒ|d	d� |j}| |¡ t	j
jjrRt|ƒ}| d¡}|d d }||fS |d fS )NÚfkzGforeign_key_%(table_name)s_%(column_0_N_name)s_%(referred_table_name)s_Ú_c                 s   ó(   � | ]}d   dd„ tdƒD ƒ¡V  qdS )Ú c                 s   ó   � | ]}t  d ¡V  qdS ©ÚabcdefN©ÚrandomÚchoice©rX   Újr#   r#   r$   Ú	<genexpr>Ö   ó   € z3LongNameBlowoutTest.fk.<locals>.<genexpr>.<genexpr>é   N©ÚjoinÚrange©rX   Úir#   r#   r$   r   Õ   ó
   € ÿ
ÿz)LongNameBlowoutTest.fk.<locals>.<genexpr>é
   Úa_things_with_stuffÚid_long_column_nameT©r   )Útest_needs_fkÚaidz'a_things_with_stuff.id_long_column_nameÚb_related_things_of_valuer   rV   )rƒ   r„   Únaming_conventionr   r   r   r   rV   Ú
create_allr   ÚrequiresÚ&foreign_key_constraint_name_reflectionÚenabledr   Úget_foreign_keys)	r"   r!   rK   Ú
conventionÚconsÚactual_nameÚinspÚfksÚreflected_namer#   r#   r$   rs   Ï   sB   
þüÿüÿÿù	


zLongNameBlowoutTest.fkc           
   	   C   s€   ddd  dd„ tdƒD ƒ¡ i}||_td|tdtd	d
�tdtd	d
�ƒ}|j}|j}| |¡ t	|ƒ}| 
d¡}|d }	||	fS )NÚpkz.primary_key_%(table_name)s_%(column_0_N_name)srt   c                 s   ru   )rv   c                 s   rw   rx   rz   r}   r#   r#   r$   r     r€   z3LongNameBlowoutTest.pk.<locals>.<genexpr>.<genexpr>é   Nr‚   r…   r#   r#   r$   r     r‡   z)LongNameBlowoutTest.pk.<locals>.<genexpr>rˆ   r‰   rŠ   Tr‹   Úid_another_long_namerV   )rƒ   r„   r�   r   r   r   r   rV   r�   r   Úget_pk_constraint)
r"   r!   rK   r•   Úar–   r—   r˜   r›   rš   r#   r#   r$   r›   ý   s(   
þýÿ
ü

zLongNameBlowoutTest.pkc           
      C   sŽ   ddd  dd„ tdƒD ƒ¡ i}||_td|tdtd	d
�tdtƒƒ}td |jj|jj	ƒ}|j
}| |¡ t|ƒ}| d¡}|d d }	||	fS )NrY   z(index_%(table_name)s_%(column_0_N_name)srt   c                 s   ru   )rv   c                 s   rw   rx   rz   r}   r#   r#   r$   r     r€   z3LongNameBlowoutTest.ix.<locals>.<genexpr>.<genexpr>rœ   Nr‚   r…   r#   r#   r$   r     r‡   z)LongNameBlowoutTest.ix.<locals>.<genexpr>rˆ   r‰   rŠ   Tr‹   r�   r   rV   )rƒ   r„   r�   r   r   r   r   r*   rŠ   r�   rV   r�   r   r\   )
r"   r!   rK   r•   rŸ   r–   r—   r˜   rY   rš   r#   r#   r$   rY     s(   
þýÿ
ü

zLongNameBlowoutTest.ixc           	      C   s†   ddd  dd„ tdƒD ƒ¡ i}||_tddƒ}td	|tdtd
d�tdtƒ|ƒ |j}| |¡ t	|ƒ}| 
d	¡}|d d }||fS )NÚuqz4unique_constraint_%(table_name)s_%(column_0_N_name)srt   c                 s   ru   )rv   c                 s   rw   rx   rz   r}   r#   r#   r$   r   ;  r€   z3LongNameBlowoutTest.uq.<locals>.<genexpr>.<genexpr>rœ   Nr‚   r…   r#   r#   r$   r   :  r‡   z)LongNameBlowoutTest.uq.<locals>.<genexpr>rˆ   rŠ   r�   r‰   Tr‹   r   rV   )rƒ   r„   r�   r   r   r   r   rV   r�   r   Úget_unique_constraints)	r"   r!   rK   r•   r–   r—   r˜   r    rš   r#   r#   r$   r    5  s*   
þýÿ

û

zLongNameBlowoutTest.uqc           	      C   s„   ddd  dd„ tdƒD ƒ¡ i}||_tdƒ}td|td	td
d�tdtƒ|ƒ |j}| |¡ t	|ƒ}| 
d¡}|d d }||fS )NÚckzcheck_constraint_%(table_name)srt   c                 s   ru   )rv   c                 s   rw   rx   rz   r}   r#   r#   r$   r   W  r€   z3LongNameBlowoutTest.ck.<locals>.<genexpr>.<genexpr>rœ   Nr‚   r…   r#   r#   r$   r   V  r‡   z)LongNameBlowoutTest.ck.<locals>.<genexpr>rˆ   zsome_long_column_name > 5r‰   rŠ   Tr‹   Úsome_long_column_namer   rV   )rƒ   r„   r�   r   r   r   r   rV   r�   r   Úget_check_constraints)	r"   r!   rK   r•   r–   r—   r˜   r¢   rš   r#   r#   r$   r¢   R  s*   
þþÿ	û

zLongNameBlowoutTest.ck)rs   )r›   )rY   r¢   r    Útype_)Úargnamesc                 C   s„   t | |ƒ||ƒ\}}t|ƒdksJ ‚|d ur@|dt|ƒ… }t|ƒt|ƒk r9t|dd… |dt|ƒd … ƒ d S t||ƒ d S d S )Néÿ   r   éûÿÿÿé   )ÚgetattrÚlenr   )r"   r¥   r!   rK   r—   rš   Úoverlapr#   r#   r$   Útest_long_convention_namen  s   	ÿ&ûz-LongNameBlowoutTest.test_long_convention_nameN)rf   rg   rh   Ú__doc__ri   rs   r›   rY   r    r¢   r   Úcombinationsr‘   Úcheck_constraint_reflectionÚas_skipsÚunique_constraint_reflectionr­   r#   r#   r#   r$   rr   Ç   s"    .úrr   )r   rq   rr   )r{   rv   r   r   r   r   Ú
assertionsr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   ÚTestBaser   ÚFutureEngineMixinrq   rr   Ú__all__r#   r#   r#   r$   Ú<module>   s2    % ?