Adds basic tests for redis status key deletion

This commit is contained in:
Mouse Reeve 2024-08-24 09:30:24 -07:00
parent 1c9bc936f6
commit ea85c119b2
2 changed files with 43 additions and 1 deletions

View file

@ -49,3 +49,45 @@ class RedisStatusViews(TestCase):
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
validate_html(result.render()) validate_html(result.render())
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
def test_redis_status_post_scan_keys(self):
"""count keys in redis"""
view = views.RedisStatus.as_view()
request = self.factory.post("", {"dry_run": True})
request.user = self.local_user
result = view(request)
self.assertIsInstance(result, TemplateResponse)
validate_html(result.render())
self.assertEqual(result.status_code, 200)
self.assertTrue("outdated_identified" in result.context_data)
self.assertFalse("outdated_deleted" in result.context_data)
self.assertFalse("cache_deleted" in result.context_data)
def test_redis_status_post_erase_keys(self):
"""count keys in redis"""
view = views.RedisStatus.as_view()
request = self.factory.post("")
request.user = self.local_user
result = view(request)
self.assertIsInstance(result, TemplateResponse)
validate_html(result.render())
self.assertEqual(result.status_code, 200)
self.assertFalse("outdated_identified" in result.context_data)
self.assertTrue("outdated_deleted" in result.context_data)
self.assertFalse("cache_deleted" in result.context_data)
def test_redis_status_post_erase_cache(self):
"""count keys in redis"""
view = views.RedisStatus.as_view()
request = self.factory.post("", {"erase_cache": True})
request.user = self.local_user
result = view(request)
self.assertIsInstance(result, TemplateResponse)
validate_html(result.render())
self.assertEqual(result.status_code, 200)
self.assertFalse("outdated_identified" in result.context_data)
self.assertFalse("outdated_deleted" in result.context_data)
self.assertTrue("cache_deleted" in result.context_data)

View file

@ -55,7 +55,7 @@ def view_data():
"""Helper function to load basic info for the view""" """Helper function to load basic info for the view"""
data = {"errors": [], "prefix": settings.CACHE_KEY_PREFIX} data = {"errors": [], "prefix": settings.CACHE_KEY_PREFIX}
try: try:
data["info"] = r.info data["info"] = r.info()
# pylint: disable=broad-except # pylint: disable=broad-except
except Exception as err: except Exception as err:
data["errors"].append(err) data["errors"].append(err)