o
    ^"<fU                     @   s  d dl Z d dlZd dlmZ d dlmZmZ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rAd d	lmZ nzd d	lmZ W n eyV   d dlZY nw d
d Z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G dd deZdS )    N)settings)ContextTemplateTemplateSyntaxError)patch)FilebrowserTestCase)
STRICT_PIL)utils)scale_and_cropprocess_image)Imagec                 K   
   d| _ | S NT)mark_1imkwargs r   J/var/www/html/kck/venv/lib/python3.10/site-packages/tests/test_versions.pyprocessor_mark_1      r   c                 K   r   r   )mark_2r   r   r   r   processor_mark_2   r   r   c                       sZ   e Zd Z fddZ fddZdd Zeddd	gd
d Zeddgdd Z  Z	S )ImageProcessorsTestsc                    s8   t t|   t| j| j d t_t	
| jj| _d S N)superr   setUpshutilcopySTATIC_IMG_PATHFOLDER_PATHr	   _default_processorsr   openF_IMAGE	path_fullr   self	__class__r   r   r   "   s   zImageProcessorsTests.setUpc                    s   t t|   d t_d S r   )r   r   tearDownr	   r!   r%   r'   r   r   r)   )   s   
zImageProcessorsTests.tearDownc                 C   s$   t | jddd}| |jd d S )N   )widthheightr*   w  )r   r   assertEqualsizer&   versionr   r   r   'test_process_image_calls_scale_and_crop-   s   z<ImageProcessorsTests.test_process_image_calls_scale_and_cropz$filebrowser.utils.VERSION_PROCESSORSz$tests.test_versions.processor_mark_1z$tests.test_versions.processor_mark_2c                 C   s0   t | ji }| t|d | t|d d S )Nr   r   )r   r   
assertTruehasattrr2   r   r   r   <test_process_image_calls_the_stack_of_processors_in_settings1   s   zQImageProcessorsTests.test_process_image_calls_the_stack_of_processors_in_settingsc                 C   s6   t | ji tgd}| t|d | t|d d S )N)
processorsr   r   )r   r   r   assertFalser6   r5   r2   r   r   r   :test_process_image_calls_only_explicit_provided_processors:   s   zOImageProcessorsTests.test_process_image_calls_only_explicit_provided_processors)
__name__
__module____qualname__r   r)   r4   r   r7   r:   __classcell__r   r   r'   r   r   !   s    
r   c                       s   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Z  ZS )-ScaleAndCropTestsc                    s2   t t|   t| j| j t| j	j
| _d S r   )r   r?   r   r   r   r   r    r   r"   r#   r$   r   r%   r'   r   r   r   D   s   zScaleAndCropTests.setUpc                 C   s&   t | jddd}| |j| jj d S Nr+   r
   r   r0   r1   r2   r   r   r   test_do_not_scaleJ   s   z#ScaleAndCropTests.test_do_not_scalec                 C   s@   | j j\}}t| j ||d}| || j  | |j||f d S r@   )r   r1   r
   assertIsr0   )r&   r,   r-   r3   r   r   r   6test_do_not_scale_if_desired_size_is_equal_to_originalN   s   zHScaleAndCropTests.test_do_not_scale_if_desired_size_is_equal_to_originalc                 C   s"   t | jddd}| |jd d S )Nr*   r+   r.   rA   r2   r   r   r   test_scale_widthT      z"ScaleAndCropTests.test_scale_widthc                 C   s"   t | jddd}| |jd d S )Nr+   r/   r.   rA   r2   r   r   r   test_scale_heightX      z#ScaleAndCropTests.test_scale_heightc                 C   s"   t | jddd}| || j d S )N  r+   r
   r   rC   r2   r   r   r   test_scale_no_upscale_too_wide]   rF   z0ScaleAndCropTests.test_scale_no_upscale_too_widec                 C   s"   t | jddd}| || j d S )Nr+   e  rJ   r2   r   r   r   test_scale_no_upscale_too_talla   rF   z0ScaleAndCropTests.test_scale_no_upscale_too_tallc                 C   s"   t | jddd}| || j d S )NrI   rL   r+   rJ   r2   r   r   r   'test_scale_no_upscale_too_wide_and_talle   rF   z9ScaleAndCropTests.test_scale_no_upscale_too_wide_and_tallc                 C   "   t | jddd}| |jd d S )NrI   r+   upscalerI   rL   rA   r2   r   r   r   test_scale_with_upscale_widthi   rF   z/ScaleAndCropTests.test_scale_with_upscale_widthc                 C   rO   )Nr+   rL   rP   rQ   rA   r2   r   r   r   test_scale_with_upscale_heightm   rF   z0ScaleAndCropTests.test_scale_with_upscale_heightc                 C   rO   )NrI   rL   rP   rQ   rA   r2   r   r   r   (test_scale_with_upscale_width_and_heightq   rF   z:ScaleAndCropTests.test_scale_with_upscale_width_and_heightc                 C   rO   )NrI   r   rP   rQ   rA   r2   r   r   r   -test_scale_with_upscale_width_and_zero_heightu   rF   z?ScaleAndCropTests.test_scale_with_upscale_width_and_zero_heightc                 C   rO   )Nr   rL   rP   rQ   rA   r2   r   r   r   -test_scale_with_upscale_zero_width_and_heighty   rF   z?ScaleAndCropTests.test_scale_with_upscale_zero_width_and_heightc                 C   rO   )Nr*   r+   rP   r.   rA   r2   r   r   r   3test_scale_with_upscale_width_too_small_for_upscale}   rF   zEScaleAndCropTests.test_scale_with_upscale_width_too_small_for_upscalec                 C   rO   )Nr+   r/   rP   r.   rA   r2   r   r   r   4test_scale_with_upscale_height_too_small_for_upscale   rF   zFScaleAndCropTests.test_scale_with_upscale_height_too_small_for_upscalec                 C   "   t | jddd}| |jd d S )Nr*   crop)r*   r*   rA   r2   r   r   r   test_crop_width_and_height   rF   z,ScaleAndCropTests.test_crop_width_and_heightc                 C   s"   t | jddd}| || j d S )NrI   rZ   rJ   r2   r   r   r   /test_crop_width_and_height_too_large_no_upscale   rH   zAScaleAndCropTests.test_crop_width_and_height_too_large_no_upscalec                 C   rY   )NrI   zcrop,upscale)rI   rI   rA   r2   r   r   r   1test_crop_width_and_height_too_large_with_upscale   rF   zCScaleAndCropTests.test_crop_width_and_height_too_large_with_upscalec                 C   rO   )Nr*   rL   r+   r.   rA   r2   r   r   r   /test_width_smaller_but_height_bigger_no_upscale      zAScaleAndCropTests.test_width_smaller_but_height_bigger_no_upscalec                 C   rO   )Nr*   rL   rP   r.   rA   r2   r   r   r   1test_width_smaller_but_height_bigger_with_upscale   rH   zCScaleAndCropTests.test_width_smaller_but_height_bigger_with_upscalec                 C   rO   )NrI   r/   r+   r.   rA   r2   r   r   r   /test_width_bigger_but_height_smaller_no_upscale   r_   zAScaleAndCropTests.test_width_bigger_but_height_smaller_no_upscalec                 C   rO   )NrI   r/   rP   r.   rA   r2   r   r   r   1test_width_bigger_but_height_smaller_with_upscale   rH   zCScaleAndCropTests.test_width_bigger_but_height_smaller_with_upscale)r;   r<   r=   r   rB   rD   rE   rG   rK   rM   rN   rR   rS   rT   rU   rV   rW   rX   r[   r\   r]   r^   r`   ra   rb   r>   r   r   r'   r   r?   C   s.    r?   c                	       s   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	e
dddddddidd Zdd Ze
dde
dddd Ze
dde
dddd Ze
dddd  Ze
ddd!d" Z  ZS )#VersionTemplateTagTestszcTest basic version uses

    Eg:
    {% version obj "large" %}
    {% version path "large" %}

    c                    >   t t|   t| j| j t| j	 t| j| j	 d S r   )
r   rc   r   r   r   r   r    osmakedirsPLACEHOLDER_PATHr%   r'   r   r   r         zVersionTemplateTagTests.setUpc                 C   $   |  tdd  |  tdd  d S )Nc                   S      t dS Nz,{% load fb_versions %}{% version obj.path %}r   r   r   r   r   <lambda>       z:VersionTemplateTagTests.test_wrong_token.<locals>.<lambda>c                   S   rj   Nz#{% load fb_versions %}{% version %}rl   r   r   r   r   rm      rn   assertRaisesr   r%   r   r   r   test_wrong_token      z(VersionTemplateTagTests.test_wrong_tokenc                 C   s0   t d}td| ji}||}| |d d S )Nz1{% load fb_versions %}{% version obj "invalid" %}objr+   )r   r   r#   renderr0   r&   tcrr   r   r   test_invalid_version   s   
z,VersionTemplateTagTests.test_invalid_versionc                 C   >   t d}t| jdd}||}| |tjtj	d d S )N0{% load fb_versions %}{% version path "large" %}"_test/uploads/folder/testimage.jpgrt   path*_test/_versions/folder/testimage_large.jpg
r   r   r#   ru   r0   re   r   joinr   	MEDIA_URLrv   r   r   r   test_hardcoded_path   s   
z+VersionTemplateTagTests.test_hardcoded_pathc                 C   <   t d}td| ji}||}| |tjtj	d d S )Nz/{% load fb_versions %}{% version obj "large" %}rt   r   r   rv   r   r   r   test_with_obj      
z%VersionTemplateTagTests.test_with_objc                 C   r   )Nz4{% load fb_versions %}{% version obj.path "large" %}rt   r   r   rv   r   r   r   test_with_obj_path   r   z*VersionTemplateTagTests.test_with_obj_pathz-filebrowser.templatetags.fb_versions.VERSIONSfixedheightzFixed heightr+   d   )verbose_namer,   r-   optsc                 C   r{   )Nz6{% load fb_versions %}{% version path "fixedheight" %}r}   r~   z0_test/_versions/folder/testimage_fixedheight.jpgr   rv   r   r   r   test_size_fixedheight      
z-VersionTemplateTagTests.test_size_fixedheightc                 C   r{   )Nr|   %_test/uploads/folder/testimagexxx.jpgr~   r+   r   rv   r   r   r   test_non_existing_path   r   z.VersionTemplateTagTests.test_non_existing_path5filebrowser.templatetags.fb_versions.SHOW_PLACEHOLDERT6filebrowser.templatetags.fb_versions.FORCE_PLACEHOLDERc                 C   r{   N3{% load fb_versions %}{% version obj.path suffix %}largert   suffix0_test/_versions/placeholders/testimage_large.jpgr   rv   r   r   r   *test_force_placeholder_with_existing_image      
zBVersionTemplateTagTests.test_force_placeholder_with_existing_imagec                 C   r{   r   
r   r   	F_MISSINGru   r0   re   r   r   r   r   rv   r   r   r   -test_force_placeholder_without_existing_image   r   zEVersionTemplateTagTests.test_force_placeholder_without_existing_imagec                 C   r{   )Nr   r   r   r   r   rv   r   r   r   -test_no_force_placeholder_with_existing_image   r   zEVersionTemplateTagTests.test_no_force_placeholder_with_existing_imagec                 C   r{   r   r   rv   r   r   r   0test_no_force_placeholder_without_existing_image   r   zHVersionTemplateTagTests.test_no_force_placeholder_without_existing_image)r;   r<   r=   __doc__r   rr   rz   r   r   r   r   dictr   r   r   r   r   r   r>   r   r   r'   r   rc      s*    

rc   c                       s   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	e
dde
dddd Ze
dddd Ze
dde
dddd Ze
dddd Z  ZS )VersionAsTemplateTagTestszTest variable version uses

    Eg:
    {% version obj "large" as version_large %}
    {% version path "large" as version_large %}

    c                    rd   r   )
r   r   r   r   r   r   r    re   rf   rg   r%   r'   r   r   r     rh   zVersionAsTemplateTagTests.setUpc                 C   \   t d}t| jdd}||}| |d jtjt	j
d | |tjt	j
d d S NX{% load fb_versions %}{% version path "large" as version_large %}{{ version_large.url }}r}   r~   version_larger   r   r   r#   ru   r0   urlre   r   r   r   r   rv   r   r   r   r     
   
z-VersionAsTemplateTagTests.test_hardcoded_pathc                 C   Z   t d}td| ji}||}| |d jtjt	j
d | |tjt	j
d d S Nz\{% load fb_versions %}{% version obj.path "large" as version_large %}{{ version_large.url }}rt   r   r   r   rv   r   r   r   test_obj_path!  
   
z'VersionAsTemplateTagTests.test_obj_pathc                 C   r   NzW{% load fb_versions %}{% version obj "large" as version_large %}{{ version_large.url }}rt   r   r   r   rv   r   r   r   r   (  r   z'VersionAsTemplateTagTests.test_with_objc                 C   r   NV{% load fb_versions %}{% version obj suffix as version_large %}{{ version_large.url }}r   r   r   r   r   rv   r   r   r   test_with_suffix_as_variable/  r   z6VersionAsTemplateTagTests.test_with_suffix_as_variablec                 C   r   Nr   r   r~   r   r+   r   rv   r   r   r   r   6  
   
z0VersionAsTemplateTagTests.test_non_existing_pathr   Tr   c                 C   r   Nr   r   r   r   r   r   rv   r   r   r   r   >  
   
zDVersionAsTemplateTagTests.test_force_placeholder_with_existing_imagec                 C   r   r   r   rv   r   r   r   r   G  r   zGVersionAsTemplateTagTests.test_no_force_placeholder_with_existing_imagec                 C   r   r   r   r   r   ru   r0   r   re   r   r   r   r   rv   r   r   r   .test_force_placeholder_with_non_existing_imageO  r   zHVersionAsTemplateTagTests.test_force_placeholder_with_non_existing_imagec                 C   r   r   r   rv   r   r   r   1test_no_force_placeholder_with_non_existing_imageX  r   zKVersionAsTemplateTagTests.test_no_force_placeholder_with_non_existing_image)r;   r<   r=   r   r   r   r   r   r   r   r   r   r   r   r   r>   r   r   r'   r   r   
  s$    
r   c                       s   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
eddedddd Zedddd Zeddedddd Zeddedddd Z  ZS )VersionObjectTemplateTagTestszTest version uses

    Eg:
    {% version obj "large" as version_large %}
    {% version path "large" as version_large %}

    c                    rd   r   )
r   r   r   r   r   r   r    re   rf   rg   r%   r'   r   r   r   i  rh   z#VersionObjectTemplateTagTests.setUpc                 C   ri   )Nc                   S   rj   rk   rl   r   r   r   r   rm   q  rn   z@VersionObjectTemplateTagTests.test_wrong_token.<locals>.<lambda>c                   S   rj   ro   rl   r   r   r   r   rm   r  rn   rp   r%   r   r   r   rr   p  rs   z.VersionObjectTemplateTagTests.test_wrong_tokenc                 C   r   r   r   rv   r   r   r   r   w  r   z1VersionObjectTemplateTagTests.test_hardcoded_pathc                 C   r   r   r   rv   r   r   r   r   ~  r   z+VersionObjectTemplateTagTests.test_obj_pathc                 C   r   r   r   rv   r   r   r   r     r   z+VersionObjectTemplateTagTests.test_with_objc                 C   r   r   r   rv   r   r   r   test_suffix_as_variable  r   z5VersionObjectTemplateTagTests.test_suffix_as_variablec                 C   r   r   r   rv   r   r   r   r     r   z4VersionObjectTemplateTagTests.test_non_existing_pathr   Tr   c                 C   r   r   r   rv   r   r   r   test_force_with_existing_image  r   z<VersionObjectTemplateTagTests.test_force_with_existing_imagec                 C   r   r   r   rv   r   r   r   !test_no_force_with_existing_image  r   z?VersionObjectTemplateTagTests.test_no_force_with_existing_imagec                 C   r   r   r   rv   r   r   r   "test_force_with_non_existing_image  r   z@VersionObjectTemplateTagTests.test_force_with_non_existing_imageFc                 C   r   r   r   rv   r   r   r   %test_no_force_with_non_existing_image  r   zCVersionObjectTemplateTagTests.test_no_force_with_non_existing_image)r;   r<   r=   r   r   rr   r   r   r   r   r   r   r   r   r   r   r>   r   r   r'   r   r   a  s(    
r   )re   r   django.confr   django.templater   r   r   mockr   testsr   TestCasefilebrowser.settingsr   filebrowserr	   filebrowser.utilsr
   r   PILr   ImportErrorr   r   r   r?   rc   r   r   r   r   r   r   <module>   s.   "h_W