bgneal@1209: """ bgneal@1209: Tests for the account application tasks. bgneal@1209: bgneal@1209: """ bgneal@1209: from django.test import TestCase bgneal@1209: from mock import call, patch, Mock bgneal@1209: bgneal@1209: import accounts.stats bgneal@1209: from accounts.tasks import user_stats_task bgneal@1209: bgneal@1209: bgneal@1209: class UserStatsTaskTestCase(TestCase): bgneal@1209: fixtures = ['accounts.json'] bgneal@1209: bgneal@1209: @patch('accounts.stats.get_redis_connection') bgneal@1209: def test_user_stats_task(self, connection_mock): bgneal@1209: redis_mock = Mock() bgneal@1209: redis_mock.incr.return_value = 1 bgneal@1209: connection_mock.return_value = redis_mock bgneal@1209: bgneal@1209: task = user_stats_task.s(1).apply() bgneal@1209: bgneal@1209: self.assertEquals(redis_mock.mock_calls, [ bgneal@1209: call.incr('accounts:user_count'), bgneal@1209: call.set('accounts:user_count', 1), bgneal@1209: call.pipeline(), bgneal@1209: call.pipeline().lpush('accounts:new_users', u'Gremmie'), bgneal@1209: call.pipeline().ltrim('accounts:new_users', 0, 9), bgneal@1209: call.pipeline().execute(), bgneal@1209: ])