コード例 #1
0
ファイル: test_table_mixins.py プロジェクト: iw/dynamatic
    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"))
コード例 #2
0
ファイル: test_table_mixins.py プロジェクト: iw/dynamatic
    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"
コード例 #3
0
 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
         },
     }
コード例 #4
0
 def test_serialize(self):
     response = serialize(Set("foo", "bar"))
     assert response == {
         "UpdateExpression": "SET #ref1 = :val1 ",
         "ExpressionAttributeNames": {
             "#ref1": "foo"
         },
         "ExpressionAttributeValues": {
             ":val1": "bar"
         },
     }
コード例 #5
0
 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"
         },
     }
コード例 #6
0
ファイル: test_table_mixins.py プロジェクト: iw/dynamatic
 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"}
コード例 #7
0
ファイル: test_table_mixins.py プロジェクト: iw/dynamatic
 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"