def test_simple_batch_put(self): r = self.connection(_lv.BatchWriteItem().table("Aaa").put( { "h": "1", "a": "xxx" }, { "h": "2", "a": "yyy" }, { "h": "3", "a": "zzz" }, )) self.assertEqual( self.connection(_lv.GetItem("Aaa", {"h": "1"})).item, { "h": "1", "a": "xxx" }) self.assertEqual( self.connection(_lv.GetItem("Aaa", {"h": "2"})).item, { "h": "2", "a": "yyy" }) self.assertEqual( self.connection(_lv.GetItem("Aaa", {"h": "3"})).item, { "h": "3", "a": "zzz" })
def test_simple_delete(self): self.connection(_lv.PutItem("Aaa", {"h": "simple", "a": "yyy"})) self.connection(_lv.DeleteItem("Aaa", {"h": "simple"})) self.assertEqual( self.connection(_lv.GetItem("Aaa", {"h": "simple"})).item, None)
def test_return_consumed_capacity_total(self): r = self.connection( _lv.GetItem(self.table, self.tab_key).return_consumed_capacity_total()) self.assertEqual(r.consumed_capacity.capacity_units, 0.5) self.assertEqual(r.consumed_capacity.global_secondary_indexes, None) self.assertEqual(r.consumed_capacity.local_secondary_indexes, None) self.assertEqual(r.consumed_capacity.table, None) self.assertEqual(r.consumed_capacity.table_name, self.table)
def test_set(self): r = self.connection( _lv.UpdateItem("Aaa", { "h": "set" }).set("a", ":v").set("#p", ":w").expression_attribute_value( "v", "aaa").expression_attribute_value( "w", "bbb").expression_attribute_name("p", "b")) self.assertEqual( self.connection(_lv.GetItem("Aaa", {"h": "set"})).item, { "h": "set", "a": "aaa", "b": "bbb" })
def test_get_with_projections(self): self.connection( _lv.PutItem( "Aaa", { "h": "attrs", "a": "yyy", "b": { "c": ["d1", "d2", "d3"] }, "e": 42, "f": "nope" })) r = self.connection( _lv.GetItem("Aaa", { "h": "attrs" }).project("b.c[1]", "e")) self.assertEqual(r.item, {"b": {"c": ["d2"]}, "e": 42})
def test_put_all_types(self): self.connection( _lv.PutItem( "Aaa", { "h": "all", "number": 42, "string": "àoé", "binary": b"\xFF\x00\xFF", "bool 1": True, "bool 2": False, "null": None, "number set": set([42, 43]), "string set": set(["éoà", "bar"]), "binary set": set([b"\xFF", b"\xAB"]), "list": [True, 42], "map": { "a": True, "b": 42 }, })) self.assertEqual( self.connection(_lv.GetItem("Aaa", {"h": "all"})).item, { "h": "all", "number": 42, "string": "àoé", "binary": b"\xFF\x00\xFF", "bool 1": True, "bool 2": False, "null": None, "number set": set([42, 43]), "string set": set(["éoà", "bar"]), "binary set": set([b"\xFF", b"\xAB"]), "list": [True, 42], "map": { "a": True, "b": 42 }, })
def test_simple_get(self): self.connection(_lv.PutItem("Aaa", {"h": "get", "a": "yyy"})) r = self.connection(_lv.GetItem("Aaa", {"h": "get"})) self.assertEqual(r.item, {"h": "get", "a": "yyy"})
def test_bad_key_type(self): with self.assertRaises(_lv.ValidationException): self.connection(_lv.GetItem("Aaa", {"h": 42}))
def test_unexisting_table(self): with self.assertRaises(_lv.ResourceNotFoundException): self.connection(_lv.GetItem("Bbb", {}))
def test_simple_put(self): self.connection(_lv.PutItem("Aaa", {"h": "simple"})) self.assertEqual( self.connection(_lv.GetItem("Aaa", {"h": "simple"})).item, {"h": "simple"})