<s> import hashlib <EOL> import pickle <EOL> import time <EOL> import zlib <EOL> from datetime import datetime <EOL> from django . conf import settings <EOL> from django . utils . encoding import force_bytes <EOL> from django . utils . safestring import SafeText <EOL> from django . test . utils import override_settings <EOL> from django . utils . http import urlquote <EOL> from adv_cache_tag . compat import get_cache , template <EOL> from adv_cache_tag . tag import CacheTag <EOL> from . compat import TestCase <EOL> @ override_settings ( <EOL> DEBUG = False , <EOL> TEMPLATE_DEBUG = False , <EOL> CACHES = { <EOL> '<STR_LIT:default>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT:foo>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> } , <EOL> SECRET_KEY = '<STR_LIT>' , <EOL> ADV_CACHE_VERSIONING = False , <EOL> ADV_CACHE_COMPRESS = False , <EOL> ADV_CACHE_COMPRESS_SPACES = False , <EOL> ADV_CACHE_INCLUDE_PK = False , <EOL> ADV_CACHE_BACKEND = '<STR_LIT:default>' , <EOL> ADV_CACHE_VERSION = '<STR_LIT>' , <EOL> ADV_CACHE_RESOLVE_NAME = False , <EOL> TEMPLATES = [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> } , <EOL> ] <EOL> ) <EOL> class BasicTestCase ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def reload_config ( cls ) : <EOL> """<STR_LIT>""" <EOL> CacheTag . options . versioning = getattr ( settings , '<STR_LIT>' , False ) <EOL> CacheTag . options . compress = getattr ( settings , '<STR_LIT>' , False ) <EOL> CacheTag . options . compress_spaces = getattr ( settings , '<STR_LIT>' , False ) <EOL> CacheTag . options . include_pk = getattr ( settings , '<STR_LIT>' , False ) <EOL> CacheTag . options . cache_backend = getattr ( settings , '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> CacheTag . options . resolve_fragment = getattr ( settings , '<STR_LIT>' , False ) <EOL> CacheTag . RAW_TOKEN = '<STR_LIT>' + hashlib . sha1 ( <EOL> b'<STR_LIT>' + force_bytes ( hashlib . sha1 ( <EOL> b'<STR_LIT>' + force_bytes ( settings . SECRET_KEY ) <EOL> ) . hexdigest ( ) ) <EOL> ) . hexdigest ( ) <EOL> CacheTag . RAW_TOKEN_START = template . BLOCK_TAG_START + CacheTag . RAW_TOKEN + template . BLOCK_TAG_END <EOL> CacheTag . RAW_TOKEN_END = template . BLOCK_TAG_START + '<STR_LIT:end>' + CacheTag . RAW_TOKEN + template . BLOCK_TAG_END <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( BasicTestCase , self ) . setUp ( ) <EOL> for cache_name in settings . CACHES : <EOL> get_cache ( cache_name ) . clear ( ) <EOL> self . reload_config ( ) <EOL> self . obj = { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . get_name , <EOL> '<STR_LIT>' : self . get_foo , <EOL> '<STR_LIT>' : datetime ( <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> } <EOL> self . get_name_called = <NUM_LIT:0> <EOL> self . get_foo_called = <NUM_LIT:0> <EOL> def get_name ( self ) : <EOL> """<STR_LIT>""" <EOL> self . get_name_called += <NUM_LIT:1> <EOL> return self . obj [ '<STR_LIT:name>' ] <EOL> def get_foo ( self ) : <EOL> """<STR_LIT>""" <EOL> self . get_foo_called += <NUM_LIT:1> <EOL> return '<STR_LIT>' % self . get_foo_called <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> for cache_name in settings . CACHES : <EOL> get_cache ( cache_name ) . clear ( ) <EOL> super ( BasicTestCase , self ) . tearDown ( ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> """<STR_LIT>""" <EOL> cls . reload_config ( ) <EOL> super ( BasicTestCase , cls ) . tearDownClass ( ) <EOL> @ staticmethod <EOL> def get_template_key ( fragment_name , vary_on = None , prefix = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if vary_on is None : <EOL> vary_on = ( ) <EOL> key = '<STR_LIT::>' . join ( [ urlquote ( var ) for var in vary_on ] ) <EOL> args = hashlib . md5 ( force_bytes ( key ) ) <EOL> return ( prefix + '<STR_LIT>' ) % ( fragment_name , args . hexdigest ( ) ) <EOL> def render ( self , template_text , extend_context_dict = None ) : <EOL> """<STR_LIT>""" <EOL> context_dict = { '<STR_LIT>' : self . obj } <EOL> if extend_context_dict : <EOL> context_dict . update ( extend_context_dict ) <EOL> return template . Template ( template_text ) . render ( template . Context ( context_dict ) ) <EOL> def assertStripEqual ( self , first , second ) : <EOL> """<STR_LIT>""" <EOL> if first : <EOL> first = first . strip ( ) <EOL> if second : <EOL> second = second . strip ( ) <EOL> self . assertEqual ( first , second ) <EOL> def assertNotStripEqual ( self , first , second ) : <EOL> """<STR_LIT>""" <EOL> if first : <EOL> first = first . strip ( ) <EOL> if second : <EOL> second = second . strip ( ) <EOL> self . assertNotEqual ( first , second ) <EOL> def test_default_cache ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , self . obj [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> self . assertStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , expected ) <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> def test_adv_cache ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , self . obj [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> self . assertNotStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , expected ) <EOL> cache_expected = b"<STR_LIT>" <EOL> self . assertStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , cache_expected ) <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> def test_timeout_value ( self ) : <EOL> "<STR_LIT>" "<STR_LIT>" <EOL> ok_values = ( '<STR_LIT:0>' , '<STR_LIT:1>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:None>' ) <EOL> ko_values = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> t = """<STR_LIT>""" <EOL> for value in ok_values : <EOL> def test_value ( value ) : <EOL> self . render ( t % value ) <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> with self . subTest ( value = value ) : <EOL> test_value ( value ) <EOL> else : <EOL> test_value ( value ) <EOL> for value in ko_values : <EOL> def test_value ( value ) : <EOL> with self . assertRaises ( template . TemplateSyntaxError ) as raise_context : <EOL> self . render ( t % value ) <EOL> self . assertIn ( <EOL> '<STR_LIT>' , <EOL> str ( raise_context . exception ) <EOL> ) <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> with self . subTest ( value = value ) : <EOL> test_value ( value ) <EOL> else : <EOL> test_value ( value ) <EOL> def test_quoted_fragment_name ( self ) : <EOL> """<STR_LIT>""" <EOL> t = """<STR_LIT>""" <EOL> with self . assertRaises ( ValueError ) as raise_context : <EOL> self . render ( t ) <EOL> self . assertIn ( '<STR_LIT>' , str ( raise_context . exception ) ) <EOL> t = """<STR_LIT>""" <EOL> with self . assertRaises ( ValueError ) as raise_context : <EOL> self . render ( t ) <EOL> self . assertIn ( '<STR_LIT>' , str ( raise_context . exception ) ) <EOL> t = """<STR_LIT>""" <EOL> with self . assertRaises ( ValueError ) as raise_context : <EOL> self . render ( t ) <EOL> self . assertIn ( '<STR_LIT>' , str ( raise_context . exception ) ) <EOL> t = """<STR_LIT>""" <EOL> with self . assertRaises ( ValueError ) as raise_context : <EOL> self . render ( t ) <EOL> self . assertIn ( '<STR_LIT>' , str ( raise_context . exception ) ) <EOL> t = """<STR_LIT>""" <EOL> expected = "<STR_LIT>" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , '<STR_LIT:foo>' , self . obj [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> cache_expected = b"<STR_LIT>" <EOL> self . assertStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , cache_expected ) <EOL> t = """<STR_LIT>""" <EOL> expected = "<STR_LIT>" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , '<STR_LIT:bar>' , self . obj [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> cache_expected = b"<STR_LIT>" <EOL> self . assertStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , cache_expected ) <EOL> @ override_settings ( <EOL> ADV_CACHE_VERSIONING = True , <EOL> ) <EOL> def test_versioning ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reload_config ( ) <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> key = self . get_template_key ( '<STR_LIT>' , vary_on = [ self . obj [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> cache_expected = b"<STR_LIT>" <EOL> self . assertStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , cache_expected ) <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> self . obj [ '<STR_LIT>' ] = datetime ( <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:2> ) <EOL> cache_expected = b"<STR_LIT>" <EOL> self . assertStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , cache_expected ) <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:2> ) <EOL> @ override_settings ( <EOL> ADV_CACHE_INCLUDE_PK = True , <EOL> ) <EOL> def test_primary_key ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reload_config ( ) <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> key = self . get_template_key ( '<STR_LIT>' % self . obj [ '<STR_LIT>' ] , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , self . obj [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> cache_expected = b"<STR_LIT>" <EOL> self . assertStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , cache_expected ) <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> @ override_settings ( <EOL> ADV_CACHE_COMPRESS_SPACES = True , <EOL> ) <EOL> def test_space_compression ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reload_config ( ) <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , self . obj [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> cache_expected = b"<STR_LIT>" <EOL> self . assertEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , cache_expected ) <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> @ override_settings ( <EOL> ADV_CACHE_COMPRESS = True , <EOL> ) <EOL> def test_compression ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reload_config ( ) <EOL> expected = "<STR_LIT>" <EOL> t = "<STR_LIT>" "<STR_LIT>" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , self . obj [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> compressed = zlib . compress ( pickle . dumps ( SafeText ( "<STR_LIT>" ) ) ) <EOL> cache_expected = b'<STR_LIT>' + compressed <EOL> self . assertEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , cache_expected ) <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> @ override_settings ( <EOL> ADV_CACHE_COMPRESS = True , <EOL> ADV_CACHE_COMPRESS_SPACES = True , <EOL> ) <EOL> def test_full_compression ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reload_config ( ) <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , self . obj [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> compressed = zlib . compress ( pickle . dumps ( "<STR_LIT>" ) ) <EOL> cache_expected = b'<STR_LIT>' + compressed <EOL> self . assertEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , cache_expected ) <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> @ override_settings ( <EOL> ADV_CACHE_BACKEND = '<STR_LIT:foo>' , <EOL> ) <EOL> def test_cache_backend ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reload_config ( ) <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , self . obj [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> cache_expected = b"<STR_LIT>" <EOL> self . assertIsNone ( get_cache ( '<STR_LIT:default>' ) . get ( key ) ) <EOL> self . assertStripEqual ( get_cache ( '<STR_LIT:foo>' ) . get ( key ) , cache_expected ) <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> @ override_settings ( <EOL> ADV_CACHE_COMPRESS_SPACES = True , <EOL> ) <EOL> def test_partial_cache ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reload_config ( ) <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . get_foo_called , <NUM_LIT:1> ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , self . obj [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> cache_expected = b"<STR_LIT>" b"<STR_LIT>" <EOL> self . assertStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , cache_expected ) <EOL> expected = "<STR_LIT>" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . get_foo_called , <NUM_LIT:2> ) <EOL> def test_new_class ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t , { '<STR_LIT>' : <NUM_LIT:10> } ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . get_foo_called , <NUM_LIT:1> ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , self . obj [ '<STR_LIT>' ] ] , <EOL> prefix = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> cache_expected = b"<STR_LIT>" b"<STR_LIT>" <EOL> self . assertStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , cache_expected ) <EOL> cache = get_cache ( '<STR_LIT:default>' ) <EOL> expire_at = cache . _expire_info [ cache . make_key ( key , version = None ) ] <EOL> now = time . time ( ) <EOL> self . assertTrue ( now + <NUM_LIT:1> < expire_at < now + <NUM_LIT:10> ) <EOL> expected = "<STR_LIT>" <EOL> self . assertStripEqual ( self . render ( t , { '<STR_LIT>' : <NUM_LIT:10> } ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . get_foo_called , <NUM_LIT:2> ) <EOL> @ override_settings ( <EOL> ADV_CACHE_RESOLVE_NAME = True , <EOL> ) <EOL> def test_resolve_fragment_name ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reload_config ( ) <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t , { '<STR_LIT>' : '<STR_LIT>' } ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , self . obj [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> self . assertNotStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , expected ) <EOL> cache_expected = b"<STR_LIT>" <EOL> self . assertStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , cache_expected ) <EOL> self . assertStripEqual ( self . render ( t , { '<STR_LIT>' : '<STR_LIT>' } ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> t = """<STR_LIT>""" <EOL> with self . assertRaises ( template . VariableDoesNotExist ) as raise_context : <EOL> self . render ( t , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertIn ( '<STR_LIT>' , str ( raise_context . exception ) ) <EOL> @ override_settings ( <EOL> ADV_CACHE_RESOLVE_NAME = True , <EOL> ) <EOL> def test_passing_fragment_name_as_string ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reload_config ( ) <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , self . obj [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> self . assertNotStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , expected ) <EOL> cache_expected = b"<STR_LIT>" <EOL> self . assertStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , cache_expected ) <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> def test_using_argument ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , self . obj [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> cache_expected = b"<STR_LIT>" <EOL> self . assertIsNone ( get_cache ( '<STR_LIT:default>' ) . get ( key ) ) <EOL> self . assertStripEqual ( get_cache ( '<STR_LIT:foo>' ) . get ( key ) , cache_expected ) <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> @ override_settings ( <EOL> ADV_CACHE_COMPRESS_SPACES = True , <EOL> ) <EOL> def test_loading_libraries_in_nocache ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reload_config ( ) <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . get_foo_called , <NUM_LIT:1> ) <EOL> expected = "<STR_LIT>" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> self . assertEqual ( self . get_name_called , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . get_foo_called , <NUM_LIT:2> ) <EOL> def test_failure_when_setting_cache ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , self . obj [ '<STR_LIT>' ] ] , <EOL> prefix = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> self . assertIsNone ( get_cache ( '<STR_LIT:default>' ) . get ( key ) ) <EOL> with override_settings ( TEMPLATE_DEBUG = True ) : <EOL> with self . assertRaises ( ValueError ) as raise_context : <EOL> self . render ( t ) <EOL> self . assertIn ( '<STR_LIT>' , str ( raise_context . exception ) ) <EOL> def test_failure_when_getting_cache ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = "<STR_LIT>" <EOL> t = """<STR_LIT>""" <EOL> self . assertStripEqual ( self . render ( t ) , expected ) <EOL> key = self . get_template_key ( '<STR_LIT>' , <EOL> vary_on = [ self . obj [ '<STR_LIT>' ] , self . obj [ '<STR_LIT>' ] ] , <EOL> prefix = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> key , '<STR_LIT>' ) <EOL> cache_expected = b"<STR_LIT>" <EOL> self . assertStripEqual ( get_cache ( '<STR_LIT:default>' ) . get ( key ) , cache_expected ) <EOL> with override_settings ( TEMPLATE_DEBUG = True ) : <EOL> with self . assertRaises ( ValueError ) as raise_context : <EOL> self . render ( t ) <EOL> self . assertIn ( '<STR_LIT>' , str ( raise_context . exception ) ) </s>
