def test_return_old_values(self): self.connection(_lv.PutItem("Aaa", {"h": "return", "a": b"yyy"})) r = self.connection( _lv.PutItem("Aaa", { "h": "return", "b": b"xxx" }).return_values_all_old()) self.assertEqual(r.attributes, {"h": "return", "a": b"yyy"})
def test_complex_update(self): self.connection( _lv.PutItem( "Aaa", { "h": "complex", "a": "a", "b": "b", "c": "c", "d": set([41, 43]), "e": 42, "f": set([41, 42, 43]), "g": set([39, 40]), })) r = self.connection( _lv.UpdateItem("Aaa", { "h": "complex" }).set("a", ":s").set("b", ":i").remove("c").add("d", "s").add( "e", "i").delete("f", "s").delete("g", "s").expression_attribute_value( "s", set([42, 43])).expression_attribute_value( "i", 52).return_values_all_new()) self.assertEqual( r.attributes, { "h": "complex", "a": set([42, 43]), "b": 52, "d": set([41, 42, 43]), "e": 94, "f": set([41]), "g": set([39, 40]), })
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_item_collection_metrics_size(self): r = self.connection( _lv.PutItem(self.table, self.item).return_item_collection_metrics_size()) self.assertEqual(r.item_collection_metrics.item_collection_key, {"tab_h": "0"}) self.assertEqual(r.item_collection_metrics.size_estimate_range_gb[0], 0.0) self.assertEqual(r.item_collection_metrics.size_estimate_range_gb[1], 1.0)
def test_add_and_delete_from_same_set(self): self.connection(_lv.PutItem("Aaa", {"h": "expr", "a": {1, 2, 3}})) # A bit sad: you can't add to and delete from the same set with self.assertRaises(_lv.ValidationException): self.connection( _lv.UpdateItem("Aaa", { "h": "expr" }).delete("a", "three").add("a", "four").expression_attribute_value( "three", {3}).expression_attribute_value( "four", {4}).return_values_all_new())
def test_return_consumed_capacity_indexes(self): r = self.connection( _lv.PutItem(self.table, self.item).return_consumed_capacity_indexes()) self.assertEqual(r.consumed_capacity.capacity_units, 3.0) self.assertEqual( r.consumed_capacity.global_secondary_indexes["gsi"].capacity_units, 1.0) self.assertEqual( r.consumed_capacity.local_secondary_indexes["lsi"].capacity_units, 1.0) self.assertEqual(r.consumed_capacity.table.capacity_units, 1.0) self.assertEqual(r.consumed_capacity.table_name, self.table)
def test_condition_expression(self): self.connection(_lv.PutItem("Aaa", {"h": "expr", "a": 42, "b": 42})) r = self.connection( _lv.UpdateItem("Aaa", { "h": "expr" }).set("checked", ":true").expression_attribute_value( "true", True).condition_expression("a=b").return_values_all_new()) self.assertEqual(r.attributes, { "h": "expr", "a": 42, "b": 42, "checked": True })
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 setUp(self): super(BatchGetItemConnectedIntegTests, self).setUp() self.connection(_lv.PutItem(self.table, self.item))
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_simple_put(self): self.connection(_lv.PutItem("Aaa", {"h": "simple"})) self.assertEqual( self.connection(_lv.GetItem("Aaa", {"h": "simple"})).item, {"h": "simple"})