Add tests for the cache api
This commit is contained in:
parent
93f385562f
commit
3a44ec8f15
1 changed files with 64 additions and 0 deletions
64
tests/test_cache.py
Normal file
64
tests/test_cache.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue