77
88class TestCache (unittest .TestCase ):
99 def setUp (self ):
10- self .cache = Cache (tempfile .gettempdir ())
10+ self .store = Cache (tempfile .gettempdir ())
1111
1212 def test_cache_put (self ):
1313 """it should store cache in specified key"""
1414 value = {"foo" : "a-foo" , "bar" : 42 }
1515 key = "a_key"
1616
1717 # When
18- self .cache .put (key , value )
19- act_value = self .cache .get (key )
18+ self .store .put (key , value )
19+ act_value = self .store .get (key )
2020
2121 # Then
2222 self .assertDictEqual (value , act_value )
@@ -25,45 +25,45 @@ def test_cache_put_overwrite(self):
2525 """it should store updated cache value"""
2626 value = {"foo" : "a-foo" , "bar" : 42 }
2727 key = "a_key"
28- self .cache .put (key , value )
28+ self .store .put (key , value )
2929
3030 new_value = {"foo" : "new-foo" }
31- self .cache .put (key , new_value )
31+ self .store .put (key , new_value )
3232
3333 # When
34- updated_value = self .cache .get (key )
34+ updated_value = self .store .get (key )
3535
3636 # Then
3737 self .assertDictEqual (new_value , updated_value )
3838
3939 def test_key_not_found (self ):
4040 """it should return None if key doesn't exist"""
41- value = self .cache .get ("it-does-not-exist" )
41+ value = self .store .get ("it-does-not-exist" )
4242 self .assertIsNone (value )
4343
4444 def test_delete (self ):
4545 """it should delete key"""
4646 key = "a_key"
47- self .cache .put (key , {"a" : "b" })
48- self .cache .delete (key )
47+ self .store .put (key , {"a" : "b" })
48+ self .store .delete (key )
4949
50- value = self .cache .get (key )
50+ value = self .store .get (key )
5151 self .assertIsNone (value )
5252
5353 def test_write_to_file (self ):
5454 """it should update the cache file"""
5555 value = {"foo" : "a-long-foo-so-to-make-sure-truncate-is-working" , "bar" : 42 }
5656 key = "a_key"
57- self .cache .put (key , value )
57+ self .store .put (key , value )
5858 # Add one and delete to make sure file gets updated
59- self .cache .put ("to-delete-key" , {"x" : "y" })
60- self .cache .delete ("to-delete-key" )
59+ self .store .put ("to-delete-key" , {"x" : "y" })
60+ self .store .delete ("to-delete-key" )
6161
6262 # When
6363 new_value = {"a" : "b" }
64- self .cache .put (key , new_value )
64+ self .store .put (key , new_value )
6565
6666 # Then
67- with open (self .cache .cache_file .name , "r" ) as stored :
67+ with open (self .store .cache_file .name , "r" ) as stored :
6868 content = json .loads (stored .read ())
6969 self .assertDictEqual (content [key ], new_value )
0 commit comments