o
    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)imagefilter_specwidthheightr   )r	   objectscreater
   r   	Rendition	rendition)cls r   m/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/images/tests/test_management_commands.pysetUpTestData   s   
z'TestUpdateImageRenditions.setUpTestDatac              	   C   sL   t j }|D ]}z	|j}|  W q ty#   td|  Y qw d S )NzCould not delete rendition for )r   r   allr   delete	Exceptionwarningswarn)self
renditionsr   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   call_commandseek)r%   optionsoutputr   r   r   run_command,   s   
z%TestUpdateImageRenditions.run_commandc                 C   sb   d}t  }td|d D ]}t||d }|| q|d dg d}| ||  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%   total_renditionoutcurrentprogress_bar_output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 )Nr1   zNo image renditions found.
T
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 )Nr1   zRegenerating i rendition(s)
Progress: [------------------------------------------------->] 100%
Successfully processed  rendition(s)
	r   r   r    lenr/   r?   r@   rA   rB   r%   r&   total_renditionsr.   rC   renditions_now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 )NTr=   r1   zPurging rE   rF   r   rG   rI   r   r   r   %test_image_renditions_with_purge_onlyj   s   

z?TestUpdateImageRenditions.test_image_renditions_with_purge_onlydefaultBACKENDz-django.core.cache.backends.locmem.LocMemCache)CACHESc                 C   sj   t j }|  }| jd| }| d| d| |  }| jd| }| d| d| d S )Nr1   zSuccessfully processed rF   )r   r   countr/   r?   r@   rA   r5   )r%   rJ   r.   rC   r   r   r    test_image_renditions_with_cache|   s   
z:TestUpdateImageRenditions.test_image_renditions_with_cacheN)__name__
__module____qualname__recompiler?   classmethodr   r(   r/   r<   rD   rM   rN   r   rS   r   r   r   r   r      s    

		
r   )rW   r#   ior   django.corer   django.testr   r   3management.commands.wagtail_update_image_renditionsr   utilsr	   r
   get_rendition_modelr   r   r   r   r   r   <module>   s    