예제 #1
0
 def test_happy_path(self):
     dy = DynamoBatchDispatcher('test_table_name',
                                'p_key',
                                max_batch_size=1)
     dy._dynamo_table = Mock()
     dy._dynamo_table.put_item = Mock()
     test_payload = {"processed_payload": False}
     dy._send_individual_payload(test_payload)
     dy._dynamo_table.put_item.assert_called_once_with(
         **{'Item': test_payload})
예제 #2
0
 def test_client_error_no_retries_remaining(self):
     dy = DynamoBatchDispatcher('test_table_name',
                                'p_key',
                                max_batch_size=1)
     dy._dynamo_table = Mock()
     dy._dynamo_table.put_item.side_effect = [
         ClientError({'Error': {
             'Code': 500,
             'Message': 'broken'
         }}, "Dynamo")
     ]
     test_payload = {"processed_payload": False}
     dy._send_individual_payload(test_payload, retry=0)
     dy._dynamo_table.put_item.assert_called_once_with(
         **{'Item': test_payload})
     self.assertEqual([test_payload], dy.unprocessed_items)
예제 #3
0
 def test_client_error_retries_remaining(self):
     dy = DynamoBatchDispatcher('test_table_name',
                                'p_key',
                                max_batch_size=1)
     dy._dynamo_table = Mock()
     dy._dynamo_table.put_item.side_effect = [
         ClientError({'Error': {
             'Code': 500,
             'Message': 'broken'
         }}, "Dynamo"), None
     ]
     test_payload = {"processed_payload": False}
     dy._send_individual_payload(test_payload, retry=1)
     dy._dynamo_table.put_item.assert_has_calls(
         [call(**{'Item': test_payload}),
          call(**{'Item': test_payload})])
예제 #4
0
 def test_several_unprocessed_items(self,
                                    mock_base_process_batch_send_response):
     dy = DynamoBatchDispatcher('test_table_name',
                                'p_key',
                                max_batch_size=1)
     dy._send_individual_payload = Mock()
     test_response = {
         'UnprocessedItems': {
             'test_table_name': [{
                 "PutRequest": {
                     "Item": "TEST_ITEM1"
                 }
             }, {
                 "PutRequest": {
                     "Item": "TEST_ITEM2"
                 }
             }, {
                 "PutRequest": {
                     "Item": "TEST_ITEM3"
                 }
             }]
         }
     }
     dy._process_batch_send_response(test_response)
     mock_base_process_batch_send_response.assert_not_called()
     dy._send_individual_payload.assert_has_calls(
         [call("TEST_ITEM1"),
          call("TEST_ITEM2"),
          call("TEST_ITEM3")])
예제 #5
0
 def test_no_unprocessed_items(self, mock_base_process_batch_send_response):
     dy = DynamoBatchDispatcher('test_table_name',
                                'p_key',
                                max_batch_size=1)
     dy._send_individual_payload = Mock()
     test_response = {'UnprocessedItems': []}
     dy._process_batch_send_response(test_response)
     mock_base_process_batch_send_response.assert_not_called()
     dy._send_individual_payload.assert_not_called()
예제 #6
0
 def test_one_unprocessed_item(self, mock_base_process_batch_send_response):
     dy = DynamoBatchDispatcher('test_table_name',
                                'p_key',
                                max_batch_size=1)
     dy._send_individual_payload = Mock()
     test_response = {
         'UnprocessedItems': {
             'test_table_name': [{
                 "PutRequest": {
                     "Item": "TEST_ITEM"
                 }
             }]
         }
     }
     dy._process_batch_send_response(test_response)
     mock_base_process_batch_send_response.assert_not_called()
     dy._send_individual_payload.assert_called_once_with("TEST_ITEM")