diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-03-20 18:13:49 +0000 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-03-20 18:25:42 +0000 |
commit | 0f86312c4cb262ad1b69207dd46712707dee75bb (patch) | |
tree | cf1489f5a43902be0a40362940ac8821cae0e555 /tests/storage/test__base.py | |
parent | func(*EXPR) is valid Python syntax, really... (diff) | |
download | synapse-0f86312c4cb262ad1b69207dd46712707dee75bb.tar.xz |
Pull out the cache logic from the @cached wrapper into its own class we can reuse
Diffstat (limited to 'tests/storage/test__base.py')
-rw-r--r-- | tests/storage/test__base.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/tests/storage/test__base.py b/tests/storage/test__base.py index 55d22f665a..783abc2b00 100644 --- a/tests/storage/test__base.py +++ b/tests/storage/test__base.py @@ -17,7 +17,39 @@ from tests import unittest from twisted.internet import defer -from synapse.storage._base import cached +from synapse.storage._base import Cache, cached + + +class CacheTestCase(unittest.TestCase): + + def setUp(self): + self.cache = Cache("test") + + def test_empty(self): + failed = False + try: + self.cache.get("foo") + except KeyError: + failed = True + + self.assertTrue(failed) + + def test_hit(self): + self.cache.prefill("foo", 123) + + self.assertEquals(self.cache.get("foo"), 123) + + def test_invalidate(self): + self.cache.prefill("foo", 123) + self.cache.invalidate("foo") + + failed = False + try: + self.cache.get("foo") + except KeyError: + failed = True + + self.assertTrue(failed) class CacheDecoratorTestCase(unittest.TestCase): |