changeset 1210:c4f7f77d55b2 modernize tip

Add unit test for wiki task.
author Brian Neal <bgneal@gmail.com>
date Mon, 03 Feb 2025 16:06:31 -0600
parents d8bb9c36aae1
children
files wiki/tests/test_tasks.py
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wiki/tests/test_tasks.py	Mon Feb 03 16:06:31 2025 -0600
@@ -0,0 +1,24 @@
+"""
+Tests for the wiki application tasks.
+
+"""
+from django.test import TestCase
+from mock import call, patch, ANY, Mock
+
+from wiki.tasks import expire_cookies
+
+
+class ExpireCookiesTaskTestCase(TestCase):
+    @patch('wiki.tasks.get_redis_connection')
+    def test_expire_cookies_task(self, connection_mock):
+        redis = Mock()
+        redis.zcard.return_value = 42
+        redis.zremrangebyscore.return_value = 4
+        connection_mock.return_value = redis
+
+        task = expire_cookies.s().apply()
+
+        self.assertEquals(redis.mock_calls, [
+            call.zcard('wiki_cookie_keys'),
+            call.zremrangebyscore('wiki_cookie_keys', 0.0, ANY),
+        ])