def test_list_batch_send_failures_sent_to_unprocessed_items(self): base = BaseDispatcher('test_subject', 'send_lots', 'send_one', max_batch_size=3) test_batch = ["abc", "cde"] base._batch_dispatch_method = Mock(side_effect=ClientError( {"Error": { "message": "Something went wrong", "code": 0 }}, "A Test")) base._process_batch_send_response = Mock() base._handle_client_error = Mock() base._unpack_failed_batch_to_unprocessed_items = Mock() base._batch_send_payloads(test_batch) base._batch_dispatch_method.assert_has_calls([ call(test_batch), call(test_batch), call(test_batch), call(test_batch), call(test_batch) ]) base._process_batch_send_response.assert_not_called() base._unpack_failed_batch_to_unprocessed_items.assert_called_once_with( test_batch)
def test_empty_list(self): base = BaseDispatcher('test_subject', 'send_lots', 'send_one', max_batch_size=3) test_batch = [] base._batch_dispatch_method = Mock(return_value="batch_response") base._process_batch_send_response = Mock() base._batch_send_payloads(test_batch) base._batch_dispatch_method.assert_called_once_with(test_batch) base._process_batch_send_response.assert_called_once_with( "batch_response")
def test_dict(self): base = BaseDispatcher('test_subject', 'send_lots', 'send_one', max_batch_size=3) test_batch = {'something_to_process': [1, 2, 3, 4, 5, 6]} base._batch_dispatch_method = Mock(return_value="batch_response") base._process_batch_send_response = Mock() base._batch_send_payloads(test_batch) base._batch_dispatch_method.assert_called_once_with(**test_batch) base._process_batch_send_response.assert_called_once_with( "batch_response")
def test_payload_list_equal_max_batch_size(self): base = BaseDispatcher('test_subject', 'send_lots', 'send_one', max_batch_size=3) base._batch_payload = [1, 2, 3] base._batch_send_payloads = Mock() base._flush_payload_selector() base._batch_send_payloads.assert_called_once_with([1, 2, 3])
def test_payload_list_less_than_max_batch_size(self): base = BaseDispatcher('test_subject', 'send_lots', 'send_one', max_batch_size=3) base._batch_payload = [1, 2] base._batch_send_payloads = Mock() base._flush_payload_selector() base._batch_send_payloads.assert_not_called()
def test_payload_list_greater_than_max_batch_size(self): base = BaseDispatcher('test_subject', 'send_lots', 'send_one', max_batch_size=3) base._batch_payload = [1, 2, 3, 4] base._batch_send_payloads = Mock() base._flush_payload_selector() base._batch_send_payloads.assert_has_calls( [call([1, 2, 3]), call([4])])
def test_payload_equal_max_batch_size(self, mock_chunks): base = BaseDispatcher('test_subject', 'send_lots', 'send_one', max_batch_size=3) base._batch_payload = [1, 2, 3] base._initialise_aws_client = Mock() base._batch_send_payloads = Mock() mock_chunks.return_value = [[1, 2, 3]] base.flush_payloads() base._initialise_aws_client.assert_called_once() base._batch_send_payloads.assert_called_once_with([1, 2, 3]) self.assertEqual([], base._batch_payload)
def test_empty_payload_list(self, mock_chunks): base = BaseDispatcher('test_subject', 'send_lots', 'send_one', max_batch_size=3) base._batch_payload = [] base._initialise_aws_client = Mock() base._batch_send_payloads = Mock() mock_chunks.return_value = [[]] base.flush_payloads() base._initialise_aws_client.assert_called_once() base._batch_send_payloads.assert_not_called() self.assertEqual([], base._batch_payload)
def test_payload_multiple_batches(self, mock_chunks): base = BaseDispatcher('test_subject', 'send_lots', 'send_one', max_batch_size=3) base._batch_payload = [1, 2, 3, 4] base._initialise_aws_client = Mock() base._batch_send_payloads = Mock() mock_chunks.return_value = [[1, 2, 3], [4]] base.flush_payloads() base._initialise_aws_client.assert_called_once() base._batch_send_payloads.assert_has_calls( [call([1, 2, 3]), call([4])]) self.assertEqual([], base._batch_payload)
def test_unprocessed_items_are_returned(self, mock_chunks): test_unprocessed_items = ['abc1', 'cde2', 'efg3'] base = BaseDispatcher('test_subject', 'send_lots', 'send_one', max_batch_size=3) base.unprocessed_items = test_unprocessed_items base._batch_payload = [1, 2, 3, 4] base._initialise_aws_client = Mock() base._batch_send_payloads = Mock() mock_chunks.return_value = [[1, 2, 3], [4]] response = base.flush_payloads() base._initialise_aws_client.assert_called_once() base._batch_send_payloads.assert_has_calls( [call([1, 2, 3]), call([4])]) self.assertEqual([], base._batch_payload) self.assertEqual(test_unprocessed_items, response)