U
    {h                     @   s   d dl mZ d dlmZmZmZ d dlmZmZ d dl	m
Z
 d dlmZ ddlmZ G dd	 d	eZed
dG dd deZeddG dd deZdS )    )transaction)TestCaseTransactionTestCaseoverride_settings)get_image_modelsignal_handlers)get_test_image_file)
Collection   )Imagec                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	 TestFilesDeletedForDefaultModelsa  
    Because we expect file deletion to only happen once a transaction is
    successfully committed, we must run these tests using TransactionTestCase
    per the following documentation:

        Django's TestCase class wraps each test in a transaction and rolls back that
        transaction after each test, in order to provide test isolation. This means
        that no transaction is ever actually committed, thus your on_commit()
        callbacks will never be run. If you need to test the results of an
        on_commit() callback, use a TransactionTestCase instead.
        https://docs.djangoproject.com/en/1.10/topics/db/transactions/#use-in-tests
    c                 C   s   t jjddddd d S NZRootZ0001r
   r   )namepathdepthZnumchild)r	   objectsget_or_createself r   q/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/images/tests/test_signal_handlers.pysetUp   s    z&TestFilesDeletedForDefaultModels.setUpc              	   C   sx   t  R t jjdt d}|jj}| |jj	
| |  | |jj	
| W 5 Q R X | |jj	
| d S )N
Test Imagetitlefile)r   atomicr   r   creater   r   r   
assertTruestorageexistsdeleteassertFalse)r   imagefilenamer   r   r    test_image_file_deleted_oncommit%   s    
 zATestFilesDeletedForDefaultModels.test_image_file_deleted_oncommitc              	   C   s   t  \ t jjdt d}|d}|jj}| 	|jj
| |  | 	|jj
| W 5 Q R X | |jj
| d S )Nr   r   original)r   r   r   r   r   r   Zget_renditionr   r   r   r   r    r!   r"   )r   r#   Z	renditionr$   r   r   r   $test_rendition_file_deleted_oncommit0   s    
 
zETestFilesDeletedForDefaultModels.test_rendition_file_deleted_oncommitN)__name__
__module____qualname____doc__r   r%   r'   r   r   r   r   r      s   r   tests.CustomImage)ZWAGTAILIMAGES_IMAGE_MODELc                   @   s   e Zd Zdd Zdd ZdS )TestFilesDeletedForCustomModelsc                 C   s    t jjddddd t  d S r   )r	   r   r   r   Zregister_signal_handlersr   r   r   r   r   ?   s    
z%TestFilesDeletedForCustomModels.setUpc                 C   s&   t  }| |jj d|j d d S )N.r,   )r   ZassertEqual_metaZ	app_labelr(   )r   clsr   r   r   test_image_modelP   s    z0TestFilesDeletedForCustomModels.test_image_modelN)r(   r)   r*   r   r1   r   r   r   r   r-   =   s   r-   T)Z'WAGTAILIMAGES_FEATURE_DETECTION_ENABLEDc                   @   s   e Zd ZdgZdd ZdS )&TestRawForPreSaveImageFeatureDetectionz	test.jsonc                 C   s*   t jjdd}| |jj|jj d S )Nr
   )pk)r   r   getr"   r   r   r    r   )r   Z	bad_imager   r   r   test_image_does_not_exist]   s    z@TestRawForPreSaveImageFeatureDetection.test_image_does_not_existN)r(   r)   r*   Zfixturesr5   r   r   r   r   r2   U   s   r2   N)Z	django.dbr   Zdjango.testr   r   r   Zwagtail.imagesr   r   Zwagtail.images.tests.utilsr   Zwagtail.modelsr	   utilsr   r   r-   r2   r   r   r   r   <module>   s   2