<s> from __future__ import unicode_literals <EOL> import os <EOL> import shutil <EOL> import tempfile <EOL> import hashlib <EOL> import unittest2 as unittest <EOL> import mock <EOL> from cactus . deployment . engine import BaseDeploymentEngine <EOL> from cactus . config . router import ConfigRouter <EOL> from cactus . deployment . file import BaseFile <EOL> from cactus . plugin . builtin . cache import CacheDurationPlugin <EOL> from cactus . plugin . loader import ObjectsPluginLoader <EOL> from cactus . plugin . manager import PluginManager <EOL> class TestHeadersPlugin ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . headers = None <EOL> def preDeployFile ( self , file ) : <EOL> self . file = file <EOL> class TestFile ( BaseFile ) : <EOL> def remote_changed ( self ) : <EOL> return True <EOL> def do_upload ( self ) : <EOL> pass <EOL> class TestDeploymentEngine ( BaseDeploymentEngine ) : <EOL> CredentialsManagerClass = lambda self , engine : None <EOL> class TestDeployFile ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . test_dir = tempfile . mkdtemp ( ) <EOL> self . build_path = os . path . join ( self . test_dir , '<STR_LIT>' ) <EOL> os . mkdir ( self . build_path ) <EOL> self . site = mock . MagicMock ( ) <EOL> self . site . plugin_manager = PluginManager ( self . site , [ ] ) <EOL> self . site . path = self . test_dir <EOL> self . site . build_path = self . build_path <EOL> self . site . config = ConfigRouter ( [ os . path . join ( self . test_dir , "<STR_LIT>" ) ] ) <EOL> self . site . config . set ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . engine = TestDeploymentEngine ( self . site ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . test_dir ) <EOL> def test_cache_control ( self ) : <EOL> """<STR_LIT>""" <EOL> content = '<STR_LIT:abc>' <EOL> h = hashlib . md5 ( content . encode ( '<STR_LIT:utf-8>' ) ) . hexdigest ( ) <EOL> filename = "<STR_LIT>" . format ( h ) <EOL> with open ( os . path . join ( self . build_path , filename ) , "<STR_LIT:w>" ) as f : <EOL> f . write ( content ) <EOL> p = TestHeadersPlugin ( ) <EOL> self . site . plugin_manager . loaders = [ ObjectsPluginLoader ( [ p , CacheDurationPlugin ( ) ] ) ] <EOL> self . site . plugin_manager . reload ( ) <EOL> self . site . plugin_manager . preDeploy ( self . site ) <EOL> f = TestFile ( self . engine , filename ) <EOL> f . upload ( ) <EOL> self . assertEqual ( p . file . cache_control , f . MAX_CACHE_EXPIRATION ) <EOL> with open ( os . path . join ( self . build_path , "<STR_LIT>" ) , "<STR_LIT:w>" ) as f : <EOL> f . write ( "<STR_LIT:abc>" ) <EOL> p = TestHeadersPlugin ( ) <EOL> self . site . plugin_manager . loaders = [ ObjectsPluginLoader ( [ p , CacheDurationPlugin ( ) ] ) ] <EOL> self . site . plugin_manager . reload ( ) <EOL> f = TestFile ( self . engine , "<STR_LIT>" ) <EOL> self . site . config . set ( "<STR_LIT>" , None ) <EOL> self . site . plugin_manager . preDeploy ( self . site ) <EOL> f . upload ( ) <EOL> self . assertEqual ( p . file . cache_control , f . DEFAULT_CACHE_EXPIRATION ) <EOL> self . site . config . set ( "<STR_LIT>" , <NUM_LIT> ) <EOL> self . site . plugin_manager . preDeploy ( self . site ) <EOL> f . upload ( ) <EOL> self . assertEqual ( p . file . cache_control , <NUM_LIT> ) </s>
