def test_where_payload_is_a_duplicate(self, mock_submit_payload, mock_convert_decimals): dy = DynamoBatchDispatcher('test_table_name', 'p_key', max_batch_size=1) mock_check_payload_is_unique = Mock(return_value=False) dy._check_payload_is_unique = mock_check_payload_is_unique test_payload = {'p_key': 1} mock_convert_decimals.return_value = test_payload dy.submit_payload(test_payload) mock_check_payload_is_unique.assert_called_once_with(test_payload) mock_submit_payload.assert_not_called()
def test_where_key_not_found(self, mock_submit_payload, mock_convert_decimals): dy = DynamoBatchDispatcher('test_table_name', 'p_key', max_batch_size=1) mock_check_payload_is_unique = Mock(return_value=True) dy._check_payload_is_unique = mock_check_payload_is_unique test_payload = {'there_is_no_real_id_here': 1} mock_convert_decimals.return_value = test_payload with self.assertRaises(KeyError): dy.submit_payload(test_payload, partition_key_location='something_useless') mock_check_payload_is_unique.assert_not_called() mock_submit_payload.assert_not_called()
def test_where_key_requires_mapping(self, mock_submit_payload, mock_convert_decimals): dy = DynamoBatchDispatcher('test_table_name', 'p_key', max_batch_size=1) mock_check_payload_is_unique = Mock(return_value=True) dy._check_payload_is_unique = mock_check_payload_is_unique test_payload = {'unmapped_id': 1} mock_convert_decimals.return_value = test_payload dy.submit_payload(test_payload, partition_key_location='unmapped_id') mock_check_payload_is_unique.assert_called_once_with(test_payload) mock_submit_payload.assert_called_once_with( {"PutRequest": { "Item": test_payload }})
def test_where_key_preexists(self, mock_submit_payload, mock_convert_decimals): dy = DynamoBatchDispatcher('test_table_name', 'p_key', max_batch_size=1) mock_check_payload_is_unique = Mock(return_value=True) dy._check_payload_is_unique = mock_check_payload_is_unique test_payload = {'p_key': 1} mock_convert_decimals.return_value = test_payload dy.submit_payload(test_payload) mock_check_payload_is_unique.assert_called_once_with(test_payload) mock_submit_payload.assert_called_once_with( {"PutRequest": { "Item": test_payload }})