<s> from django . test import TestCase <EOL> from mock import Mock <EOL> from wwwhisper_auth . site_cache import CachingSitesCollection <EOL> from wwwhisper_auth . site_cache import SiteCache <EOL> TEST_SITE = '<STR_LIT>' <EOL> class FakeCacheUpdater ( object ) : <EOL> def __init__ ( self ) : <EOL> self . return_value = False <EOL> def is_obsolete ( self , site ) : <EOL> return self . return_value <EOL> class SiteCacheTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . updater = FakeCacheUpdater ( ) <EOL> self . cache = SiteCache ( self . updater ) <EOL> def test_cache ( self ) : <EOL> site = Mock ( ) <EOL> site . site_id = '<STR_LIT:foo>' <EOL> self . assertIsNone ( self . cache . get ( '<STR_LIT:foo>' ) ) <EOL> self . cache . insert ( site ) <EOL> self . assertEqual ( site , self . cache . get ( '<STR_LIT:foo>' ) ) <EOL> self . assertIsNone ( self . cache . get ( '<STR_LIT:bar>' ) ) <EOL> self . cache . delete ( '<STR_LIT:foo>' ) <EOL> self . assertIsNone ( self . cache . get ( '<STR_LIT:foo>' ) ) <EOL> def test_cache_obsolete ( self ) : <EOL> site = Mock ( ) <EOL> site . site_id = '<STR_LIT:foo>' <EOL> self . cache . insert ( site ) <EOL> self . assertEqual ( site , self . cache . get ( '<STR_LIT:foo>' ) ) <EOL> self . updater . return_value = True <EOL> self . assertIsNone ( self . cache . get ( '<STR_LIT:foo>' ) ) <EOL> class CachingSitesCollectionTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . sites = CachingSitesCollection ( ) <EOL> def test_find_returns_cached_item_if_not_modified ( self ) : <EOL> site = self . sites . create_item ( TEST_SITE ) <EOL> site2 = self . sites . find_item ( TEST_SITE ) <EOL> self . assertTrue ( site is site2 ) <EOL> def test_find_rereads_item_if_externally_modified ( self ) : <EOL> site = self . sites . create_item ( TEST_SITE ) <EOL> orig_mod_id = site . mod_id <EOL> site . site_modified ( ) <EOL> site . mod_id = orig_mod_id <EOL> site2 = self . sites . find_item ( TEST_SITE ) <EOL> self . assertTrue ( site is not site2 ) <EOL> def test_delete_removes_cached_item ( self ) : <EOL> site = self . sites . create_item ( TEST_SITE ) <EOL> self . assertTrue ( self . sites . delete_item ( TEST_SITE ) ) <EOL> self . assertIsNone ( self . sites . find_item ( TEST_SITE ) ) </s>
