î
2!ìVh	  ã               @   sý   d  d l  m Z m 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 d  d	 l m Z d  d
 l m Z d  d l m Z Gd d „  d e ƒ Z e d d ƒ Gd d „  d e
 ƒ ƒ Z d S)é    )Úwith_statementÚunicode_literalsN)ÚContentFile)Úget_storage_class)ÚTestCase)Úoverride_settings)Ú
LazyObject)Ústorage)Úsettings)Úcss_tag)Úrenderc               @   s   e  Z d  Z d d „  Z d S)ÚGzipStoragec             C   s   t  d ƒ ƒ  |  _ d  S)Nz,compressor.storage.GzipCompressorFileStorage)r   Z_wrapped)Úself© r   úK/tmp/pip-build-0sboevxh/django-compressor/compressor/tests/test_storages.pyÚ_setup   s    zGzipStorage._setupN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r      s   r   ZCOMPRESS_ENABLEDTc               @   sL   e  Z d  Z d d „  Z d d „  Z d d „  Z d d „  Z d	 d
 „  Z d S)ÚStorageTestCasec             C   s   t  j |  _ t ƒ  t  _ d  S)N)r	   Údefault_storager   )r   r   r   r   ÚsetUp   s    zStorageTestCase.setUpc             C   s   |  j  t _  d  S)N)r   r	   )r   r   r   r   ÚtearDown   s    zStorageTestCase.tearDownc             C   ss   t  j j d t d ƒ ƒ |  j t j j t j j t	 j
 d ƒ ƒ ƒ |  j t j j t j j t	 j
 d ƒ ƒ ƒ d  S)Nztest.txtz	yeah yeahztest.txt.gz)r	   r   Úsaver   Z
assertTrueÚosÚpathÚexistsÚjoinr
   ZCOMPRESS_ROOT)r   r   r   r   Útest_gzip_storage   s    +z!StorageTestCase.test_gzip_storagec             C   s?   d } i t  j d 6} t d ƒ } |  j | t | | ƒ ƒ d  S)Na2  {% load compress %}{% compress css %}
        <link rel="stylesheet" href="{{ STATIC_URL }}css/one.css" type="text/css">
        <style type="text/css">p { border:5px solid white;}</style>
        <link rel="stylesheet" href="{{ STATIC_URL }}css/two.css" type="text/css">
        {% endcompress %}
        Z
STATIC_URLz"/static/CACHE/css/1d4424458f88.css)r
   ZCOMPRESS_URLr   ZassertEqualr   )r   ÚtemplateÚcontextÚoutr   r   r   Útest_css_tag_with_storage$   s    z)StorageTestCase.test_css_tag_with_storagec                s{   t  j ‰  ‡  f d d †  } zO | t  _ |  j j d t d ƒ ƒ |  j j d ƒ |  j |  j j d ƒ ƒ Wd  ˆ  t  _ Xd  S)Nc                s    ˆ  |  ƒ t  t j d ƒ ‚ d S)z=Patched os.remove to raise ENOENT (No such file or directory)zFake ENOENTN)ÚOSErrorÚerrnoÚENOENT)r   )Úoriginal_remover   r   Úrace_remove3   s    
zAStorageTestCase.test_race_condition_handling.<locals>.race_removez	race.filezFake ENOENT)r   Úremover   r   r   ÚdeleteZassertFalser   )r   r'   r   )r&   r   Útest_race_condition_handling/   s    		z,StorageTestCase.test_race_condition_handlingN)r   r   r   r   r   r   r"   r*   r   r   r   r   r      s
   r   )Ú
__future__r   r   r$   r   Zdjango.core.files.baser   Zdjango.core.files.storager   Zdjango.testr   Zdjango.test.utilsr   Zdjango.utils.functionalr   Z
compressorr	   Zcompressor.confr
   Zcompressor.tests.test_baser   Z"compressor.tests.test_templatetagsr   r   r   r   r   r   r   Ú<module>   s   