Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_cache.py 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from django.conf import settings
  2. from django.test import TestCase
  3. from post_office import cache
  4. from ..settings import get_cache_backend
  5. class CacheTest(TestCase):
  6. def test_get_backend_settings(self):
  7. """Test basic get backend function and its settings"""
  8. # Sanity check
  9. self.assertTrue('post_office' in settings.CACHES)
  10. self.assertTrue(get_cache_backend())
  11. # If no post office key is defined, it should return default
  12. del(settings.CACHES['post_office'])
  13. self.assertTrue(get_cache_backend())
  14. # If no caches key in settings, it should return None
  15. delattr(settings, 'CACHES')
  16. self.assertEqual(None, get_cache_backend())
  17. def test_get_cache_key(self):
  18. """
  19. Test for converting names to cache key
  20. """
  21. self.assertEqual('post_office:template:test', cache.get_cache_key('test'))
  22. self.assertEqual('post_office:template:test-slugify', cache.get_cache_key('test slugify'))
  23. def test_basic_cache_operations(self):
  24. """
  25. Test basic cache operations
  26. """
  27. # clean test cache
  28. cache.cache_backend.clear()
  29. self.assertEqual(None, cache.get('test-cache'))
  30. cache.set('test-cache', 'awesome content')
  31. self.assertTrue('awesome content', cache.get('test-cache'))
  32. cache.delete('test-cache')
  33. self.assertEqual(None, cache.get('test-cache'))