def test_handle_unprocessed(self): """ Retry all unprocessed items """ conn = MagicMock() writer = BatchWriter(conn, 'foo') key1, key2 = object(), object() unprocessed = [[key1], [key2], []] conn.call.side_effect = lambda *_, **__: { 'UnprocessedItems': { 'foo': unprocessed.pop(0), } } with writer: writer.put({'id': 'a'}) # Should insert the first item, and then the two sets we marked as # unprocessed self.assertEqual(len(conn.call.mock_calls), 3) kwargs = { 'RequestItems': { 'foo': [key1], }, 'ReturnConsumedCapacity': ANY, 'ReturnItemCollectionMetrics': ANY, } self.assertEqual(conn.call.mock_calls[1], call('batch_write_item', **kwargs)) kwargs['RequestItems']['foo'][0] = key2 self.assertEqual(conn.call.mock_calls[2], call('batch_write_item', **kwargs))
def test_handle_unprocessed(self): """Retry all unprocessed items""" conn = MagicMock() writer = BatchWriter(conn) action1, action2 = object(), object() unprocessed = [[action1], [action2], None] def replace_call(*_, **kwargs): actions = unprocessed.pop(0) ret = {} if actions is not None: ret["UnprocessedItems"] = { "foo": actions, } return ret conn.call.side_effect = replace_call with writer: writer.put("foo", {"id": "a"}) # Should insert the first item, and then the two sets we marked as # unprocessed self.assertEqual(len(conn.call.mock_calls), 3) kwargs = { "RequestItems": { "foo": [action1], }, } self.assertEqual(conn.call.mock_calls[1], call("batch_write_item", **kwargs)) kwargs["RequestItems"]["foo"][0] = action2 self.assertEqual(conn.call.mock_calls[2], call("batch_write_item", **kwargs))
def test_handle_unprocessed(self): """ Retry all unprocessed items """ conn = MagicMock() writer = BatchWriter(conn, 'foo') key1, key2 = object(), object() unprocessed = [[key1], [key2], []] conn.call.side_effect = lambda *_, **__: { 'UnprocessedItems': { 'foo': unprocessed.pop(0), } } with writer: writer.put({'id': 'a'}) # Should insert the first item, and then the two sets we marked as # unprocessed self.assertEqual(len(conn.call.mock_calls), 3) self.assertEqual(conn.call.mock_calls[1], call('BatchWriteItem', request_items={'foo': [key1]})) self.assertEqual(conn.call.mock_calls[2], call('BatchWriteItem', request_items={'foo': [key2]}))