Example #1
0
 def test_transform_fcm_response_success(self):
     _status_code = 200
     _content = '{"name": "projects/testbed-test/messages/1545762214218984"}'
     response = MockResponse(_status_code, _content)
     transformed_response = FCMMessage._transform_fcm_response(response)
     self.assertEqual(transformed_response.status_code, _status_code)
     self.assertEqual(transformed_response.content, _content)
 def test_init(self):
     response = MockResponse(200, '{"results": [{}]}')
     batch_response = SubscriptionBatchResponse(tokens=['abc'],
                                                response=response)
     self.assertEqual(len(batch_response.subscribers), 1)
     subscriber = batch_response.subscribers[0]
     self.assertEqual(subscriber.token, 'abc')
Example #3
0
 def test_transform_fcm_response_error(self):
     _status_code = 404
     _content = '{"error": {"code": 404,"message": "Requested entity was not found.","status": "NOT_FOUND","details": [{"@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError","errorCode": "UNREGISTERED"}]}}'
     response = MockResponse(_status_code, _content)
     transformed_response = FCMRequest._transform_fcm_response(response)
     self.assertEqual(transformed_response.status_code, _status_code)
     self.assertEqual(transformed_response.content, 'registration-token-not-registered')
 def test_init_error(self):
     response = MockResponse(500, '{"error": "not the same error"}')
     subscription_response = SubscriptionResponse(response=response,
                                                  error="some error")
     self.assertEqual(subscription_response.error, "some error")
     self.assertEqual(subscription_response.iid_error, "unknown-error")
     self.assertEqual(subscription_response.data, {})
 def test_result_type_error(self):
     # init with an empty results but with an error is valid
     response = MockResponse(400, '{"error": "some error"}')
     batch_response = SubscriptionBatchResponse(tokens=['abc'],
                                                response=response)
     self.assertEqual(batch_response.error, "some error")
     self.assertEqual(batch_response.subscribers, [])
 def test_init_multiple_error(self):
     response = MockResponse(500, '{"error": "some json error"}')
     subscription_response = SubscriptionResponse(response=response, error="some error")
     # Should default to passed error
     self.assertEqual(subscription_response.error, "some error")
     self.assertEqual(subscription_response.iid_error, "unknown-error")
     self.assertEqual(subscription_response.data, {})
 def test_str_error(self):
     response = MockResponse(400, '{"error":"some error"}')
     subscription_status = SubscriptionStatus(response=response)
     self.assertEqual(
         str(subscription_status),
         "SubscriptionStatus(subscriptions=[], iid_error=invalid-argument, error=some error)"
     )
 def test_init(self):
     response = MockResponse(200, '{"applicationVersion": "1.0.2"}')
     subscription_response = SubscriptionResponse(response=response)
     self.assertEqual(subscription_response.error, None)
     self.assertEqual(subscription_response.iid_error, None)
     self.assertEqual(subscription_response.data,
                      {'applicationVersion': '1.0.2'})
 def test_str(self):
     response = MockResponse(
         200, '{"rel":{"topics":{"broadcasts":{"addDate":"2019-02-15"}}}}')
     subscription_status = SubscriptionStatus(response=response)
     self.assertEqual(
         str(subscription_status),
         "SubscriptionStatus(subscriptions=['broadcasts'], iid_error=None, error=None)"
     )
 def test_init_json_error(self):
     response = MockResponse(400,
                             '{"error": "Topic name format is invalid"}')
     subscription_response = SubscriptionResponse(response=response)
     self.assertEqual(subscription_response.error,
                      "Topic name format is invalid")
     self.assertEqual(subscription_response.iid_error, "invalid-argument")
     self.assertEqual(subscription_response.data, {})
 def test_response_content(self):
     response = MockResponse(500, 200)
     with self.assertRaises(TypeError):
         SubscriptionResponse(response=response)
 def test_init_empty(self):
     response = MockResponse(200, '')
     subscription_response = SubscriptionResponse(response=response)
     self.assertEqual(subscription_response.error, None)
     self.assertEqual(subscription_response.iid_error, None)
     self.assertEqual(subscription_response.data, {})
 def test_init_error_code(self):
     response = MockResponse(500, '{"error": "InvalidToken"}')
     subscription_response = SubscriptionResponse(response=response)
     self.assertEqual(subscription_response.error, "InvalidToken")
     self.assertEqual(subscription_response.iid_error, "internal-error")
     self.assertEqual(subscription_response.data, {})
 def test_response_empty(self):
     response = MockResponse(0, '')
     SubscriptionResponse(response=response)
 def test_result_type(self):
     response = MockResponse(200, '{"results": []}')
     with self.assertRaises(ValueError):
         SubscriptionBatchResponse(tokens=['abc'], response=response)
 def test_init_topics(self):
     response = MockResponse(
         200, '{"rel":{"topics":{"broadcasts":{"addDate":"2019-02-15"}}}}')
     subscription_status = SubscriptionStatus(response=response)
     self.assertEqual(subscription_status.error, None)
     self.assertEqual(subscription_status.subscriptions, ["broadcasts"])
 def test_init_garbage(self):
     response = MockResponse(200, 'abcd')
     subscription_status = SubscriptionStatus(response=response)
     self.assertEqual(subscription_status.error, None)
     self.assertEqual(subscription_status.subscriptions, [])
 def test_response_status_code_type(self):
     response = MockResponse('', '')
     with self.assertRaises(TypeError):
         SubscriptionResponse(response=response)
 def test_response_status_code(self):
     response = MockResponse(None, '')
     with self.assertRaises(ValueError):
         SubscriptionResponse(response=response)