Beispiel #1
0
 def test_busting(self):
     with mock.patch.object(cache, 'has_expired', return_value=False):
         cache.setv(se.key, se.value)
         with cache.maybe_bust(False):
             self.assertEqual(se.value, cache.getv(se.key))
         with cache.maybe_bust(True):
             self.assertRaises(KeyError, cache.getv, se.key)
Beispiel #2
0
 def test_busting(self):
     with mock.patch.object(cache, 'has_expired', return_value=False):
         cache.setv(se.key, se.value)
         with cache.maybe_bust(False):
             self.assertEqual(se.value, cache.getv(se.key))
         with cache.maybe_bust(True):
             self.assertRaises(KeyError, cache.getv, se.key)
Beispiel #3
0
 def test_stats(self):
     with mock.patch.object(cache, 'has_expired', return_value=False):
         cache.setv(se.key, se.value)
         self.assertEqual(cache.get_stats()['sets'], 1)
         self.assertEqual(cache.get_stats()['gets'], 0)
         cache.getv(se.key)
         self.assertEqual(cache.get_stats()['gets'], 1)
Beispiel #4
0
 def test_stats(self):
     with mock.patch.object(cache, 'has_expired', return_value=False):
         cache.setv(se.key, se.value)
         self.assertEqual(cache.get_stats()['sets'], 1)
         self.assertEqual(cache.get_stats()['gets'], 0)
         cache.getv(se.key)
         self.assertEqual(cache.get_stats()['gets'], 1)
Beispiel #5
0
 def test_configure(self):
     cache.configure(cache_time=13)
     with mock.patch('time.time', return_value=1):
         cache.setv(se.key, se.value)
         with mock.patch.object(cache, 'has_expired', return_value=False) as m:
             cache.getv(se.key, time.time())
             m.assert_called_once_with(cache.Record(14, mock.ANY), 1)
Beispiel #6
0
 def test_configure(self):
     cache.configure(cache_time=13)
     with mock.patch('time.time', return_value=1):
         cache.setv(se.key, se.value)
         with mock.patch.object(cache, 'has_expired',
                                return_value=False) as m:
             cache.getv(se.key, time.time())
             m.assert_called_once_with(cache.Record(14, mock.ANY), 1)
Beispiel #7
0
 def test_expiry(self):
     with mock.patch.object(cache, 'has_expired', return_value=False) as m:
         cache.setv(se.key, se.value)
         self.assertEqual(cache.getv(se.key), se.value)
         self.assertEqual(m.call_count, 1)
     with mock.patch.object(cache, 'has_expired', return_value=True) as m:
         cache.setv(se.key, se.value)
         self.assertRaises(KeyError, cache.getv, se.key)
         self.assertEqual(m.call_count, 1)
Beispiel #8
0
 def test_expiry(self):
     with mock.patch.object(cache, 'has_expired', return_value=False) as m:
         cache.setv(se.key, se.value)
         self.assertEqual(cache.getv(se.key), se.value)
         self.assertEqual(m.call_count, 1)
     with mock.patch.object(cache, 'has_expired', return_value=True) as m:
         cache.setv(se.key, se.value)
         self.assertRaises(KeyError, cache.getv, se.key)
         self.assertEqual(m.call_count, 1)