Beispiel #1
0
 def test_300_error(self, mock_request):
     # type: (mock.MagicMock) -> None
     with self.assertRaises(PushNotificationBouncerException) as exc:
         apn.send_to_push_bouncer('register', 'register', {'msg': True})
     self.assertEqual(
         str(exc.exception),
         'Push notification bouncer returned unexpected status code 300')
 def test_400_error_invalid_server_key(self):
     # type: () -> None
     from zerver.decorator import InvalidZulipServerError
     # This is the exception our decorator uses for an invalid Zulip server
     error_obj = InvalidZulipServerError("testRole")
     with mock.patch('requests.request',
                     return_value=Result(status=400,
                                         content=ujson.dumps(error_obj.to_json()))):
         with self.assertRaises(PushNotificationBouncerException) as exc:
             apn.send_to_push_bouncer('register', 'register', {'msg': True})
     self.assertEqual(str(exc.exception),
                      'Push notifications bouncer error: '
                      'Zulip server auth failure: testRole is not registered')
 def test_300_error(self, mock_request):
     # type: (mock.MagicMock) -> None
     with self.assertRaises(PushNotificationBouncerException) as exc:
         apn.send_to_push_bouncer('register', 'register', {'msg': True})
     self.assertEqual(str(exc.exception),
                      'Push notification bouncer returned unexpected status code 300')
 def test_400_error_when_content_is_not_serializable(self, mock_request):
     # type: (mock.MagicMock) -> None
     with self.assertRaises(ValueError) as exc:
         apn.send_to_push_bouncer('register', 'register', {'msg': True})
     self.assertEqual(str(exc.exception),
                      'Expected object or value')
 def test_400_error(self, mock_request):
     # type: (mock.MagicMock) -> None
     with self.assertRaises(apn.JsonableError) as exc:
         apn.send_to_push_bouncer('register', 'register', {'msg': True})
     self.assertEqual(exc.exception.msg, 'error')
 def test_500_error(self, mock_request):
     # type: (mock.MagicMock) -> None
     with self.assertRaises(PushNotificationBouncerException) as exc:
         apn.send_to_push_bouncer('register', 'register', {'data': True})
     self.assertEqual(str(exc.exception),
                      'Received 500 from push notification bouncer')