def test_capacity(self): """ Can return consumed capacity """ conn = MagicMock() conn.call.return_value = { 'Items': [], 'ConsumedCapacity': { 'TableName': 'foobar', 'CapacityUnits': 3, 'Table': { 'CapacityUnits': 1, }, 'LocalSecondaryIndexes': { 'l-index': { 'CapacityUnits': 1, }, }, 'GlobalSecondaryIndexes': { 'g-index': { 'CapacityUnits': 1, }, }, }, } rs = ResultSet(conn, Limit()) list(rs) self.assertEqual(rs.capacity, 3) self.assertEqual(rs.table_capacity, 1) self.assertEqual(rs.indexes, {'l-index': 1}) self.assertEqual(rs.global_indexes, {'g-index': 1})
def test_filter(self): """ Limit can post-process to filter items """ self.make_table() limit = Limit(filter=lambda x: x['num'] > 5) ret = self.dynamo.scan2('foobar', limit=limit) self.assertEqual(len(list(ret)), 4)
def test_item_limit(self): """ An item_limit will fetch until reached or exceeded """ self.make_table() limit = Limit(item_limit=5) ret = self.dynamo.scan2('foobar', limit=limit) self.assertEqual(len(list(ret)), 10)
def test_strict(self): """ Strict=True will end the list exactly at the item_limit """ self.make_table() ret = self.dynamo.scan2('foobar', limit=Limit(item_limit=5, strict=True)) self.assertEqual(len(list(ret)), 5)
def test_scan_limit(self): """ Limit can specify a max number of items to scan """ self.make_table() ret = self.dynamo.scan2('foobar', limit=Limit(5)) self.assertEqual(len(list(ret)), 5)