コード例 #1
0
    def test_send_fcm_unhandled_error(self):
        client = MobileClient(parent=ndb.Key(Account, 'user_id'),
                              user_id='user_id',
                              messaging_id='messaging_id',
                              client_type=ClientType.OS_IOS)
        client.put()

        # Sanity check
        self.assertEqual(fcm_messaging_ids('user_id'), ['messaging_id'])

        batch_response = messaging.BatchResponse(
            [messaging.SendResponse(None, FirebaseError('code', 'message'))])
        with patch.object(FCMRequest, 'send',
                          return_value=batch_response), patch(
                              'logging.error') as mock_error:
            exit_code = TBANSHelper._send_fcm([client], MockNotification())
            self.assertEqual(exit_code, 0)
            mock_error.assert_called_once_with(
                'Unhandled FCM error for messaging_id - code / message')

        # Sanity check
        self.assertEqual(fcm_messaging_ids('user_id'), ['messaging_id'])

        # Check that we didn't queue for a retry
        tasks = self.taskqueue_stub.get_filtered_tasks(
            queue_names='push-notifications')
        self.assertEqual(len(tasks), 0)
コード例 #2
0
    def test_debug_string_response(self):
        class MockResponse:
            def json(self):
                import json
                return json.dumps({'mock': 'mock'})

        exception = FirebaseError('code', 'message', None, MockResponse())
        self.assertEqual(TBANSHelper._debug_string(exception),
                         'code / message / {"mock": "mock"}')
コード例 #3
0
    def test_ping_fcm_fail(self):
        client = MobileClient(parent=ndb.Key(Account, 'user_id'),
                              user_id='user_id',
                              messaging_id='token',
                              client_type=ClientType.OS_IOS,
                              device_uuid='uuid',
                              display_name='Phone')

        batch_response = messaging.BatchResponse(
            [messaging.SendResponse(None, FirebaseError(500, 'testing'))])
        with patch.object(FCMRequest, 'send',
                          return_value=batch_response) as mock_send:
            success = TBANSHelper._ping_client(client)
            mock_send.assert_called_once()
            self.assertFalse(success)
コード例 #4
0
 def test_debug_string(self):
     exception = FirebaseError('code', 'message')
     self.assertEqual(TBANSHelper._debug_string(exception),
                      'code / message')