a
    [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_keyZautoincrementdata2   r   r   metadatar   r   r   )selfr    r"   o/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/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 )NZ_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    n1 sP0    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   s&   |   }|jtjdd | | d S NFZ
checkfirst)r$   creater   r,   r5   r!   r)   r"   r"   r#   test_create_table>   s    zTableDDLTest.test_create_tablec                 C   s,   | j tjd}|jtjdd | | d S )Nr   Fr7   )r$   r   Ztest_schemar8   r,   r5   r9   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 r6   )r$   r8   r   r,   Zdropr9   r"   r"   r#   test_drop_tableM   s    zTableDDLTest.test_drop_tablec                 C   s&   |   }|jtjdd | | d S r6   )r&   r8   r   r,   r5   r9   r"   r"   r#   test_underscore_namesT   s    z"TableDDLTest.test_underscore_namesc                 C   sH   |   }|j|dd d|_|t| tt|dddi d S NFr7   z	a commentr   text)	r$   r8   commentr.   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 r>   )
r$   r8   r@   r.   r   rA   ZDropTableCommentr   r   rB   rC   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Zif_not_existsr   )r$   r.   r   CreateTabler
   r   	has_tablerC   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 )NTrG   r   r'   c                 S   s   g | ]}|d  qS namer"   .0ixr"   r"   r#   
<listcomp>   s   z@TableDDLTest.test_create_index_if_not_exists.<locals>.<listcomp>c                 S   s   g | ]}|d  qS rK   r"   rM   r"   r"   r#   rP      s   )
r+   r.   r   rH   r
   r   rI   r	   get_indexesZCreateIndexr!   rD   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Z	if_exists)	r$   r8   r
   r   rI   r.   r   Z	DropTabler	   rC   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   s   g | ]}|d  qS rK   r"   rM   r"   r"   r#   rP      s   z:TableDDLTest.test_drop_index_if_exists.<locals>.<listcomp>r   TrT   c                 S   s   g | ]}|d  qS rK   r"   rM   r"   r"   r#   rP      s   )	r+   r8   r
   r   rQ   r.   r   Z	DropIndexr	   rR   r"   r"   r#   test_drop_index_if_exists   s$    
z&TableDDLTest.test_drop_index_if_exists)N)N)__name__
__module____qualname____backend__r$   r&   r+   r5   r   Zcreate_tabler   Zprovide_metadatar:   Zschemasr;   Z
drop_tabler<   r=   Zcomment_reflectionrE   rF   Ztable_ddl_if_existsrJ   Zindex_ddl_if_existsrS   rU   rV   r"   r"   r"   r#   r      sH   
	


r   c                   @   s   e Zd ZdS )FutureTableDDLTestN)rW   rX   rY   r"   r"   r"   r#   r[      s   r[   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rt|}|d}|d d }||fS |d fS d S )NfkzGforeign_key_%(table_name)s_%(column_0_N_name)s_%(referred_table_name)s__c                 s   s&   | ]}d  dd tdD V  qdS ) c                 s   s   | ]}t d V  qdS ZabcdefNrandomchoicerN   jr"   r"   r#   	<genexpr>       z3LongNameBlowoutTest.fk.<locals>.<genexpr>.<genexpr>   NjoinrangerN   ir"   r"   r#   rf      s   z)LongNameBlowoutTest.fk.<locals>.<genexpr>
   a_things_with_stuffid_long_column_nameTr   )Ztest_needs_fkZaidz'a_things_with_stuff.id_long_column_nameZb_related_things_of_valuer   rL   )rj   rk   naming_conventionr   r   r   r   rL   
create_allr   requiresZ&foreign_key_constraint_name_reflectionenabledr   Zget_foreign_keys)	r!   r    rD   
conventionconsactual_nameinspZfksreflected_namer"   r"   r#   r]      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)sr^   c                 s   s&   | ]}d  dd tdD V  qdS )r_   c                 s   s   | ]}t d V  qdS r`   ra   rd   r"   r"   r#   rf     rg   z3LongNameBlowoutTest.pk.<locals>.<genexpr>.<genexpr>   Nri   rl   r"   r"   r#   rf     s   z)LongNameBlowoutTest.pk.<locals>.<genexpr>rn   ro   rp   Trq   id_another_long_namerL   )rj   rk   rr   r   r   r   r   rL   rs   r   Zget_pk_constraint)
r!   r    rD   rv   arw   rx   ry   r{   rz   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 )NrO   z(index_%(table_name)s_%(column_0_N_name)sr^   c                 s   s&   | ]}d  dd tdD V  qdS )r_   c                 s   s   | ]}t d V  qdS r`   ra   rd   r"   r"   r#   rf     rg   z3LongNameBlowoutTest.ix.<locals>.<genexpr>.<genexpr>r|   Nri   rl   r"   r"   r#   rf     s   z)LongNameBlowoutTest.ix.<locals>.<genexpr>rn   ro   rp   Trq   r}   r   rL   )rj   rk   rr   r   r   r   r   r(   rp   r}   rL   rs   r   rQ   )
r!   r    rD   rv   r~   rw   rx   ry   rO   rz   r"   r"   r#   rO     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)sr^   c                 s   s&   | ]}d  dd tdD V  qdS )r_   c                 s   s   | ]}t d V  qdS r`   ra   rd   r"   r"   r#   rf   ;  rg   z3LongNameBlowoutTest.uq.<locals>.<genexpr>.<genexpr>r|   Nri   rl   r"   r"   r#   rf   :  s   z)LongNameBlowoutTest.uq.<locals>.<genexpr>rn   rp   r}   ro   Trq   r   rL   )rj   rk   rr   r   r   r   r   rL   rs   r   Zget_unique_constraints)	r!   r    rD   rv   rw   rx   ry   r   rz   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)sr^   c                 s   s&   | ]}d  dd tdD V  qdS )r_   c                 s   s   | ]}t d V  qdS r`   ra   rd   r"   r"   r#   rf   W  rg   z3LongNameBlowoutTest.ck.<locals>.<genexpr>.<genexpr>r|   Nri   rl   r"   r"   r#   rf   V  s   z)LongNameBlowoutTest.ck.<locals>.<genexpr>rn   zsome_long_column_name > 5ro   rp   Trq   Zsome_long_column_namer   rL   )rj   rk   rr   r   r   r   r   rL   rs   r   Zget_check_constraints)	r!   r    rD   rv   rw   rx   ry   r   rz   r"   r"   r#   r   R  s*    
	

zLongNameBlowoutTest.ck)r]   )r{   )rO   r   r   type_)argnamesc                 C   s~   t | |||\}}t|dks$J |d urz|dt| }t|t|k rpt|dd |dt|d   n
t|| d S )N   r      )getattrlenr   )r!   r   r    rD   rx   rz   overlapr"   r"   r#   test_long_convention_namen  s    	$z-LongNameBlowoutTest.test_long_convention_nameN)rW   rX   rY   __doc__rZ   r]   r{   rO   r   r   r   combinationsrt   Zcheck_constraint_reflectionZas_skipsZunique_constraint_reflectionr   r"   r"   r"   r#   r\      s    .r\   )r   r[   r\   )rb   r_   r   r   r   r   Z
assertionsr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   ZTestBaser   ZFutureEngineMixinr[   r\   __all__r"   r"   r"   r#   <module>	   s0    % ?