Skip to content

Commit

Permalink
Adds basic tests for redis status key deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
mouse-reeve committed Aug 24, 2024
1 parent 1c9bc93 commit ea85c11
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions bookwyrm/tests/views/admin/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,45 @@ def test_redis_status_get(self):
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)

Check failure on line 59 in bookwyrm/tests/views/admin/test_redis.py

View workflow job for this annotation

GitHub Actions / Tests (pytest)

RedisStatusViews.test_redis_status_post_scan_keys redis.exceptions.ConnectionError: Error -3 connecting to redis_activity:6379. Temporary failure in name resolution.
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)

Check failure on line 73 in bookwyrm/tests/views/admin/test_redis.py

View workflow job for this annotation

GitHub Actions / Tests (pytest)

RedisStatusViews.test_redis_status_post_erase_keys redis.exceptions.ConnectionError: Error -3 connecting to redis_activity:6379. Temporary failure in name resolution.
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)

Check failure on line 87 in bookwyrm/tests/views/admin/test_redis.py

View workflow job for this annotation

GitHub Actions / Tests (pytest)

RedisStatusViews.test_redis_status_post_erase_cache redis.exceptions.ConnectionError: Error -3 connecting to redis_activity:6379. Temporary failure in name resolution.
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)
2 changes: 1 addition & 1 deletion bookwyrm/views/admin/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ea85c11

Please sign in to comment.