From ea85c119b21a08bfa9fa8237c84d01bac6c622ba Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 24 Aug 2024 09:30:24 -0700 Subject: [PATCH] Adds basic tests for redis status key deletion --- bookwyrm/tests/views/admin/test_redis.py | 42 ++++++++++++++++++++++++ bookwyrm/views/admin/redis.py | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/bookwyrm/tests/views/admin/test_redis.py b/bookwyrm/tests/views/admin/test_redis.py index 3dcbb7518..e59bf32de 100644 --- a/bookwyrm/tests/views/admin/test_redis.py +++ b/bookwyrm/tests/views/admin/test_redis.py @@ -49,3 +49,45 @@ class RedisStatusViews(TestCase): self.assertIsInstance(result, TemplateResponse) validate_html(result.render()) 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) diff --git a/bookwyrm/views/admin/redis.py b/bookwyrm/views/admin/redis.py index 9ee40796e..0395a15f6 100644 --- a/bookwyrm/views/admin/redis.py +++ b/bookwyrm/views/admin/redis.py @@ -55,7 +55,7 @@ def view_data(): """Helper function to load basic info for the view""" data = {"errors": [], "prefix": settings.CACHE_KEY_PREFIX} try: - data["info"] = r.info + data["info"] = r.info() # pylint: disable=broad-except except Exception as err: data["errors"].append(err)