diff accounts/tests/test_tasks.py @ 1209:d8bb9c36aae1 modernize

Add unit test for accounts task.
author Brian Neal <bgneal@gmail.com>
date Thu, 30 Jan 2025 18:46:03 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/accounts/tests/test_tasks.py	Thu Jan 30 18:46:03 2025 -0600
@@ -0,0 +1,30 @@
+"""
+Tests for the account application tasks.
+
+"""
+from django.test import TestCase
+from mock import call, patch, Mock
+
+import accounts.stats
+from accounts.tasks import user_stats_task
+
+
+class UserStatsTaskTestCase(TestCase):
+    fixtures = ['accounts.json']
+
+    @patch('accounts.stats.get_redis_connection')
+    def test_user_stats_task(self, connection_mock):
+        redis_mock = Mock()
+        redis_mock.incr.return_value = 1
+        connection_mock.return_value = redis_mock
+
+        task = user_stats_task.s(1).apply()
+
+        self.assertEquals(redis_mock.mock_calls, [
+            call.incr('accounts:user_count'),
+            call.set('accounts:user_count', 1),
+            call.pipeline(),
+            call.pipeline().lpush('accounts:new_users', u'Gremmie'),
+            call.pipeline().ltrim('accounts:new_users', 0, 9),
+            call.pipeline().execute(),
+        ])