mirror of
https://github.com/zulip/zulip.git
synced 2026-07-15 21:03:26 +08:00
Create MockRedis class.
Redis is not available on Travis and creating a mock Redis server looks easier than using `mock` module.
This commit is contained in:
parent
2ab796aeb5
commit
df8fc30b75
@ -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']
|
||||
|
||||
Loading…
Reference in New Issue
Block a user