From df8fc30b759a2c8e0735918eda0634ec21afe286 Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Fri, 5 Aug 2016 15:02:35 +0500 Subject: [PATCH] Create MockRedis class. Redis is not available on Travis and creating a mock Redis server looks easier than using `mock` module. --- zerver/tests/test_push_notifications.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py index 52a0b2df16..c1dff18f1c 100644 --- a/zerver/tests/test_push_notifications.py +++ b/zerver/tests/test_push_notifications.py @@ -1,4 +1,5 @@ import mock +from typing import Any from django.test import TestCase from django.conf import settings @@ -6,14 +7,31 @@ from django.conf import settings from zerver.models import PushDeviceToken, UserProfile from zerver.models import get_user_profile_by_email from zerver.lib import push_notifications as apn -from zerver.lib.redis_utils import get_redis_client +class MockRedis(object): + data = {} # type: Dict[str, Any] + + def hgetall(self, key): + return self.data.get(key) + + def exists(self, key): + return key in self.data + + def hmset(self, key, data): + self.data[key] = data + + def delete(self, key): + if self.exists(key): + del self.data[key] + + def expire(self, *args, **kwargs): + pass class PushNotificationTest(TestCase): def setUp(self): email = 'hamlet@zulip.com' - self.redis_client = get_redis_client() apn.connection = apn.get_connection('fake-cert', 'fake-key') + self.redis_client = apn.redis_client = MockRedis() # type: ignore apn.dbx_connection = apn.get_connection('fake-cert', 'fake-key') self.user_profile = get_user_profile_by_email(email) self.tokens = ['aaaa', 'bbbb']