Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
1208:5c8a38122e24 | 1209:d8bb9c36aae1 |
---|---|
1 """ | |
2 Tests for the account application tasks. | |
3 | |
4 """ | |
5 from django.test import TestCase | |
6 from mock import call, patch, Mock | |
7 | |
8 import accounts.stats | |
9 from accounts.tasks import user_stats_task | |
10 | |
11 | |
12 class UserStatsTaskTestCase(TestCase): | |
13 fixtures = ['accounts.json'] | |
14 | |
15 @patch('accounts.stats.get_redis_connection') | |
16 def test_user_stats_task(self, connection_mock): | |
17 redis_mock = Mock() | |
18 redis_mock.incr.return_value = 1 | |
19 connection_mock.return_value = redis_mock | |
20 | |
21 task = user_stats_task.s(1).apply() | |
22 | |
23 self.assertEquals(redis_mock.mock_calls, [ | |
24 call.incr('accounts:user_count'), | |
25 call.set('accounts:user_count', 1), | |
26 call.pipeline(), | |
27 call.pipeline().lpush('accounts:new_users', u'Gremmie'), | |
28 call.pipeline().ltrim('accounts:new_users', 0, 9), | |
29 call.pipeline().execute(), | |
30 ]) |