a
    œcl_§  ã                   @   sL   d dl mZ d dlmZ d dlmZmZ d dlZd dlZG dd„ deƒZ	dS )é    )ÚTestCaseInTempDir)ÚSamDB)ÚLdbErrorÚERR_OPERATIONS_ERRORNc                       sX   e Zd Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
‡  ZS )ÚSamDBApiTestCasec                    s   t t| ƒ ¡  d S )N)Úsuperr   ÚsetUp)Úself©Ú	__class__© ú7/usr/lib/python3/dist-packages/samba/tests/samdb_api.pyr      s    zSamDBApiTestCase.setUpc              
      s¦   zt  | jd ¡ W n4 tyH } z|  |jtj¡ W Y d }~n
d }~0 0 zt  | jd ¡ W n4 ty’ } z|  |jtj¡ W Y d }~n
d }~0 0 tt| ƒ 	¡  d S )Nú/test.dbú/existing.db)
ÚosÚremoveÚtempdirÚOSErrorÚassertEqualÚerrnoÚENOENTr   r   ÚtearDown)r	   Úer
   r   r   r      s    &&zSamDBApiTestCase.tearDownc              
   C   s    | j d }t|dƒ}| d¡ | ¡  ztd| d |  d¡ W n: ty| } z"|j\}}|  |t	¡ W Y d }~n
d }~0 0 t|dƒ}| 
¡ }|  d|¡ d S )Nr   ÚwzThis is not a tdb file!!!!!!
útdb://©ÚurlúException not thrown Úr)r   ÚopenÚwriteÚcloser   Úfailr   Úargsr   r   Úreadline)r	   Úexisting_nameÚexistingr   ÚerrÚ_Úcontentsr   r   r   Ú)test_dont_create_db_existing_non_tdb_file2   s    



"
z:SamDBApiTestCase.test_dont_create_db_existing_non_tdb_filec                 C   sX   | j d }t|dƒ}| d¡ | ¡  td| dd t|dƒ}| ¡ }|  d|¡ d S )	Nr   Úwbs   This is not a tdb file!!!!!!r   r   ©r   ÚflagsÚrbó	   TDB file
)r   r   r    r!   r   r$   r   )r	   r%   r&   r)   r   r   r   Ú)test_create_db_existing_file_non_tdb_fileI   s    



z:SamDBApiTestCase.test_create_db_existing_file_non_tdb_filec                 C   sp   | j d }td| dd}d}| |ddœ¡ | d|¡}|  d	|¡ td| d
}| d|¡}|  d	|¡ d S )Nr   r   r   r,   ú,dn=,cn=test_dont_create_db_existing_tdb_fileÚ%test_dont_create_db_existing_tdb_file©ÚdnÚcnr5   ó%   test_dont_create_db_existing_tdb_filer   ©r   r   ÚaddZ	searchoner   ©r	   r%   Úinitialr4   r5   Úsecondr   r   r   r2   \   s    
þz6SamDBApiTestCase.test_dont_create_db_existing_tdb_filec                 C   sr   | j d }td| dd}d}| |ddœ¡ | d|¡}|  d	|¡ td| dd}| d|¡}|  d	|¡ d S )
Nr   r   r   r,   r1   r2   r3   r5   r6   r7   r9   r   r   r   Ú%test_create_db_existing_file_tdb_files   s    
þz6SamDBApiTestCase.test_create_db_existing_file_tdb_filec              
   C   s¶   z"t d| j d d |  d¡ W n: ty\ } z"|j\}}|  |t¡ W Y d }~n
d }~0 0 zt| jd dƒ}|  d¡ W n4 ty° } z|  |j	t	j
¡ W Y d }~n
d }~0 0 d S )Nr   r   r   r   r   zNew database file created)r   r   r"   r   r#   r   r   r   ÚIOErrorr   r   )r	   Ze1r'   r(   Úfiler   r   r   r   Útest_dont_create_db_new_fileˆ   s    
"z-SamDBApiTestCase.test_dont_create_db_new_filec                 C   s@   t d| j d dd t| jd dd}| ¡ }|  d|¡ d S )Nr   r   r   r,   r.   )Úmoder/   )r   r   r   r$   r   )r	   r&   r)   r   r   r   Útest_create_db_new_fileœ   s    z(SamDBApiTestCase.test_create_db_new_file)Ú__name__Ú
__module__Ú__qualname__r   r   r*   r0   r2   r<   r?   rA   Ú__classcell__r   r   r
   r   r      s   r   )
Zsamba.testsr   Zsamba.samdbr   Zldbr   r   r   r   r   r   r   r   r   Ú<module>   s
   