def test_update_with_conditions(self): self.table.update(("Partition1", "Sort1"), Set("status", "in_progress"), condition=Attr("status").eq("active")) with self.assertRaises(ConditionalCheckFailedException): self.table.update(("Partition1", "Sort1"), Set("status", "in_progress"), condition=Attr("status").eq("active"))
def test_update_set_if_not_exists(self): self.table.update( ("Partition1", "Sort1"), Set("status", "in_progress", if_not_exists="semiphore"), ) item = self.table.get(("Partition1", "Sort1")) assert item["status"] == "in_progress" self.table.update(("Partition1", "Sort1"), Set("status", "archived", if_not_exists="status")) # Update should have failed item = self.table.get(("Partition1", "Sort1")) assert item["status"] == "in_progress"
def test_serialize_multiple_expressions(self): response = serialize([Set("foo", "bar"), Set("biz", 5), Add("bar", 2)]) assert response == { "UpdateExpression": "SET #ref1 = :val1, #ref2 = :val2 ADD #ref3 :val3 ", "ExpressionAttributeNames": { "#ref1": "foo", "#ref2": "biz", "#ref3": "bar", }, "ExpressionAttributeValues": { ":val1": "bar", ":val2": 5, ":val3": 2 }, }
def test_serialize(self): response = serialize(Set("foo", "bar")) assert response == { "UpdateExpression": "SET #ref1 = :val1 ", "ExpressionAttributeNames": { "#ref1": "foo" }, "ExpressionAttributeValues": { ":val1": "bar" }, }
def test_serialize_if_not_exists(self): response = serialize(Set("foo", "bar", if_not_exists="biz")) assert response == { "UpdateExpression": "SET #ref1 = if_not_exists(#ref1b, :val1) ", "ExpressionAttributeNames": { "#ref1": "foo", "#ref1b": "biz" }, "ExpressionAttributeValues": { ":val1": "bar" }, }
def test_update_multiple_expressions(self): self.table.update( ("Partition1", "Sort1"), [ Set("status", "in_progress"), Increase("sequence", 10), Delete("tags", {"red"}), ], ) item = self.table.get(("Partition1", "Sort1")) assert item["status"] == "in_progress" assert item["sequence"] == 11 assert item["tags"] == {"blue", "green"}
def test_update_set(self): updates = Set("status", "in_progress") attributes = self.table.update(("Partition1", "Sort1"), updates) assert attributes == {} item = self.table.get(("Partition1", "Sort1")) assert item["status"] == "in_progress"