U
    {hP                     @   sp   d dl Z d dlZd dlmZ d dlmZ d dlmZmZ ddl	m
Z
 ddlmZmZ e ZG d	d
 d
eZdS )    N)StringIO)
management)TestCaseoverride_settings   )progress_bar   )Imageget_test_image_filec                   @   sl   e Zd ZedZedd Zdd Zdd Z	dd	 Z
d
d Zdd Zdd Zedddiiddd ZdS )TestUpdateImageRenditionsz
\x1b[^m]*mc              
   C   sB   t jjdtdddd| _tjj| jdddtddd	d
d| _d S )Nz
Test imageztest_image.pngwhite)filenamecolour)titlefileoriginal  ztest_rendition.png)r   r   )r   r   size)imageZfilter_specwidthheightr   )r	   objectscreater
   r   	Rendition	rendition)cls r   u/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/images/tests/test_management_commands.pysetUpTestData   s    
  z'TestUpdateImageRenditions.setUpTestDatac              	   C   sP   t j }|D ]<}z|j}|  W q tk
rH   td|  Y qX qd S )NzCould not delete rendition for )r   r   allr   delete	Exceptionwarningswarn)self
renditionsr   Zrendition_imager   r   r   delete_renditions#   s    
z+TestUpdateImageRenditions.delete_renditionsc                 K   s(   t  }tjdd|i| |d |S )Nwagtail_update_image_renditionsstdoutr   )r'   )r   r   Zcall_commandseek)r$   optionsoutputr   r   r   run_command,   s     
z%TestUpdateImageRenditions.run_commandc                 C   sr   d}t  }td|d D ]}t||d }|| q|d dddddd	d
ddddg
}| ||  d S )N
   r   r    zBProgress: [---->                                             ] 10%zBProgress: [--------->                                        ] 20%zBProgress: [-------------->                                   ] 30%zBProgress: [------------------->                              ] 40%zBProgress: [------------------------>                         ] 50%zBProgress: [----------------------------->                    ] 60%zBProgress: [---------------------------------->               ] 70%zBProgress: [--------------------------------------->          ] 80%zBProgress: [-------------------------------------------->     ] 90%zCProgress: [------------------------------------------------->] 100%)r   ranger   writer)   joinassertIngetvalue)r$   Ztotal_renditionoutcurrentZprogress_bar_outputZexpected_outputr   r   r   test_progress_bar5   s(    
z+TestUpdateImageRenditions.test_progress_barc                 C   s\   |    |  }| jd| }| |d | jdd}| jd| }| |d d S )Nr.   zNo image renditions found.
TZ
purge_only)r&   r,   REAESCsubreadassertEqual)r$   r+   output_stringr   r   r   "test_exits_early_for_no_renditionsL   s    z<TestUpdateImageRenditions.test_exits_early_for_no_renditionsc                 C   sh   t j }t|}|  }| jd| }| |d| d| d t j }t|}| || d S )Nr.   zRegenerating i rendition(s)
Progress: [------------------------------------------------->] 100%
Successfully processed  rendition(s)
	r   r   r   lenr,   r8   r9   r:   r;   r$   r%   total_renditionsr+   r<   Zrenditions_nowZtotal_renditions_nowr   r   r   test_image_renditionsX   s    

z/TestUpdateImageRenditions.test_image_renditionsc                 C   sl   t j }t|}| jdd}| jd| }| |d| d| d t j }t|}| |d d S )NTr7   r.   zPurging r>   r?   r   r@   rB   r   r   r   %test_image_renditions_with_purge_onlyj   s    

z?TestUpdateImageRenditions.test_image_renditions_with_purge_onlydefaultZBACKENDz-django.core.cache.backends.locmem.LocMemCache)ZCACHESc                 C   sj   t j }|  }| jd| }| d| d| |  }| jd| }| d| d| d S )Nr.   zSuccessfully processed r?   )r   r   countr,   r8   r9   r:   r2   )r$   rC   r+   r<   r   r   r    test_image_renditions_with_cache|   s    

 
 z:TestUpdateImageRenditions.test_image_renditions_with_cacheN)__name__
__module____qualname__recompiler8   classmethodr   r&   r,   r6   r=   rD   rE   r   rH   r   r   r   r   r      s   

		
r   )rL   r"   ior   Zdjango.corer   Zdjango.testr   r   Z3management.commands.wagtail_update_image_renditionsr   utilsr	   r
   Zget_rendition_modelr   r   r   r   r   r   <module>   s   