
    _f%                        d dl Z d dlZd dl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 d dlmZmZ d dlmZmZmZ d d	lmZmZ d d
l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# d dl$m%Z% d Z&d Z' G d de(          Z)ed             Z* G d d          Z+ G d de+e          Z, G d de+e          Z- G d d          Z. G d de.e+e          Z/ G d d e.e+e          Z0 G d! d"e.e+e          Z1 G d# d$e.e+e          Z2 G d% d&e+e          Z3 G d' d(e+e          Z4 G d) d*e+e          Z5 G d+ d,e+e          Z6 G d- d.e+e          Z7 G d/ d0e.e+e          Z8 G d1 d2e+e          Z9 G d3 d4e.e9          Z: G d5 d6e+e          Z; G d7 d8e.e;          Z< G d9 d:e;          Z= G d; d<e+e          Z> G d= d>e.e+e          Z? G d? d@e+e          Z@ G dA dBe+e          ZA G dC dDe+e          ZB G dE dFe+e          ZC G dG dHe+e          ZD G dI dJe+e          ZE G dK dLe+e          ZF G dM dNe+e          ZG G dO dPe.e+e          ZH G dQ dRe+e          ZI G dS dTe;          ZJdS )U    N)contextmanager)import_moduleSkipTest)patch)settings)call_commandCommandError)ContextOriginTemplate)override_settingsTestCaseget_script_prefixset_script_prefix)flush_offline_manifestget_offline_manifest)OfflineGenerationError)Command) default_offline_manifest_storage)get_mod_funcc               #   B   K   t          dd          D ]} dd| z  iV  d S )N      contentzOK %d!)range)is    O/var/www/html/env/lib/python3.11/site-packages/compressor/tests/test_offline.pyoffline_context_generatorr       s?      1a[[ ( ((Q,'''''( (    c               #   *   K   dt           j        iV  d S )N
STATIC_URL)r   r#    r!   r   static_url_context_generatorr%      s       ,
------r!   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	LazyScriptNamePrefixedUrla  
    Lazy URL with ``SCRIPT_NAME`` WSGI param as path prefix.

    .. code-block :: python

        settings.STATIC_URL = LazyScriptNamePrefixedUrl('/static/')

        # HTTP request to '/some/page/' without SCRIPT_NAME
        str(settings.STATIC_URL) == '/static/'

        # HTTP request to '/app/prefix/some/page/` with SCRIPT_NAME = '/app/prefix/'
        str(settings.STATIC_URL) == '/app/prefix/static/'

        # HTTP request to '/another/prefix/some/page/` with SCRIPT_NAME = '/another/prefix/'
        str(settings.STATIC_URL) == '/another/prefix/static/'

    The implementation is incomplete, all ``str`` methods must be overridden
    in order to work correctly with the rest of Django core.
    c                 b    |                      d          rt                      | dd          z   n| S )N/r   )
startswithr   selfs    r   __str__z!LazyScriptNamePrefixedUrl.__str__4   s2    151E1EO ""T!""X--4Or!   c                      t          |           S N)strr+   s    r   __unicode__z%LazyScriptNamePrefixedUrl.__unicode__7   s    4yyr!   c                 P    t                               t          |                     S r/   )r0   __hash__r+   s    r   r3   z"LazyScriptNamePrefixedUrl.__hash__:   s    ||CII&&&r!   c                 6     t          |           j        |i |S )zV
        Override ``.lstrip()`` method to make it work with ``{% static %}``.
        )r0   lstripr,   argskwargss      r   r5   z LazyScriptNamePrefixedUrl.lstrip=   s"      s4yy0000r!   c                 6     t          |           j        |i |S )zU
        Override ``.split()`` method to make it work with ``{% static %}``.
        )r0   splitr6   s      r   r:   zLazyScriptNamePrefixedUrl.splitC   s!     s4yy////r!   c                 6     t          |           j        |i |S )a;  Override ``.replace()`` to make it work with ``{% static %}``.

        In ``django.core.files.storage``, ``FileSystemStorage.url()`` passes
        this object to ``urllib.parse.urljoin``.

        In ``urllib.parse``, the function that calls ``replace()`` is
        ``_remove_unsafe_bytes_from_url()``.

        )r0   replacer6   s      r   r<   z!LazyScriptNamePrefixedUrl.replaceI   s"     !s4yy $1&111r!   N)
__name__
__module____qualname____doc__r-   r1   r3   r5   r:   r<   r$   r!   r   r'   r'      s{         (P P P  ' ' '1 1 10 0 0
2 
2 
2 
2 
2r!   r'   c              #   j   K   t                      }t          |            dV  t          |           dS )z
    Override ``SCRIPT_NAME`` WSGI param, yield, then restore its original value.

    :param new_prefix: New ``SCRIPT_NAME`` value.
    Nr   )
new_prefix
old_prefixs     r   script_prefixrD   V   s>       #$$Jj!!!	EEEj!!!!!r!   c                       e Zd ZdZdZdZdZdZdZdZ	d Z
d Zd	 Zd
 Zd Zd ZddZddZd Zd Zd Zd Zd Zd Zd Zd ZdS )OfflineTestCaseMixinzutf-8test_compressor_offline.html output)djangojinja2Nc                     t          j        t          j                  }t          j                            |d         d         d          j                  }t          j                            |d         d         d          j                  }|g|d         d<   |g|d         d<   |ddd}d j        v r fd|d<    j	         |j
         j	                     j        di | _         j                                         d	 j        v rt          j                            | j                   _        t           j         j        
          }t!          j         j         j                  5 }t'          |                                |           _        d d d            n# 1 swxY w Y   d j        v rt          j                            | j                   _         |d                     }t!          j         j         j                  5 }|                    |                                           _        d d d            d S # 1 swxY w Y   d S d S )Nr   DIRSr   T)	TEMPLATESCOMPRESS_ENABLEDCOMPRESS_OFFLINErK   c                  ,                                      S r/   )_get_jinja2_envr+   s   r   <lambda>z,OfflineTestCaseMixin.setUp.<locals>.<lambda>   s    ,,.. r!   COMPRESS_JINJA2_GET_ENVIRONMENTrJ   )nametemplate_nameencoding)originr$   )copydeepcopyr   rN   ospathjointemplates_direnginesadditional_test_settingsupdater   	__enter__rV   template_pathr   ioopenCHARSETr   readtemplatetemplate_path_jinja2from_stringtemplate_jinja2)r,   rN   django_template_dirjinja2_template_dirr   rY   file_
jinja2_envs   `       r   setUpzOfflineTestCaseMixin.setUpn   s    M("455	 gll9Q<+?+BDDVWW gll9Q<+?+BDDVWW 34	!V 34	!V # $ $
 
 t|## /... 1 (4$$T%BCCC!.!C!C1B!C!C((***t|##!#.A4CU!V!VD'"0  F +dlCCC Fu (f E E EF F F F F F F F F F F F F F F t|##(*#T%7) )D% N*+LMOOJ2T\JJJ Le'1'='=ejjll'K'K$L L L L L L L L L L L L L L L L L L $#s$   2)F''F+.F+-IIIc                     | j                             d d d            d}t          j        |          rt          j        |           d S d S )Nmanifest.json)r   __exit__r   existsdelete)r,   manifest_filenames     r   tearDownzOfflineTestCaseMixin.tearDown   s\    ''dD999++23DEE 	G,34EFFFFF	G 	Gr!   c                     t           j        }t          |t          t          f          s|g}|dk    rd |D             S |dk    r|S d S )NrJ   c                 ,    g | ]}t          |          S r$   r   .0cs     r   
<listcomp>z:OfflineTestCaseMixin._prepare_contexts.<locals>.<listcomp>   s    1111GAJJ111r!   rK   )r   COMPRESS_OFFLINE_CONTEXT
isinstancelisttupler,   enginecontextss      r   _prepare_contextsz&OfflineTestCaseMixin._prepare_contexts   s[    4(T5M22 	" zHX111111XOtr!   c                                            |          }|dk    r!d                     fd|D                       S |dk    r$d                     fd|D                       dz   S d S )NrJ   rH   c              3   L   K   | ]}j                             |          V  d S r/   )ri   renderr}   r~   r,   s     r   	<genexpr>z8OfflineTestCaseMixin._render_template.<locals>.<genexpr>   s3      EEq4=//22EEEEEEr!   rK   
c              3   L   K   | ]}j                             |          V  d S r/   )rl   r   r   s     r   r   z8OfflineTestCaseMixin._render_template.<locals>.<genexpr>   s4      NNT188;;NNNNNNr!   )r   r^   r   s   `  r   _render_templatez%OfflineTestCaseMixin._render_template   s    ))&11X77EEEEHEEEEEEX99NNNNXNNNNNQUUUtr!   c                 N    d                     t          j        | j        |          S )Nz+<script src="{}CACHE/js/{}.{}.js"></script>formatr   COMPRESS_URL_PLACEHOLDERexpected_basenamer,   hashs     r   _render_scriptz#OfflineTestCaseMixin._render_script   s'    ?FF-t/Et
 
 	
r!   c                 N    d                     t          j        | j        |          S )NzD<link rel="stylesheet" href="{}CACHE/css/{}.{}.css" type="text/css">r   r   s     r   _render_linkz!OfflineTestCaseMixin._render_link   s(    %v143I4   	
r!   r   c                     |                     |          dz                       t          j        t	          t          j                            S Nr   )r^   r<   r   r   r0   COMPRESS_URL)r,   result	separators      r   _render_resultz#OfflineTestCaseMixin._render_result   s>    v&&-66-s83H/I/I
 
 	
r!   r   c                      j         }t          |t          t          f          s|g}t	                                          |g|          \  }}                     t          |          |                                 fd|D             |                                |          }                     | 	                    |                     d S )Nr`   	verbosityc                 :    g | ]}                     |          S r$   r   )r}   hr,   s     r   r   z6OfflineTestCaseMixin._test_offline.<locals>.<listcomp>   s'    AAAQ$--a00AAAr!   )
expected_hashr   r   r   CompressCommandhandle_innerassertEquallenr   r   )r,   r   r   hashescountr   rendered_templates   `      r   _test_offlinez"OfflineTestCaseMixin._test_offline   s    #&4-00 	XF'))66H	 7 
 
v 	Ve,,,AAAA&AAA6JJJ 11&99*D,?,?,G,GHHHHHr!   c                 b    d| j         vrt          d          |                     d           d S )NrJ   /This test class does not support django engine.r   r`   r   r   r+   s    r   test_offline_djangoz(OfflineTestCaseMixin.test_offline_django   ;    4<''LMMM(+++++r!   c                 b    d| j         vrt          d          |                     d           d S )NrK   /This test class does not support jinja2 engine.r   r   r+   s    r   test_offline_jinja2z(OfflineTestCaseMixin.test_offline_jinja2   r   r!   c                 d    d| j         vrt          d          |                     dd           d S )NrJ   r   r   r   r   r   r+   s    r   test_offline_django_verbosity_1z4OfflineTestCaseMixin.test_offline_django_verbosity_1   =    4<''LMMM(a88888r!   c                 d    d| j         vrt          d          |                     dd           d S )NrK   r   r   r   r   r+   s    r   test_offline_jinja2_verbosity_1z4OfflineTestCaseMixin.test_offline_jinja2_verbosity_1   r   r!   c                 d    d| j         vrt          d          |                     dd           d S )NrJ   r      r   r   r+   s    r   test_offline_django_verbosity_2z4OfflineTestCaseMixin.test_offline_django_verbosity_2   r   r!   c                 d    d| j         vrt          d          |                     dd           d S )NrK   r   r   r   r   r+   s    r   test_offline_jinja2_verbosity_2z4OfflineTestCaseMixin.test_offline_jinja2_verbosity_2   r   r!   c                     dd l }ddlm}m} ddlm} |||j        j        g}|                                 }|	                    ||          }||j
        d<   |S )Nr   )url_forSpacelessExtension)CompressorExtension)
extensionsloaderr   )
jinja2.extcompressor.offline.jinja2r   r   compressor.contrib.jinja2extr   extdo_get_jinja2_loaderEnvironmentglobals)r,   rK   r   r   r   r   r   envs           r   rR   z$OfflineTestCaseMixin._get_jinja2_env   s    IIIIIIIIDDDDDD  JM


 ((**  Jv FF!(I
r!   c                 r    dd l }|                    t          j        d         d         | j                  }|S )Nr   r   rM   rW   )rK   FileSystemLoaderr   rN   rg   )r,   rK   r   s      r   r   z'OfflineTestCaseMixin._get_jinja2_loader	  s@    ((q!&)DL ) 
 
 r!   r   r   )r=   r>   r?   rg   rV   r_   r   r   r`   ra   rq   rx   r   r   r   r   r   r   r   r   r   r   r   r   rR   r   r$   r!   r   rF   rF   c   s>       G2MM M"G#3L 3L 3LjG G G    
 
 


 
 

 
 
 


I 
I 
I 
I, , ,
, , ,
9 9 9
9 9 9
9 9 9
9 9 9
  "    r!   rF   c                   B   e Zd ZdZdZ ej        ed          d             Z ej        ed          d             Z	 ej        ed          d             Z
 ej        ed          d             Zd Zd	 Zd
 Zd Zd Z ed ed                    d             ZdS )OfflineCompressBasicTestCasebasic822ac7501287compressc                     i dg f|_         t                                                       |                     |j        d           d S )Nr   )return_valuer   handler   
call_countr,   compress_mocks     r   test_handle_no_argsz0OfflineCompressBasicTestCase.test_handle_no_args  sG    %'BY"  """1155555r!   c                 <   |                      d          5  |                     t                    5  t                                                       d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     |j        d           d S )NF)rO   r   r   assertRaisesr
   r   r   r   r   r   s     r   test_handle_compress_disabledz:OfflineCompressBasicTestCase.test_handle_compress_disabled     ]]E]22 	+ 	+""<00 + +!!((***+ + + + + + + + + + + + + + +	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	11555554   A6!AA6A#	#A6&A#	'A66A:=A:c                 <   |                      d          5  |                     t                    5  t                                                       d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     |j        d           d S )NFrP   r   r   r   s     r   %test_handle_compress_offline_disabledzBOfflineCompressBasicTestCase.test_handle_compress_offline_disabled#  r   r   c                     i dg f|_         |                     d          5  t                                          d           d d d            n# 1 swxY w Y   |                     |j        d           d S )Nr   Fr   T)force)r   r   r   r   r   r   r   s     r   +test_handle_compress_offline_disabled_forcezHOfflineCompressBasicTestCase.test_handle_compress_offline_disabled_force*  s    %'BY"]]E]22 	1 	1$$4$000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	11155555s   #AAAc                     t                       |                     t          | j        j        t          i                      d S r/   )r   r   r   ri   r   r   r+   s    r   0test_rendering_without_manifest_raises_exceptionzMOfflineCompressBasicTestCase.test_rendering_without_manifest_raises_exception1  s9       0$-2FPRTTTTTr!   c                 n    t                       |                     t          | j        j        i            d S r/   )r   r   r   rl   r   r+   s    r   7test_rendering_without_manifest_raises_exception_jinja2zTOfflineCompressBasicTestCase.test_rendering_without_manifest_raises_exception_jinja26  s3       0$2F2MrRRRRRr!   c                    t                                          |gd          \  }}t                       d}t          j        |          rt          j        |           |                     d|           |                     |                     | j                  g|           | 	                    |          }|                     || 
                    |                     d S )Nr   r   rs   r   )r   r   r   r   ru   rv   r   r   r   r   r   )r,   r   r   r   rw   r   s         r   1_test_deleting_manifest_does_not_affect_renderingzNOfflineCompressBasicTestCase._test_deleting_manifest_does_not_affect_rendering;  s    '))66xST6UUv++23DEE 	G,34EFFFE"""$--d.@AABFKKK 11&99*D,?,?,G,GHHHHHr!   c                 D    | j         D ]}|                     |           d S r/   )r`   r   r,   r   s     r   0test_deleting_manifest_does_not_affect_renderingzMOfflineCompressBasicTestCase.test_deleting_manifest_does_not_affect_renderingF  s8    l 	K 	KFBB6JJJJ	K 	Kr!   c                 d   d}|                      |          5  ddlm} ddlm} t	                                                      }|                     t          |d         |                     |                     t          |d         |                     d d d            d S # 1 swxY w Y   d S )N)z%django.template.loaders.cached.Loader)z)django.template.loaders.filesystem.Loaderz.django.template.loaders.app_directories.Loader)TEMPLATE_LOADERSr   )Loaderr   )r   "django.template.loaders.filesystemr   'django.template.loaders.app_directoriesr   get_loaders
assertTruer   )r,   r   r   AppDirectoriesLoaderloaderss        r   test_get_loadersz-OfflineCompressBasicTestCase.test_get_loadersJ  s$   
 ]],<]== 	J 	JUUUUUU      &''3355GOOJwqz3CDDEEEOOJwqz3GHHIII	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	Js   A?B%%B),B)z2compressor.offline.django.DjangoParser.render_nodes   non-ascii character here:ä)side_effectc                     |                      t                    5  t                                          d           d d d            d S # 1 swxY w Y   d S )Nr   )r   )r   r
   r   r   )r,   mocks     r   !test_non_ascii_exception_messagesz>OfflineCompressBasicTestCase.test_non_ascii_exception_messages^  s    
 |,, 	2 	2$$q$111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s   #AAAN)r=   r>   r?   r_   r   r   objectr   r   r   r   r   r   r   r   r   r  	Exceptionr  r$   r!   r   r   r     s^       M"MU\/:..6 6 /.6
 U\/:..6 6 /.6 U\/:..6 6 /.6 U\/:..6 6 /.6U U U
S S S
	I 	I 	IK K KJ J J( U<IBCC  2 2	 2 2 2r!   r   c                       e Zd ZdZddZdS )%OfflineCompressSkipDuplicatesTestCasetest_duplicater   c                 X   t                                          |g|          \  }}|                     d|           |                     |                     d          g|           |                     |          }|                     ||                     |dz  d                     d S )Nr   r   r   r   rH   r   r   r   r   r   r   r,   r   r   r   r   r   s         r   r   z3OfflineCompressSkipDuplicatesTestCase._test_offlinej  s    '))66H	 7 
 
v 	E"""$--n==>GGG 11&99*D,?,?
B,O,OPPPPPr!   Nr   r=   r>   r?   r_   r   r$   r!   r   r	  r	  g  s3        $M
Q 
Q 
Q 
Q 
Q 
Qr!   r	  c                       e Zd ZdZdS )
SuperMixinrJ   N)r=   r>   r?   r`   r$   r!   r   r  r  w  s        GGGr!   r  c                       e Zd ZdZdZdS )!OfflineCompressBlockSuperTestCasetest_block_super817b5defb197Nr=   r>   r?   r_   r   r$   r!   r   r  r  |          &M"MMMr!   r  c                       e Zd ZdZdZdS ))OfflineCompressBlockSuperMultipleTestCasetest_block_super_multipled3f749e83c81Nr  r$   r!   r   r  r    s         0M"MMMr!   r  c                       e Zd ZdZdZddiZdS )5OfflineCompressBlockSuperMultipleCachedLoaderTestCase test_block_super_multiple_cached055f88f4751fr   r   Nr=   r>   r?   r_   r   ra   r$   r!   r   r  r    s,         7M"M 

 r!   r  c                       e Zd ZdZddZdS )1OfflineCompressBlockSuperTestCaseWithExtraContenttest_block_super_extrar   c                 z   t                                          |g|          \  }}|                     d|           |                     |                     d          |                     d          g|           |                     |          }|                     ||                     |d                     d S )Nr   r   bfcec76e0f28r  rH   r  r  s         r   r   z?OfflineCompressBlockSuperTestCaseWithExtraContent._test_offline  s    '))66H	 7 
 
v 	E"""  00$2E2En2U2UV	
 	
 	
 !11&99*D,?,?,K,KLLLLLr!   Nr   r  r$   r!   r   r"  r"    s5         -M
M 
M 
M 
M 
M 
Mr!   r"  c                   "    e Zd ZdZdZdddiiZdS ) OfflineCompressConditionTestCasetest_conditiona3275743dc69r   	conditionredNr   r$   r!   r   r'  r'    s/        $M"M"%
 r!   r'  c                       e Zd ZdZdZdS )"OfflineCompressTemplateTagTestCasetest_templatetag2bb88185b4f5Nr  r$   r!   r   r-  r-    r  r!   r-  c                       e Zd ZdZdZdS )(OfflineCompressStaticTemplateTagTestCasetest_static_templatetagbe0b1eade28bNr  r$   r!   r   r1  r1    s        -M"MMMr!   r1  c                       e Zd ZdZdZdZdS )'OfflineCompressTemplateTagNamedTestCasetest_templatetag_namedoutput_namer   N)r=   r>   r?   r_   r   r   r$   r!   r   r5  r5    s        ,M%"MMMr!   r5  c                   "    e Zd ZdZdZdddiiZdS )"OfflineCompressTestCaseWithContexttest_with_contextc6bf81bca7adr   r   OK!Nr   r$   r!   r   r9  r9    s/        'M"M"u%
 r!   r9  c                   "    e Zd ZdZdZdddiiZdS )'OfflineCompressTestCaseWithContextSupertest_with_context_superdd79e1bd1527r   r   r<  Nr   r$   r!   r   r>  r>    s1         .M"M"u%
 r!   r>  c                   J    e Zd ZdZg dZd e e                      iZd ZdS )&OfflineCompressTestCaseWithContextListr:  8b4a7452e1c555b3123e884cbfc63829cc58r   c                 b    |dk    rd t           j        D             S |dk    rt           j        S d S )NrJ   c                 ,    g | ]}t          |          S r$   r{   r|   s     r   r   zLOfflineCompressTestCaseWithContextList._prepare_contexts.<locals>.<listcomp>  s    JJJ1GAJJJJJr!   rK   )r   r   r   s     r   r   z8OfflineCompressTestCaseWithContextList._prepare_contexts  s=    XJJ(IJJJJX44tr!   N)	r=   r>   r?   r_   r   r   r    ra   r   r$   r!   r   rB  rB    sT        'MDDDM"DD)B)B)D)D$E$E     r!   rB  c                   D    e Zd ZdZg dZd e e                      iZdS )+OfflineCompressTestCaseWithContextListSuperr?  b39975a8f6eaed565a1d262f6ac9e4b29febr   N)r=   r>   r?   r_   r   r   r    ra   r$   r!   r   rJ  rJ    sC         .MDDDM"DD)B)B)D)D$E$E r!   rJ  c                   (    e Zd ZdZg dZddiZd ZdS )+OfflineCompressTestCaseWithContextGeneratorr:  rC  r   7compressor.tests.test_offline.offline_context_generatorc                     t          t          j                  \  }} t          t	          |          |                      }|dk    rd |D             S |dk    r|S d S )NrJ   c              3   4   K   | ]}t          |          V  d S r/   r{   r|   s     r   r   zPOfflineCompressTestCaseWithContextGenerator._prepare_contexts.<locals>.<genexpr>  s(      111GAJJ111111r!   rK   )r   r   r   getattrr   )r,   r   modulefunctionr   s        r   r   z=OfflineCompressTestCaseWithContextGenerator._prepare_contexts  sj    '(IJJ;7=00(;;==X111111XOtr!   N)r=   r>   r?   r_   r   ra   r   r$   r!   r   rP  rP    sC        'MDDDM" %$ 
    r!   rP  c                   "    e Zd ZdZg dZddiZdS )0OfflineCompressTestCaseWithContextGeneratorSuperr?  rK  r   rQ  Nr   r$   r!   r   rX  rX    s2         .MDDDM" %$ r!   rX  c                   ,    e Zd ZdZdZdZdddZd
dZd	S ),OfflineCompressStaticUrlIndependenceTestCasez
    Test that the offline manifest is independent of STATIC_URL.
    I.e. users can use the manifest with any other STATIC_URL in the future.
    test_static_url_independenceb0bfc3754fd4z/custom/static/url/:compressor.tests.test_offline.static_url_context_generator)r#   r   r   c                 ,   t                                          |g|          \  }}|                     d|           |                     |                     | j                  g|           |                     |                     |          |                     |                     |                     d          5  |                     |                     |          |                     |                     d d d            d S # 1 swxY w Y   d S )Nr   r   z/another/static/url/)r#   )r   r   r   r   r   r   r   r   r,   r   r   r   r   s        r   r   z:OfflineCompressStaticUrlIndependenceTestCase._test_offline%  sc   '))66H	 7 
 
v 	E"""$--d.@AABFKKK..v668K8KF8S8STTT ]]&<]== 	Y 	YT226::D<O<OPV<W<WXXX	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Ys   ?=D		DDNr   )r=   r>   r?   r@   r_   r   ra   r   r$   r!   r   rZ  rZ    sZ         
 3M"M+ I   Y Y Y Y Y Yr!   rZ  c                   4     e Zd ZdZdZdddiiZd fd	Z xZS )	5OfflineCompressTestCaseWithContextVariableInheritance&test_with_context_variable_inheritanceb8376aad1357r   parent_template	base.htmlr   c                 N    dt                                          ||          z   S r   )superr   )r,   r   r   	__class__s      r   r   zDOfflineCompressTestCaseWithContextVariableInheritance._render_result>  s"    egg,,VY????r!   r   )r=   r>   r?   r_   r   ra   r   __classcell__rh  s   @r   ra  ra  3  sh         =M"M"{%
 @ @ @ @ @ @ @ @ @ @r!   ra  c                   .    e Zd ZdZdddiddigiZddgZdS )	:OfflineCompressTestCaseWithContextVariableInheritanceSuper,test_with_context_variable_inheritance_superr   rd  z
base1.html
base2.htmlcee48db7cedcc877c436363aN)r=   r>   r?   r_   ra   r   r$   r!   r   rl  rl  B  sH         CM"!< "<	%
	  $^4MMMr!   rl  c                       e Zd ZdZddZdS )6OfflineCompressTestCaseWithContextGeneratorImportErrorr:  r   c                    |                      d          5  |                     t          t                      j        |g           d d d            n# 1 swxY w Y   |                      d          5  |                     t          t                      j        |g           d d d            n# 1 swxY w Y   |                      d          5  |                     t          t                      j        |g           d d d            n# 1 swxY w Y   |                      d          5  |                     t          t                      j        |g           d d d            n# 1 swxY w Y   d}|                      |          5  	 t                                          |g|           n%# t          $ r |                     d	           Y nw xY wd d d            d S # 1 swxY w Y   d S )
Nzinvalid_mod.invalid_func)r   )r`   
compressorz!compressor.tests.invalid_functionzcompressor.tests.test_offlinerQ  r   zCValid path to offline context generator must not raise ImportError.)r   r   ImportErrorr   r   fail)r,   r   r   
valid_paths       r   r   zDOfflineCompressTestCaseWithContextGeneratorImportError._test_offlineX  s_   
 ]]4N]OO 	 	_..;fX    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ]]L]AA 	 	_..;fX    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ]]%H  
 
 	 	 _..;fX    		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ]]4S]TT 	 	_..;fX    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 O
]]J]?? 		 		!!..x9.UUUU   		.    		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		s}   0AAA40B00B47B40DDD.0E**E.1E.G&$F43G&4GG&GG&&G*-G*Nr   r  r$   r!   r   rr  rr  S  s/         (M) ) ) ) ) )r!   rr  c                       e Zd ZdZddZdS )OfflineCompressTestCaseErrorstest_error_handlingr   c                 .   t                                          |g|          \  }}|dk    r|                     d|           n~|                     d|           |                     |d           |                     |                     d          |           |                     |                     d          |           |                     |                     d          |           |                     |                     d	          |           d S )
Nr   rJ   r   r   rK   187e2ce75808fffafcdf428eeeabdac292329a7f06880ce3)r   r   r   assertInr   r   r_  s        r   r   z+OfflineCompressTestCaseErrors._test_offline  s   '))66H	 7 
 
v XQ&&&& Q&&&VX...MM$++N;;VDDDMM$++N;;VDDDd)).996BBBd)).996BBBBBr!   Nr   r  r$   r!   r   ry  ry    s3        )MC C C C C Cr!   ry  c                   "    e Zd ZdZddiZddZdS ) OfflineCompressTestCaseWithErrorrz  COMPRESS_PRECOMPILERS))ztext/coffeescriptznonexisting-binaryr   c                    |                      d          5  |                     t          t                      j        |g|           ddd           n# 1 swxY w Y   |                      d          5  |                     t          t                      j        |g|           ddd           dS # 1 swxY w Y   dS )z
        Test that a CommandError is raised with DEBUG being False as well as
        True, as otherwise errors in configuration will never show in
        production.
        T)DEBUGr   NF)r   r   r
   r   r   r,   r   r   s      r   r   z.OfflineCompressTestCaseWithError._test_offline  sO    ]]]&& 	 	!!.#	    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ]]]'' 	 	!!.#	    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s#   1AAA51B33B7:B7Nr   r=   r>   r?   r_   ra   r   r$   r!   r   r  r    s;        )M!O      r!   r  c                   "    e Zd ZdZdZdZddZdS )OfflineCompressEmptyTaga  
    In case of a compress template tag with no content, an entry
    will be added to the manifest with an empty string as value.
    This test makes sure there is no recompression happening when
    compressor encounters such an emptystring in the manifest.
    r   r   r   c                     t                                          |g|           t                      }d|t          |          d         <   |                     |                     |          d           d S )Nr   rH   r   r   )r   r   r   r   r   r   )r,   r   r   manifests       r   r   z%OfflineCompressEmptyTag._test_offline  sm    &&x9&MMM'))&(h"#..v66=====r!   Nr   )r=   r>   r?   r@   r_   r   r   r$   r!   r   r  r    s>          M"M> > > > > >r!   r  c                   L     e Zd Zg dZdZg dZg dZdZ fdZd Z	d
d	Z
 xZS )'OfflineCompressBlockSuperBaseCompressed)re  rn  rG    test_block_super_base_compressed)e4e9263fa4c09cecd41a505fr  )028c3fc422322e9d3f5545a6r  r  c                     t                                                       g | _        g | _        | j        D ]}t
          j                            t          j	        d         d         d         |          }| j        
                    |           t          j        || j                  5 }t          |                                          }d d d            n# 1 swxY w Y   | j        
                    |           d S )Nr   rM   rW   )rg  rq   template_paths	templatestemplate_namesr\   r]   r^   r   rN   appendre   rf   rg   r   rh   )r,   rV   rd   ro   ri   rh  s        r   rq   z-OfflineCompressBlockSuperBaseCompressed.setUp  s    !0 	, 	,MGLL"1%f-a0- M &&}555>>> 2%#EJJLL112 2 2 2 2 2 2 2 2 2 2 2 2 2 2N!!(++++	, 	,s   *"CC	C	c                     |dk    r,|                     t          t          j                            S |dk    r"|                     t          j                  dz   S d S )NrJ   rK   r   )r   r   r   r   )r,   ri   r   s      r   r   z8OfflineCompressBlockSuperBaseCompressed._render_template  sT    X??78+L#M#MNNNx??8#DEELL4r!   r   c                    t                                          |g|          \  }}|                     t          | j                  |           t          | j        | j                  D ]p\  }}|                     |          }| 	                    ||           | 
                    ||          }|                     ||                     |g                     qd S )Nr   )r   r   r   r   r   zipexpected_hash_offliner  r   r  r   r   )	r,   r   r   r   r   r   ri   expectedr   s	            r   r   z5OfflineCompressBlockSuperBaseCompressed._test_offline  s    '))66H	 7 
 
v 	T/00%888'*4+Et~'V'V 	Q 	Q#M8**=99HMM(F+++ $ 5 5h G G.0C0CXJ0O0OPPPP		Q 	Qr!   r   )r=   r>   r?   r  r_   r  r   r`   rq   r   r   ri  rj  s   @r   r  r    s        PPPN6MLLLDDDMG, , , , ,  	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Qr!   r  c                   &    e Zd ZdZdddiiZddZdS )	%OfflineCompressInlineNonAsciiTestCasetest_inline_non_asciir   test_non_ascii_valueu   —r   c                     t                                          |g|          \  }}|                     |          }|                     |d                    |          dz              d S )Nr   rH   r   )r   r   r   r   r^   )r,   r   r   _r   r   s         r   r   z3OfflineCompressInlineNonAsciiTestCase._test_offline  so    #%%22H	 3 
 
	6 !11&99*BGGFOOd,BCCCCCr!   Nr   r  r$   r!   r   r  r    sH        +M""H%
 D D D D D Dr!   r  c                   (    e Zd ZdZddddiZd	dZdS )
OfflineCompressComplexTestCasetest_complexr   r<  )z	js/one.jszjs/nonasc.js)r*  my_namesr   c                    t                                          |g|          \  }}|                     d|           |                     |                     d          |                     d          |                     d          g|           |                     |          }|                     ||                     |d         |d         gd                     d S )	Nr      76a82cfab9ab7219642b8ab4567bb77b13dbr   r   rH   r  r  s         r   r   z,OfflineCompressComplexTestCase._test_offline  s    '))66H	 7 
 
v 	E"""##N33##N33##N33
 	
 	
 	
 !11&99t22F1Ivay3I2NN	
 	
 	
 	
 	
r!   Nr   r  r$   r!   r   r  r    sJ        "M" 6%
 %
 
 
 
 
 
 
r!   r  c                   J    e Zd ZdZdZg dZ ee          dd            ZdS )	'OfflineCompressExtendsRecursionTestCasez
    Test that templates extending templates with the same name
    (e.g. admin/index.html) don't cause an infinite test_extends_recursion
    test_extends_recursion)zdjango.contrib.adminzdjango.contrib.authzdjango.contrib.contenttypeszdjango.contrib.staticfilesrt  )INSTALLED_APPSr   c                     t                                          |g|          \  }}|                     |d           d S )Nr   r   )r   r   r   )r,   r   r   r   r  s        r   r   z5OfflineCompressExtendsRecursionTestCase._test_offline4  sB    "$$116(i1XXq"""""r!   Nr   )r=   r>   r?   r@   r_   r  r   r   r$   r!   r   r  r  $  se         
 -M  N n555# # # 65# # #r!   r  c                       e Zd ZdZdZdZdS )&OfflineCompressExtendsRelativeTestCasezu
    Test that templates extending templates using relative paths
    (e.g. ./base.html) are evaluated correctly
    test_extends_relativer  N)r=   r>   r?   r@   r_   r   r$   r!   r   r  r  :  s$         
 ,M"MMMr!   r  c                   &    e Zd ZdZddZd Zd ZdS )TestCompressCommandtest_compress_commandr   c                      t          d          )NzNot utilized for this test caser   r  s      r   r   z!TestCompressCommand._test_offlineI  s    8999r!   c                 D      fd|                                 D             S )Nc                 B    i | ]\  }}|                     |          S r$   r   )r}   kvr,   s      r   
<dictcomp>z@TestCompressCommand._build_expected_manifest.<locals>.<dictcomp>M  s-    GGGda4&&q))GGGr!   )items)r,   r  s   ` r   _build_expected_manifestz,TestCompressCommand._build_expected_manifestL  s'    GGGGhnn6F6FGGGGr!   c                    ddd}t          dddgi| t                      }|                     ddi          }|                     ||           t          ddd	gi| t                      }|                     d
di          }|                     ||           t          dddd	gi| t                      }|                     ddd          }|                     ||           d S )NTr   )r   r   r   r`   rJ   @0fed9c02607acba22316a328075a81a74e0983ae79470daa9d3707a337623dc30241107e9a9arK   @077408d23d4a829b8f88db2eadcf902b29d71b14f94018d900f38a3f8ed24c945694ca83dd14)r  r  )r   )r	   r   r  r   )r,   optsmanifest_djangomanifest_django_expectedmanifest_jinja2manifest_jinja2_expectedmanifest_bothmanifest_both_expecteds           r   test_multiple_enginesz)TestCompressCommand.test_multiple_enginesO  sD   
 

 	<<(<t<<<.00#'#@#@RTb$
 $
 
 	*BCCC<<(<t<<<.00#'#@#@RTb$
 $
 
 	*BCCCFF(H)=FFFF,..!%!>!>TbTb "
 "
 	(>?????r!   Nr   )r=   r>   r?   r_   r   r  r  r$   r!   r   r  r  F  sS        +M: : : :H H H @  @  @  @  @r!   r  c                   R    e Zd ZdZdZ ed           ed          ddZdZd
dZd	S ).OfflineCompressTestCaseWithLazyStringAlikeUrlsad  
    Test offline compressing with ``STATIC_URL`` and ``COMPRESS_URL`` as instances of
    *lazy string-alike objects* instead of strings.

    In particular, lazy string-alike objects that add ``SCRIPT_NAME`` WSGI param
    as URL path prefix.

    For example:

    - We've generated offline assets and deployed them with our Django project.
    - We've configured HTTP server (e.g. Nginx) to serve our app at two different URLs:
      ``http://example.com/my/app/`` and ``http://app.example.com/``.
    - Both URLs are leading to the same app, but in the first case we pass
      ``SCRIPT_NAME = /my/app/`` to WSGI app server (e.g. to uWSGI, which is *behind* Nginx).
    - Django (1.11.7, as of today) *ignores* ``SCRIPT_NAME`` when generating
      static URLs, while it uses ``SCRIPT_NAME`` when generating Django views URLs -
      see https://code.djangoproject.com/ticket/25598.
    - As a solution - we can use a lazy string-alike object instead of ``str`` for ``STATIC_URL``
      so it will know about ``SCRIPT_NAME`` and add it as a prefix every time we do any
      string operation with ``STATIC_URL``.
    - However, there are some cases when we cannot force CPython to render our lazy string
      correctly - e.g. ``some_string.replace(STATIC_URL, '...')``. So we need to do explicit
      ``str`` type cast: ``some_string.replace(str(STATIC_URL), '...')``.
    r2  /static/r]  )r#   r   r   r3  r   c                    t                                          |g|          \  }}|                     d|           dD ]}t          |          5  |                     t	          t
          j                  |                    d          dz              |                     t	          t
          j                  |                    d          dz              | 	                    |          }| 
                    |          }|                     ||           |                     t	          t
          j                  |           d d d            n# 1 swxY w Y   d S )Nr   r   )rH   z/app/prefix/z/another/prefix/r)   r  )r   r   r   rD   r0   r   r#   rstripr   r   r   r  )r,   r   r   r   r   script_nameexpected_resultactual_results           r   r   z<OfflineCompressTestCaseWithLazyStringAlikeUrls._test_offline  s   '))66H	 7 
 
v 	E""" D 	I 	IK{++ I I  +,,k.@.@.E.E
.R     -..0B0B30G0G*0T   #'"5"5f"="= $ 5 5f = =  @@@c("788-HHHI I I I I I I I I I I I I I I	I 	Is   C4EE	E	Nr   )	r=   r>   r?   r@   r_   r'   ra   r   r   r$   r!   r   r  r  r  su         2 .M//
;;11*== I    #MI I I I I Ir!   r  )KrZ   re   r\   
contextlibr   	importlibr   unittestr   unittest.mockr   django.confr   django.core.managementr	   r
   django.templater   r   r   django.testr   r   django.urlsr   r   compressor.cacher   r   compressor.exceptionsr   'compressor.management.commands.compressr   r   compressor.storager   compressor.utilsr   r    r%   r0   r'   rD   rF   r   r	  r  r  r  r  r"  r'  r-  r1  r5  r9  r>  rB  rJ  rP  rX  rZ  ra  rl  rr  ry  r  r  r  r  r  r  r  r  r  r$   r!   r   <module>r     s    				 				 % % % % % % # # # # # #                         = = = = = = = = 5 5 5 5 5 5 5 5 5 5 3 3 3 3 3 3 3 3 < < < < < < < < I I I I I I I I 8 8 8 8 8 8 N N N N N N ? ? ? ? ? ? ) ) ) ) ) )( ( (
. . .42 42 42 42 42 42 42 42n 	" 	" 	"l l l l l l l l^R2 R2 R2 R2 R2#7 R2 R2 R2jQ Q Q Q Q,@( Q Q Q        
# # # # #
4H( # # #
# # # # #$h# # #    $h  $M M M M M$hM M M$    ';X   # # # # #)=x # # #
# # # # #/CX # # #
# # # # #.BH # # #    )=x   	 	 	 	 	$h	 	 	    -A8       6      2F   $    ;  Y Y Y Y Y/Y Y YB@ @ @ @ @(@ @ @5 5 5 5 5$h5 5 5". . . . .(. . .bC C C C C$8( C C C0    ';X   :> > > > >2H > > >$'Q 'Q 'Q 'Q 'Q.BH 'Q 'Q 'QTD D D D D,@( D D D 
 
 
 
 
%98 
 
 
># # # # #.BH # # #,	# 	# 	# 	# 	#$h	# 	# 	#)@ )@ )@ )@ )@. )@ )@ )@X>I >I >I >I >I/>I >I >I >I >Ir!   