
    hH                     j    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
  G d de
j                        Zy)	    )SimpleUploadedFile)DjangoTemplates)ClearableFileInput)widgets)utilsc                   X     e Zd Z fdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Z xZS )ImageClearableFileInputc                 T    t         |           t        j                         | _        y N)supersetUptestTemporaryStoragestorageself	__class__s    R/home/dcms/DCMS/lib/python3.12/site-packages/easy_thumbnails/tests/test_widgets.pyr   zImageClearableFileInput.setUp   s    ,,.    c                 V    | j                   j                          t        |           y r   )r   delete_temporary_storager   tearDownr   s    r   r   z ImageClearableFileInput.tearDown   s    --/r   c                 h    t        j                         }| j                  |j                  ddi       y)zT
        If thumbnail options are not passed, default options will be used.
        size)P   r   Nr   r	   assertEqualthumbnail_options)r   widgets     r   test_options_defaultz,ImageClearableFileInput.test_options_default   s-     00211FH3EFr   c                     ddd}t        j                  |      }d|d<   | j                  |j                  ddd       y)z
        A dictionary can be passed as the thumbnail options. The dictionary is
        copied so it isn't just a mutable reference of the original.
        )i,  d   T)r   cropr   Fr#   Nr   )r   optionsr   s      r   test_options_customz+ImageClearableFileInput.test_options_custom   sH    
 &t4007K  $$z4&H	Jr   c                 t   | j                  | j                  d      }t        j                         }| j                  j	                  |      5 }| j                  |_        | j                  |_        |j                  d|      }ddd       | j                  |       | j                  d|       y# 1 sw Y   .xY w)zX
        The output contains a link to both the source image and the thumbnail.
        test.jpgphotoN.80x80_create_imager   r   r	   openthumbnail_storagerenderassertInr   source_filenamer   source_filehtmls        r   test_renderz#ImageClearableFileInput.test_render'   s     ++DLL*E002\\/ 	7;"&,,K,0LLK)==+6D	7
 	ot,i&	7 	7s   5B..B7c                    | j                  | j                  d      }dddd}t        j                  |      }| j                  j	                  |      5 }| j                  |_        | j                  |_        |j                  d|      }ddd       | j                  |       | j                  d	|       y# 1 sw Y   .xY w)
zV
        The thumbnail is generated using the options provided to the widget.
        r(   )r"   i  Z   T)r   qualityr#   r$   r)   Nz.100x500_q90_crop.jpgr+   )r   r2   r%   r   r3   r4   s         r    test_render_custom_thumb_optionsz8ImageClearableFileInput.test_render_custom_thumb_options6   s     ++DLL*E%"dC007K\\/ 	7;"&,,K,0LLK)==+6D	7
 	ot,-t4	7 	7s   5B66B?c                    | j                  | j                  d      }t        j                         }d|_        | j                  j                  |      5 }| j                  |_        | j                  |_        |j                  d|      }ddd       | j                  |       | j                  d|       | j                  d|       y# 1 sw Y   @xY w)z
        The template used to render the thumbnail and the standard
        ``ClearableFileInput`` output can be customized.
        r(   z<%(template)s<br /><a href="%(source_url)s">%(thumb)s</a> FOOr)   Nr*   FOO)	r,   r   r   r	   template_with_thumbnailr-   r.   r/   r0   r1   s        r   test_custom_templatez,ImageClearableFileInput.test_custom_templateF   s    
 ++DLL*E0029 	&
 \\/ 	7;"&,,K,0LLK)==+6D	7
 	ot,i&eT"	7 	7s   5CCc                    | j                  | j                  d      }t        j                         } G d dt              }| j                  j                  |      5 }| j                  |_        | j                  |_        |j                  d| |             }ddd       | j                  |       | j                  d|       | j                  d|       y# 1 sw Y   @xY w)	z
        The form renderer used to render the thumbnail and the standard
        ``ClearableFileInput`` output can be customized.
        r(   c                         e Zd Zd fd	Z xZS )DImageClearableFileInput.test_custom_renderer.<locals>.CustomRendererc                 0    t         |   |||      }|dz   S )Nz FOOBAR)r   r/   )r   template_namecontextrequestoutputr   s        r   r/   zKImageClearableFileInput.test_custom_renderer.<locals>.CustomRenderer.renderc   s     wH	))r   r   )__name__
__module____qualname__r/   __classcell__r   s   @r   CustomRendererr@   b   s    * *r   rK   r)   )rendererNr*   FOOBAR)	r,   r   r   r	   r   r-   r.   r/   r0   )r   r2   r   rK   r3   r4   s         r   test_custom_rendererz,ImageClearableFileInput.test_custom_renderer[   s    
 ++DLL*E002	*_ 	*
 \\/ 	R;"&,,K,0LLK)==+@P=QD	R
 	ot,i&h%	R 	Rs   <CCc                     t        j                         }t               }|j                  dd      }|j                  dd      }| j	                  ||       y)z8
        If value not passed, use super widget.
        r)   N)r   r	   r   r/   r   )r   r   base_widgetr4   	base_htmls        r   test_render_without_valuez1ImageClearableFileInput.test_render_without_valuep   sL     002(*}}Wd+&&w5	D)r   c                 ,   t        j                         }t               }d}| j                  d|      }t	        ||j                               }|j                  d|      }|j                  d|      }| j                  ||       | j                  ||       y)a  
        The widget treats UploadedFile as no input.

        Rationale:
        When widget is used in ModelForm and the form (submitted with upload)
        is not valid, widget should discard the value (just like standard
        Django ClearableFileInput does).
        r(   Nr)   )	r   r	   r   r,   r   getvaluer/   r   assertNotIn)r   r   rP   	file_nameimageupload_filer4   rQ   s           r   test_render_uploadedz,ImageClearableFileInput.test_render_uploadedz   s     002(*	!!$	2(ENN4DE}}Wk2&&w<	D)D)r   )rF   rG   rH   r   r   r    r&   r5   r9   r=   rN   rR   rY   rI   rJ   s   @r   r	   r	   	   s7    /GJ'5 #*&***r   r	   N)django.core.files.uploadedfiler   django.forms.renderersr   django.forms.widgetsr   easy_thumbnailsr   easy_thumbnails.testsr   r   BaseTestr	    r   r   <module>ra      s&    = 2 3 # /C*dmm C*r   