
    @Oc                     Z    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e          Z	dS )    )TestCaseInTempDir)SamDB)LdbErrorERR_OPERATIONS_ERRORNc                   L     e Zd Z fdZ fdZd Zd Zd Zd Zd Z	d Z
 xZS )	SamDBApiTestCasec                 V    t          t          |                                            d S )N)superr   setUpself	__class__s    7/usr/lib/python3/dist-packages/samba/tests/samdb_api.pyr   zSamDBApiTestCase.setUp   s&    %%++-----    c                     |                      ddd           t          t          |                                            d S )Nztest.dbzexisting.dbT)allow_missing)rm_filesr
   r   tearDownr   s    r   r   zSamDBApiTestCase.tearDown   s>    idCCC%%..00000r   c                    | j         dz   }t          |d          }|                    d           |                                 	 t	          d|z              |                     d           n<# t          $ r/}|j        \  }}|                     |t                     Y d }~nd }~ww xY wt          |d          }|
                                }|                     d|           d S )N/existing.dbwzThis is not a tdb file!!!!!!
tdb://urlException not thrown r)tempdiropenwritecloser   failr   argsassertEqualr   readline)r   existing_nameexistingeerr_contentss          r   )test_dont_create_db_existing_non_tdb_filez:SamDBApiTestCase.test_dont_create_db_existing_non_tdb_file*   s    ~5s++7888	8h.////II-.... 	8 	8 	8vHS!S"677777777	8 s++$$&&98DDDDDs   (A. .
B'8%B""B'c                 (   | j         dz   }t          |d          }|                    d           |                                 t	          d|z   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*   s       r   )test_create_db_existing_file_non_tdb_filez:SamDBApiTestCase.test_create_db_existing_file_non_tdb_fileA   s    ~5t,,6777(]*!4444t,,$$&&11111r   c                 L   | j         dz   }t          d|z   d          }d}|                    |dd           |                    d|          }|                     d	|           t          d|z   
          }|                    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cnr8   %   test_dont_create_db_existing_tdb_filer   r   r   add	searchoner#   r   r%   initialr7   r8   seconds         r   r5   z6SamDBApiTestCase.test_dont_create_db_existing_tdb_fileT   s    ~5H}4A>>>;9
 
 	 	 	
 tR((A2FFF8m3444dB''A2FFFFFr   c                 N   | j         dz   }t          d|z   d          }d}|                    |dd           |                    d|          }|                     d	|           t          d|z   d          }|                    d|          }|                     d	|           d S )
Nr   r   r   r.   r4   r5   r6   r8   r9   r:   r=   s         r   %test_create_db_existing_file_tdb_filez6SamDBApiTestCase.test_create_db_existing_file_tdb_filek   s    ~5H}4A>>>;9
 
 	 	 	
 tR((A2FFF8m31===dB''A2FFFFFr   c                    	 t          d| j        z   dz              |                     d           n<# t          $ r/}|j        \  }}|                     |t                     Y d }~nd }~ww xY w	 t          | j        dz   d          }|                     d           d S # t          $ r0}|                     |j	        t          j
                   Y d }~d S d }~ww xY w)Nr   /test.dbr   r   r   zNew database file created)r   r   r!   r   r"   r#   r   r   IOErrorerrnoENOENT)r   e1r(   r)   filer'   s         r   test_dont_create_db_new_filez-SamDBApiTestCase.test_dont_create_db_new_file   s	   	8h-
:;;;;II-.... 	8 	8 	8wHS!S"677777777	8	4z1377DII122222 	4 	4 	4QWel333333333	4s,   03 
A,%A''A,0-B 
C)%CCc                     t          d| j        z   dz   d           t          | j        dz   d          }|                                }|                     d|           d S )Nr   rC   r   r.   r0   )moder1   )r   r   r   r$   r#   )r   r&   r*   s      r   test_create_db_new_filez(SamDBApiTestCase.test_create_db_new_file   sg    (T\)J6a@@@@z1===$$&&11111r   )__name__
__module____qualname__r   r   r+   r2   r5   rA   rI   rL   __classcell__)r   s   @r   r   r      s        . . . . .1 1 1 1 1E E E.
2 
2 
2&G G G.G G G*4 4 4(2 2 2 2 2 2 2r   r   )
samba.testsr   samba.samdbr   ldbr   r   osrE   r    r   r   <module>rV      s   & * ) ) ) ) )       . . . . . . . . 				 ~2 ~2 ~2 ~2 ~2( ~2 ~2 ~2 ~2 ~2r   