Beispiel #1
0
 def _raise_publish_error(self, status_code, e, destination=None):
     if status_code >= 400 and status_code < 500:
         raise PublishHTTPPushClientError.httpPushError(e, destination)
     elif status_code >= 500 and status_code < 600:
         raise PublishHTTPPushServerError.httpPushError(e, destination)
     else:
         raise PublishHTTPPushError.httpPushError(e, destination)
Beispiel #2
0
    def test_no_retry_on_http_push_client_error(self, *mocks):
        self.app.config['MAX_TRANSMIT_RETRY_ATTEMPT'] = 4

        item_1 = {
            '_id': 'item_1',
            'destination': {},
            'subscriber_id': '1',
            'item_id': 'test',
            'headline': 'test headline',
            'item_version': 4,
            'state': 'pending'
        }

        orig_item = item_1.copy()  # item's original state in DB

        fake_get_service = mocks[1]
        fake_get_service().find_one.return_value = orig_item

        fake_transmitter = MagicMock()
        fake_transmitter.transmit.side_effect = PublishHTTPPushClientError.httpPushError(
            Exception('client 4xx'))

        fake_transmitters_list = mocks[0]
        fake_transmitters_list.__getitem__.return_value = fake_transmitter

        self.func_under_test(item_1['_id'])

        fake_get_service().system_update.assert_called_with(
            'item_1', {
                '_updated': ANY,
                'state': 'failed'
            }, orig_item)
Beispiel #3
0
 def _raise_publish_error(self, status_code, e, destination=None):
     if status_code >= 400 and status_code < 500:
         raise PublishHTTPPushClientError.httpPushError(e, destination)
     elif status_code >= 500 and status_code < 600:
         raise PublishHTTPPushServerError.httpPushError(e, destination)
     else:
         raise PublishHTTPPushError.httpPushError(e, destination)
    def test_no_retry_on_http_push_client_error(self, *mocks):
        self.app.config['MAX_TRANSMIT_RETRY_ATTEMPT'] = 4

        item_1 = {
            '_id': 'item_1',
            'destination': {},
            'subscriber_id': '1',
            'item_id': 'test',
            'headline': 'test headline',
            'item_version': 4,
            'state': 'pending'
        }

        orig_item = item_1.copy()  # item's original state in DB

        fake_get_service = mocks[1]
        fake_get_service().find_one.return_value = orig_item
        queue_items = [item_1]

        fake_transmitter = MagicMock()
        fake_transmitter.transmit.side_effect = PublishHTTPPushClientError.httpPushError(Exception('client 4xx'))

        fake_transmitters_list = mocks[0]
        fake_transmitters_list.__getitem__.return_value = fake_transmitter

        self.func_under_test(queue_items)

        fake_get_service().system_update.assert_called_with('item_1', {'_updated': ANY,
                                                                       'state': 'failed'}, orig_item)
    def test_no_retry_on_http_push_client_error(self, *mocks):
        self.app.config["MAX_TRANSMIT_RETRY_ATTEMPT"] = 4

        item_1 = {
            "_id": "item_1",
            "destination": {},
            "subscriber_id": "1",
            "item_id": "test",
            "headline": "test headline",
            "item_version": 4,
            "state": "pending",
        }

        orig_item = item_1.copy()  # item's original state in DB

        fake_get_service = mocks[1]
        fake_get_service().find_one.return_value = orig_item

        fake_transmitter = MagicMock()
        fake_transmitter.transmit.side_effect = PublishHTTPPushClientError.httpPushError(
            Exception("client 4xx"))

        fake_transmitters_list = mocks[0]
        fake_transmitters_list.__getitem__.return_value = fake_transmitter

        self.assertIsNone(self.func_under_test(item_1["_id"]))

        fake_get_service().system_update.assert_called_with(
            "item_1", {
                "_updated": ANY,
                "state": "failed"
            }, orig_item)
    def test_client_publish_error_thrown(self, fake_post, fake_notifiers):
        raise_http_exception = Mock(side_effect=PublishHTTPPushClientError.httpPushError(Exception('client 4xx')))

        fake_post.return_value = Mock(status_code=401, text='client 4xx', raise_for_status=raise_http_exception)

        # needed for bad exception handling classes
        fake_notifiers.return_value = []

        service = HTTPPushService()

        with self.assertRaises(PublishHTTPPushClientError):
            service._push_item(self.destination, json.dumps(self.item))
    def test_client_publish_error_thrown(self, fake_post, fake_notifiers):
        raise_http_exception = Mock(side_effect=PublishHTTPPushClientError.httpPushError(Exception('client 4xx')))

        fake_post.return_value = Mock(status_code=401, text='client 4xx', raise_for_status=raise_http_exception)

        # needed for bad exception handling classes
        fake_notifiers.return_value = []

        service = HTTPPushService()

        with self.assertRaises(PublishHTTPPushClientError):
            service._push_item(self.destination, json.dumps(self.item))