o
    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 NRoot0001r
   r   )namepathdepthnumchild)r	   objectsget_or_createself r   i/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/images/tests/test_signal_handlers.pysetUp   s   
z&TestFilesDeletedForDefaultModels.setUpc                 C   s   t  / t jjddt d}|jj}| |jj	
| |  | |jj	
| W d    n1 s6w   Y  | |jj	
| d S )N
Test ImageA test descriptiontitledescription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  4 t jjddt d}|d}|jj}| 	|jj
| |  | 	|jj
| W d    n1 s;w   Y  | |jj
| d S )Nr   r   r   original)r   r!   r   r   r"   r   get_renditionr    r   r#   r$   r%   r&   r'   )r   r(   	renditionr)   r   r   r   $test_rendition_file_deleted_oncommit2   s   

zETestFilesDeletedForDefaultModels.test_rendition_file_deleted_oncommitN)__name__
__module____qualname____doc__r   r*   r.   r   r   r   r   r      s
    r   tests.CustomImage)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   register_signal_handlersr   r   r   r   r   C   s   
z%TestFilesDeletedForCustomModels.setUpc                 C   s&   t  }| |jj d|j d d S )N.r3   )r   assertEqual_meta	app_labelr/   )r   clsr   r   r   test_image_modelT   s    z0TestFilesDeletedForCustomModels.test_image_modelN)r/   r0   r1   r   r<   r   r   r   r   r5   A   s    r5   T)'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   	bad_imager   r   r   test_image_does_not_exista   s   z@TestRawForPreSaveImageFeatureDetection.test_image_does_not_existN)r/   r0   r1   fixturesrB   r   r   r   r   r>   Y   s    r>   N)	django.dbr   django.testr   r   r   wagtail.imagesr   r   wagtail.images.tests.utilsr   wagtail.modelsr	   utilsr   r   r5   r>   r   r   r   r   <module>   s    6