def test_simple_batch_delete(self):
        self.connection(_lv.BatchWriteItem().table("Aaa").put(
            {
                "h": "1",
                "a": "xxx"
            },
            {
                "h": "2",
                "a": "yyy"
            },
            {
                "h": "3",
                "a": "zzz"
            },
        ))

        r = self.connection(_lv.BatchWriteItem().table("Aaa").delete(
            {"h": "1"}, {"h": "2"}, {"h": "3"}))

        self.assertEqual(
            self.connection(_lv.GetItem("Aaa", {"h": "1"})).item, None)
        self.assertEqual(
            self.connection(_lv.GetItem("Aaa", {"h": "2"})).item, None)
        self.assertEqual(
            self.connection(_lv.GetItem("Aaa", {"h": "3"})).item, None)
示例#2
0
def batch_put_item(connection, table, *items):
    """
    Make as many :class:`.BatchWriteItem` actions as needed to put all specified items.
    Including processing :attr:`.BatchWriteItemResponse.unprocessed_items`.

    >>> batch_put_item(
    ...   connection,
    ...   table,
    ...   {"h": 0, "a": 42},
    ...   {"h": 1, "a": 57},
    ...   {"h": 2, "a": 33, "b": 22},
    ... )
    """
    items = list(items)
    unprocessed_items = []

    while len(items) != 0:
        r = connection(_lv.BatchWriteItem().table(table).put(items[:25]))
        items = items[25:]
        if isinstance(r.unprocessed_items, dict) and table in r.unprocessed_items:
            unprocessed_items.extend(r.unprocessed_items[table])

    while len(unprocessed_items) != 0:
        r = connection(_lv.BatchWriteItem().previous_unprocessed_items({table: unprocessed_items[:25]}))
        unprocessed_items = unprocessed_items[25:]
        if isinstance(r.unprocessed_items, dict) and table in r.unprocessed_items:
            unprocessed_items.extend(r.unprocessed_items[table])
示例#3
0
def batch_delete_item(connection, table, *keys):
    """
    Make as many :class:`.BatchWriteItem` actions as needed to delete all specified keys.
    Including processing :attr:`.BatchWriteItemResponse.unprocessed_items`.

    >>> batch_delete_item(
    ...   connection,
    ...   table,
    ...   {"h": 0},
    ...   {"h": 1},
    ...   {"h": 2}
    ... )
    """
    keys = list(keys)
    unprocessed_items = []

    while len(keys) != 0:
        r = connection(_lv.BatchWriteItem().table(table).delete(keys[:25]))
        keys = keys[25:]
        if isinstance(r.unprocessed_items, dict) and table in r.unprocessed_items:
            unprocessed_items.extend(r.unprocessed_items[table])

    while len(unprocessed_items) != 0:
        r = connection(_lv.BatchWriteItem().previous_unprocessed_items({table: unprocessed_items[:25]}))
        unprocessed_items = unprocessed_items[25:]
        if isinstance(r.unprocessed_items, dict) and table in r.unprocessed_items:
            unprocessed_items.extend(r.unprocessed_items[table])
示例#4
0
    def test_simple_batch_get(self):
        self.connection(_lv.BatchWriteItem().table("Aaa").put(
            {
                "h": "1",
                "a": "xxx"
            },
            {
                "h": "2",
                "a": "yyy"
            },
            {
                "h": "3",
                "a": "zzz"
            },
        ))

        r = self.connection(_lv.BatchGetItem().table("Aaa").keys({"h": "1"},
                                                                 {"h": "2"},
                                                                 {"h": "3"}))

        self.assertEqual(list(r.responses.keys()), ["Aaa"])
        self.assertEqual(sorted(r.responses["Aaa"], key=lambda i: i["h"]),
                         [{
                             "h": "1",
                             "a": "xxx"
                         }, {
                             "h": "2",
                             "a": "yyy"
                         }, {
                             "h": "3",
                             "a": "zzz"
                         }])
示例#5
0
    def test_get_unexisting_keys(self):
        self.connection(_lv.BatchWriteItem().table("Aaa").put(
            {
                "h": "1",
                "a": "xxx"
            },
            {
                "h": "2",
                "a": "yyy"
            },
        ))

        r = self.connection(_lv.BatchGetItem().table("Aaa").keys({"h": "1"},
                                                                 {"h": "2"},
                                                                 {"h": "3"}))

        self.assertEqual(sorted(r.responses["Aaa"], key=lambda i: i["h"]),
                         [{
                             "h": "1",
                             "a": "xxx"
                         }, {
                             "h": "2",
                             "a": "yyy"
                         }])
        self.assertEqual(r.unprocessed_keys, {})
示例#6
0
 def setUp(self):
     super(ScanLocalIntegTests, self).setUp()
     self.connection(_lv.BatchWriteItem().table("Aaa").put(
         {"h": "0", "v": 0},
         {"h": "1", "v": 1},
         {"h": "2", "v": 2},
         {"h": "3", "v": 3},
     ))
示例#7
0
 def setUp(self):
     super(ScanIteratorLocalIntegTests, self).setUp()
     self.connection(_lv.BatchWriteItem().table("Aaa").put(
         {
             "h": h,
             "xs": "x" * 300000
         }  # 300kB items ensure a single Query will return at most 4 items
         for h in self.keys))
    def test_return_item_collection_metrics_size(self):
        r = self.connection(_lv.BatchWriteItem().table(self.table).put(
            self.item).return_item_collection_metrics_size())

        self.assertEqual(
            r.item_collection_metrics[self.table][0].item_collection_key,
            {"tab_h": "0"})
        self.assertEqual(
            r.item_collection_metrics[self.table][0].size_estimate_range_gb[0],
            0.0)
        self.assertEqual(
            r.item_collection_metrics[self.table][0].size_estimate_range_gb[1],
            1.0)
    def test_return_consumed_capacity_indexes(self):
        r = self.connection(_lv.BatchWriteItem().table(self.table).put(
            self.item).return_consumed_capacity_indexes())

        self.assertEqual(r.consumed_capacity[0].capacity_units, 3.0)
        self.assertEqual(
            r.consumed_capacity[0].global_secondary_indexes["gsi"].
            capacity_units, 1.0)
        self.assertEqual(
            r.consumed_capacity[0].local_secondary_indexes["lsi"].
            capacity_units, 1.0)
        self.assertEqual(r.consumed_capacity[0].table.capacity_units, 1.0)
        self.assertEqual(r.consumed_capacity[0].table_name, self.table)
示例#10
0
    def test_batch_get_with_projections(self):
        self.connection(_lv.BatchWriteItem().table("Aaa").put(
            {
                "h": "1",
                "a": "a1",
                "b": "b1",
                "c": "c1"
            },
            {
                "h": "2",
                "a": "a2",
                "b": "b2",
                "c": "c2"
            },
            {
                "h": "3",
                "a": "a3",
                "b": "b3",
                "c": "c3"
            },
        ))

        r = self.connection(_lv.BatchGetItem().table("Aaa").keys({
            "h": "1"
        }, {
            "h": "2"
        }, {
            "h": "3"
        }).expression_attribute_name("p",
                                     "b").project("h").project("a", ["#p"]))
        self.assertEqual(sorted(r.responses["Aaa"], key=lambda i: i["h"]),
                         [{
                             "h": "1",
                             "a": "a1",
                             "b": "b1"
                         }, {
                             "h": "2",
                             "a": "a2",
                             "b": "b2"
                         }, {
                             "h": "3",
                             "a": "a3",
                             "b": "b3"
                         }])
示例#11
0
 def setUp(self):
     super(QueryLocalIntegTests, self).setUp()
     self.connection(_lv.BatchWriteItem().table("Aaa").put(
         {
             "h": "0",
             "r": 41,
             "v": 0
         },
         {
             "h": "0",
             "r": 42,
             "v": 1
         },
         {
             "h": "0",
             "r": 43,
             "v": 2
         },
         {
             "h": "0",
             "r": 44,
             "v": 3
         },
         {
             "h": "0",
             "r": 45,
             "v": 4
         },
         {
             "h": "1",
             "r": 42,
             "v": 2
         },
         {
             "h": "2",
             "r": 42,
             "v": 3
         },
     ))