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')
Exemplo n.º 2
0
    def send(self):
        """ Attempt to send SubscriptionBatchRequest

        Return:
            SubscriptionBatchResponse
        """
        headers = {
            'Authorization': 'Bearer ' + get_firebase_messaging_access_token(),
            'Content-Type': 'application/json'
        }
        try:
            response = urlfetch.fetch(url=self._batch_url,
                                      payload=self._json_string,
                                      method='POST',
                                      headers=headers)
            return SubscriptionBatchResponse(tokens=self.tokens,
                                             response=response)
        except Exception, e:
            # https://cloud.google.com/appengine/docs/standard/python/refdocs/google.appengine.api.urlfetch_errors
            return SubscriptionBatchResponse(tokens=self.tokens, error=str(e))
 def test_tokens_type(self):
     with self.assertRaises(ValueError):
         SubscriptionBatchResponse(tokens=1)
 def test_result_type(self):
     response = MockResponse(200, '{"results": []}')
     with self.assertRaises(ValueError):
         SubscriptionBatchResponse(tokens=['abc'], response=response)
 def test_result_none(self):
     with self.assertRaises(ValueError):
         SubscriptionBatchResponse(tokens=['abc'], response=None)
 def test_tokens_mixed(self):
     with self.assertRaises(ValueError):
         SubscriptionBatchResponse(tokens=['abc', 1])