mirror of https://github.com/zulip/zulip.git
push_notifications: Create BouncerTestCase.
Adds bounce_request method to simulate a bounce.
This commit is contained in:
parent
5907877038
commit
8a6498f55d
|
@ -57,20 +57,21 @@ class MockRedis(object):
|
||||||
# type: (*Any, **Any) -> None
|
# type: (*Any, **Any) -> None
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class PushBouncerNotificationTest(ZulipTestCase):
|
class BouncerTestCase(ZulipTestCase):
|
||||||
server_uuid = "1234-abcd"
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
|
self.server_uuid = "1234-abcd"
|
||||||
server = RemoteZulipServer(uuid=self.server_uuid,
|
server = RemoteZulipServer(uuid=self.server_uuid,
|
||||||
api_key="magic_secret_api_key",
|
api_key="magic_secret_api_key",
|
||||||
hostname="demo.example.com",
|
hostname="demo.example.com",
|
||||||
last_updated=now())
|
last_updated=now())
|
||||||
server.save()
|
server.save()
|
||||||
|
super(BouncerTestCase, self).setUp()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
RemoteZulipServer.objects.filter(uuid=self.server_uuid).delete()
|
RemoteZulipServer.objects.filter(uuid=self.server_uuid).delete()
|
||||||
|
super(BouncerTestCase, self).tearDown()
|
||||||
|
|
||||||
def bounce_request(self, *args, **kwargs):
|
def bounce_request(self, *args, **kwargs):
|
||||||
# type: (*Any, **Any) -> HttpResponse
|
# type: (*Any, **Any) -> HttpResponse
|
||||||
|
@ -81,12 +82,28 @@ class PushBouncerNotificationTest(ZulipTestCase):
|
||||||
local_url = args[1].replace(settings.PUSH_NOTIFICATION_BOUNCER_URL, "")
|
local_url = args[1].replace(settings.PUSH_NOTIFICATION_BOUNCER_URL, "")
|
||||||
if args[0] == "POST":
|
if args[0] == "POST":
|
||||||
result = self.client_post(local_url,
|
result = self.client_post(local_url,
|
||||||
ujson.loads(kwargs['data']),
|
kwargs['data'],
|
||||||
**self.get_auth())
|
**self.get_auth())
|
||||||
else:
|
else:
|
||||||
raise AssertionError("Unsupported method for bounce_request")
|
raise AssertionError("Unsupported method for bounce_request")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def get_generic_payload(self, method='register'):
|
||||||
|
# type: (Text) -> Dict[str, Any]
|
||||||
|
user_id = 10
|
||||||
|
token = "111222"
|
||||||
|
token_kind = PushDeviceToken.GCM
|
||||||
|
|
||||||
|
return {'user_id': user_id,
|
||||||
|
'token': token,
|
||||||
|
'token_kind': token_kind}
|
||||||
|
|
||||||
|
def get_auth(self):
|
||||||
|
# type: () -> Dict[str, Text]
|
||||||
|
# Auth on this user
|
||||||
|
return self.api_auth(self.server_uuid)
|
||||||
|
|
||||||
|
class PushBouncerNotificationTest(BouncerTestCase):
|
||||||
def test_unregister_remote_push_user_params(self):
|
def test_unregister_remote_push_user_params(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
token = "111222"
|
token = "111222"
|
||||||
|
@ -208,21 +225,6 @@ class PushBouncerNotificationTest(ZulipTestCase):
|
||||||
server=server))
|
server=server))
|
||||||
self.assertEqual(len(tokens), 0)
|
self.assertEqual(len(tokens), 0)
|
||||||
|
|
||||||
def get_generic_payload(self, method='register'):
|
|
||||||
# type: (Text) -> Dict[str, Any]
|
|
||||||
user_id = 10
|
|
||||||
token = "111222"
|
|
||||||
token_kind = PushDeviceToken.GCM
|
|
||||||
|
|
||||||
return {'user_id': user_id,
|
|
||||||
'token': token,
|
|
||||||
'token_kind': token_kind}
|
|
||||||
|
|
||||||
def get_auth(self):
|
|
||||||
# type: () -> Dict[str, Text]
|
|
||||||
# Auth on this user
|
|
||||||
return self.api_auth(self.server_uuid)
|
|
||||||
|
|
||||||
class PushNotificationTest(ZulipTestCase):
|
class PushNotificationTest(ZulipTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
|
|
Loading…
Reference in New Issue