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)