o
    &zhfQ                     @   s  d dl Z 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mZ eddddZG dd deZG dd deZG dd deZ G dd deZ!dS )    N)ImageKit)URL)BadRequestException)ForbiddenException)InternalServerException)NotFoundException)UnknownException)CopyFolderRequestOptions)CreateFolderRequestOptions)DeleteFolderRequestOptions)MoveFolderRequestOptions)camel_dict_to_snake_dict)ClientTestCasecreate_headers_for_testzprivate_fake:zpublic_fake123:zfake.com)private_key
public_keyurl_endpointc                   @   V   e Zd ZdZejdd Zejdd Zejdd Zejdd	 Z	ejd
d Z
dS )TestFolderszB
    TestFolders class used to test create and Delete folders
    c              
   C      dt _dt j}ztjtj|ddd | jjtdddd	 | 	t
 W dS  tyH } z| |jd
 | |jjd W Y d}~dS d}~ww )A
        Tests if the unauthenticated request restricted
        http://test.com{}/v1/folder  {'message': 'Your account cannot be authenticated.'
                                    , 'help': 'For support kindly contact us at support@imagekit.io .'}statusbodyfolder_name/testr   parent_folder_pathoptions%Your account cannot be authenticated.N)r   API_BASE_URLformat	responsesaddPOSTclientcreate_folderr
   assertRaisesr   r   assertEqualmessageresponse_metadatahttp_status_codeselfurle r5   P/var/www/html/kangema/venv/lib/python3.10/site-packages/tests/test_folder_ops.py3test_create_folder_fails_on_unauthenticated_request"   (   z?TestFolders.test_create_folder_fails_on_unauthenticated_requestc                 C   s   dt _dt j}t }tjtj|dd|d | jjt	dddd	}d
ddddi d}| 
t||jj | 
dtjd jj | 
dtjd jj dS )z1
        Tests if create_folder succeeds
        r   r      {})r   r   headersr   r   r    r"   
text/plaingzip, deflateBasic ZmFrZTEyMjo=Content-TypezAccept-EncodingAuthorizationr;   httpStatusCoderawhttp://test.com/v1/folderr   z:{"folderName": "folder_name", "parentFolderPath": "/test"}N)r   r%   r&   r   r'   r(   r)   r*   r+   r
   r-   r   r/   __dict__callsrequestr3   r   r2   r3   r;   respmock_response_metadatar5   r5   r6   test_create_folder_succeeds;   s2   
z'TestFolders.test_create_folder_succeedsc              
   C   r   )z7
        Tests if create folder fails with 400
        r   r     z{"message": "folderName parameter cannot have a slash.",
                                 "help": "For support kindly contact us at support@imagekit.io ."}r   r   r   r    r"   z)folderName parameter cannot have a slash.N)r   r%   r&   r'   r(   r)   r*   r+   r
   r,   r   r   r-   r.   r/   r0   r1   r5   r5   r6   !test_create_folder_fails_with_400^   r8   z-TestFolders.test_create_folder_fails_with_400c              
   C   s   dt _dt j}ztjtj|ddd | jjtddd | 	t
 W dS  t
yQ } z | d	|j | d|jj | d
|jjd  W Y d}~dS d}~ww )z7
        Tests if Delete folder fails with 400
        r   r     z{
                    "message": "No folder found with folderPath test",
                    "help": "For support kindly contact us at support@imagekit.io .",
                    "reason": "FOLDER_NOT_FOUND"
                }r   r   folder_pathr"   z$No folder found with folderPath testFOLDER_NOT_FOUNDreasonN)r   r%   r&   r'   r(   DELETEr*   delete_folderr   r,   r   r-   r.   r/   r0   rD   r1   r5   r5   r6   !test_delete_folder_fails_with_400w   s&   
"z-TestFolders.test_delete_folder_fails_with_400c                 C   s   dt _dt j}tjtj|ddd | jjtddd}d	dd
did}| 	t
||jj | 	dtjd jj | 	dtjd jj d	S )z1
        Tests if Delete folder succeeds
        r   r      r:   r   z/folderNamerP   r"   Nr@   r<   )rD   rC   r;   rE   r   z{"folderPath": "/folderName"})r   r%   r&   r'   r(   rT   r*   rU   r   r-   r   r/   rF   rG   rH   r3   r   )r2   r3   rJ   rK   r5   r5   r6   test_delete_folder_succeeds   s*   z'TestFolders.test_delete_folder_succeedsN)__name__
__module____qualname____doc__r'   activater7   rL   rN   rV   rX   r5   r5   r5   r6   r      s    

"

r   c                   @   r   )TestCopyFolderz7
    TestCopyFolder class used to test copy folder
    c              
   C   s   dt _dt j}ztjtj|ddd | jjtddddd	 | 	t
 W dS  t
yI } z| d
|j | d|jj W Y d}~dS d}~ww )z5
        Tests if Copy folder fails with 400
        r   {}/v1/bulkJobs/copyFolderrM   {
                    "message": "sourceFolderPath and destinationPath cannot be same.",
                    "help": "For support kindly contact us at support@imagekit.io ."
                }r   r   Fsource_folder_pathdestination_pathinclude_file_versionsr"   4sourceFolderPath and destinationPath cannot be same.N)r   r%   r&   r'   r(   r)   r*   copy_folderr	   r,   r   r-   r.   r/   r0   r1   r5   r5   r6   test_copy_folder_fails_with_400   s0   	z.TestCopyFolder.test_copy_folder_fails_with_400c              
   C   s   dt _dt j}ztjtj|ddd | jjtdddd	d
 | 	t
 W dS  t
yS } z | d|j | d|jj | d|jjd  W Y d}~dS d}~ww )z5
        Tests if Copy folder fails with 404
        r   r_   rO   {
                    "message": "No files & folder found at sourceFolderPath /test",
                    "help": "For support kindly contact us at support@imagekit.io .",
                    "reason": "NO_FILES_FOLDER"
                }r   r   /test1Fra   r"   1No files & folder found at sourceFolderPath /testNO_FILES_FOLDERrS   N)r   r%   r&   r'   r(   r)   r*   rf   r	   r,   r   r-   r.   r/   r0   rD   r1   r5   r5   r6   test_copy_folder_fails_with_404   s2   
"z.TestCopyFolder.test_copy_folder_fails_with_404c                 C      dt _dt j}tjtj|dd | jjtddddd	}d
didddid}t	
t	d}| d|j | t||jj | dtjd jj | |tjd jj dS )/
        Tests if Copy folder succeeds
        r   r_   %{"jobId": "62de84fb1b02a58936cc740c"}r   r   ri   Tra   r"   r@   r<      jobId62de84fb1b02a58936cc740crB   z{
                "sourceFolderPath": "/test",
                "destinationPath": "/test1",
                "includeFileVersions": true
            }&http://test.com/v1/bulkJobs/copyFolderr   Nr   r%   r&   r'   r(   r)   r*   rf   r	   jsondumpsloadsr-   job_idr   r/   rF   rG   rH   r3   r   r2   r3   rJ   rK   request_bodyr5   r5   r6   test_copy_folder_succeeds   @   	z(TestCopyFolder.test_copy_folder_succeedsc                 C   rm   )rn   r   r_   ro   rp   r   ri   Fra   r"   r@   r<   rq   rr   rs   rB   z{
                "sourceFolderPath": "/test",
                "destinationPath": "/test1",
                "includeFileVersions": false
            }rt   r   Nru   rz   r5   r5   r6   :test_copy_folder_succeeds_with_include_file_versions_false  r}   zITestCopyFolder.test_copy_folder_succeeds_with_include_file_versions_falsec                 C      dt _dt j}tjtj|dd | jjtdddd}d	d
idddid}t	
t	d}| d|j | t||jj | dtjd jj | |tjd jj dS )rn   r   r_   ro   rp   r   ri   rb   rc   r"   r@   r<   rq   rr   rs   rB   h{
                "sourceFolderPath": "/test",
                "destinationPath": "/test1"
            }rt   r   Nru   rz   r5   r5   r6   7test_copy_folder_succeeds_without_include_file_versionsJ  s>   zFTestCopyFolder.test_copy_folder_succeeds_without_include_file_versionsN)rY   rZ   r[   r\   r'   r]   rg   rl   r|   r~   r   r5   r5   r5   r6   r^      s    

 
*
*r^   c                   @   sH   e Zd ZdZejdd Zejdd Zejdd Zejdd	 Z	d
S )TestMoveFolderz7
    TestMoveFolder class used to test move folder
    c              
   C   s   dt _dt j}ztjtj|ddd | jjtdddd	 | 	t
 W dS  t
yH } z| |jd
 | d|jj W Y d}~dS d}~ww )r   r   {}/v1/bulkJobs/moveFolderr   r   r   r   ri   r   r"   r$   N)r   r%   r&   r'   r(   r)   r*   move_folderr   r,   r   r-   r.   r/   r0   r1   r5   r5   r6   1test_move_folder_fails_on_unauthenticated_requesty  r8   z@TestMoveFolder.test_move_folder_fails_on_unauthenticated_requestc              
   C   s   dt _dt j}ztjtj|ddd | jjtdddd | 	t
 W d
S  t
yH } z| d	|j | d|jj W Y d
}~d
S d
}~ww )z5
        Tests if Move folder fails with 400
        r   r   rM   r`   r   r   r   r"   re   N)r   r%   r&   r'   r(   r)   r*   r   r   r,   r   r-   r.   r/   r0   r1   r5   r5   r6   test_move_folder_fails_with_400  s,   	z.TestMoveFolder.test_move_folder_fails_with_400c              
   C   s   dt _dt j}ztjtj|ddd | jjtdddd	 | 	t
 W dS  t
yR } z | d
|j | d|jj | d|jjd  W Y d}~dS d}~ww )z5
        Tests if Move folder fails with 404
        r   r   rO   rh   r   r   ri   r   r"   rj   rk   rS   N)r   r%   r&   r'   r(   r)   r*   r   r   r,   r   r-   r.   r/   r0   rD   r1   r5   r5   r6   test_move_folder_fails_with_404  s.   
"z.TestMoveFolder.test_move_folder_fails_with_404c                 C   r   )z/
        Tests if Move folder succeeds
        r   r   ro   rp   r   ri   r   r"   r@   r<   rq   rr   rs   rB   r   z&http://test.com/v1/bulkJobs/moveFolderr   N)r   r%   r&   r'   r(   r)   r*   r   r   rv   rw   rx   r-   ry   r   r/   rF   rG   rH   r3   r   rz   r5   r5   r6   test_move_folder_succeeds  s<   z(TestMoveFolder.test_move_folder_succeedsN)
rY   rZ   r[   r\   r'   r]   r   r   r   r   r5   r5   r5   r6   r   t  s    


r   c                   @   s0   e Zd ZdZdZejdd Zejdd ZdS )TestGetBulkJobStatusz@
    TestGetBulkJobStatus class used to get bulk job status
    mock_job_idc              
   C   s   dt _dt j| j}ztjtj|ddd | j| j | 	t
 W dS  t
yF } z| d|j | d|jj W Y d}~dS d}~ww )7
        Tests if get_bulk_job_status succeeds
        r   {}/v1/bulkJobs/{}i  z{"message": "We have experienced an internal error while processing your request.",
                                 "help": "For support kindly contact us at support@imagekit.io ."}r   zDWe have experienced an internal error while processing your request.N)r   r%   r&   ry   r'   r(   GETr*   get_bulk_job_statusr,   r   r-   r.   r/   r0   r1   r5   r5   r6   'test_get_bulk_job_status_fails_with_500  s&   z<TestGetBulkJobStatus.test_get_bulk_job_status_fails_with_500c                 C   s   dt _dt j| j}t }tjtj|d|d | j	| j}ddddd	d
dddd}| 
t||jj | 
d
|j | 
d|j | 
d|j | 
dtjd jj dS )r   r   r   z{
                "jobId": "mock_job_id",
                "type": "COPY_FOLDER",
                "status": "Completed"
            })r   r;   r<   r=   r>   r?   rq   r   	CompletedCOPY_FOLDER)rr   r   typerB   z'http://test.com/v1/bulkJobs/mock_job_idr   N)r   r%   r&   ry   r   r'   r(   r   r*   r   r-   r   r/   rF   r   r   rG   rH   r3   rI   r5   r5   r6   !test_get_bulk_job_status_succeeds  s<   
z6TestGetBulkJobStatus.test_get_bulk_job_status_succeedsN)	rY   rZ   r[   r\   ry   r'   r]   r   r   r5   r5   r5   r6   r     s    
r   )"rv   r'   
imagekitior   imagekitio.constants.urlr   )imagekitio.exceptions.BadRequestExceptionr   (imagekitio.exceptions.ForbiddenExceptionr   -imagekitio.exceptions.InternalServerExceptionr   'imagekitio.exceptions.NotFoundExceptionr   &imagekitio.exceptions.UnknownExceptionr   *imagekitio.models.CopyFolderRequestOptionsr	   ,imagekitio.models.CreateFolderRequestOptionsr
   ,imagekitio.models.DeleteFolderRequestOptionsr   *imagekitio.models.MoveFolderRequestOptionsr   imagekitio.utils.formatterr   tests.helpersr   r   imagekit_objr   r^   r   r   r5   r5   r5   r6   <module>   s6      F 