diff options
author | mathieui <mathieui@mathieui.net> | 2019-02-02 17:32:10 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2019-02-02 17:32:10 +0100 |
commit | 3a44ec8f15c1d6267f6838b21b210d844202762c (patch) | |
tree | 09e3a643f0a80c144ea23e9bbb8030432cc3e32e | |
parent | 93f385562ff316142121f520ee344f3accea8487 (diff) | |
download | slixmpp-3a44ec8f15c1d6267f6838b21b210d844202762c.tar.gz slixmpp-3a44ec8f15c1d6267f6838b21b210d844202762c.tar.bz2 slixmpp-3a44ec8f15c1d6267f6838b21b210d844202762c.tar.xz slixmpp-3a44ec8f15c1d6267f6838b21b210d844202762c.zip |
Add tests for the cache api
-rw-r--r-- | tests/test_cache.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/test_cache.py b/tests/test_cache.py new file mode 100644 index 00000000..789e8bbf --- /dev/null +++ b/tests/test_cache.py @@ -0,0 +1,64 @@ +import unittest +from slixmpp.test import SlixTest +from slixmpp.util import ( + MemoryCache, MemoryPerJidCache, + FileSystemCache, FileSystemPerJidCache +) +from tempfile import TemporaryDirectory + +class TestCacheClass(SlixTest): + + def testMemoryCache(self): + cache = MemoryCache() + + cache.store("test", "test_value") + self.assertEqual(cache.retrieve("test"), "test_value") + self.assertEqual(cache.retrieve("test2"), None) + + cache.remove("test") + self.assertEqual(cache.retrieve("test"), None) + + def testMemoryPerJidcache(self): + cache = MemoryPerJidCache() + + cache.store_by_jid("test@example.com", "test", "test_value") + self.assertEqual( + cache.retrieve_by_jid("test@example.com", "test"), + "test_value" + ) + + cache.remove_by_jid("test@example.com", "test") + self.assertEqual( + cache.retrieve_by_jid("test@example.com", "test"), + None + ) + + def testFileSystemCache(self): + with TemporaryDirectory() as tmpdir: + cache = FileSystemCache(tmpdir, "test") + cache.store("test", "test_value") + self.assertEqual( + cache.retrieve("test"), + "test_value" + ) + cache.remove("test") + self.assertEqual( + cache.retrieve("test"), + None + ) + + def testFileSystemPerJidCache(self): + with TemporaryDirectory() as tmpdir: + cache = FileSystemPerJidCache(tmpdir, "test") + cache.store_by_jid("test@example.com", "test", "test_value") + self.assertEqual( + cache.retrieve_by_jid("test@example.com", "test"), + "test_value" + ) + cache.remove_by_jid("test@example.com", "test") + self.assertEqual( + cache.retrieve_by_jid("test@example.com", "test"), + None + ) + +suite = unittest.TestLoader().loadTestsFromTestCase(TestCacheClass) |