示例#1
0
 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])
示例#2
0
 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()
示例#3
0
 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])])
示例#4
0
 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)
示例#5
0
 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)
示例#6
0
 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)
示例#7
0
    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)