Beispiel #1
0
 def test_unlock_persistent_graph_no_such_key(
         self, mocker: MockerFixture) -> None:
     """Test unlock_persistent_graph empty graph NoSuchKey."""
     mocker.patch.object(
         CfnginContext,
         "persistent_graph_location",
         {
             "Bucket": "test-bucket",
             "Key": "something.json"
         },
     )
     mocker.patch.object(CfnginContext, "persistent_graph_locked", True)
     mocker.patch.object(CfnginContext, "persistent_graph_lock_code", "123")
     obj = CfnginContext()
     obj.persistent_graph = Graph.from_dict({}, context=obj)
     stubber = Stubber(obj.s3_client)
     stubber.add_response(
         "get_object",
         {"Body": "{}".encode()},
         {
             "ResponseContentType": "application/json",
             **obj.persistent_graph_location,
         },
     )
     stubber.add_client_error("delete_object_tagging", "NoSuchKey")
     with stubber:
         assert obj.unlock_persistent_graph("123")
Beispiel #2
0
 def test_unlock_persistent_graph(self, graph_dict: Dict[str, List[str]],
                                  mocker: MockerFixture) -> None:
     """Test unlock_persistent_graph."""
     mocker.patch.object(
         CfnginContext,
         "persistent_graph_location",
         {
             "Bucket": "test-bucket",
             "Key": "something.json"
         },
     )
     mocker.patch.object(CfnginContext, "persistent_graph_locked", True)
     mocker.patch.object(CfnginContext, "persistent_graph_lock_code", "123")
     obj = CfnginContext()
     obj.persistent_graph = Graph.from_dict(graph_dict, context=obj)
     stubber = Stubber(obj.s3_client)
     if not graph_dict:
         stubber.add_response(
             "get_object",
             {"Body": "{}".encode()},
             {
                 "ResponseContentType": "application/json",
                 **obj.persistent_graph_location,
             },
         )
     stubber.add_response("delete_object_tagging", {},
                          obj.persistent_graph_location)
     with stubber:
         assert obj.unlock_persistent_graph("123")
Beispiel #3
0
 def test_unlock_persistent_graph_empty_no_such_key(
         self, mocker: MockerFixture) -> None:
     """Test unlock_persistent_graph empty graph NoSuchKey."""
     mocker.patch.object(
         CfnginContext,
         "persistent_graph_location",
         {
             "Bucket": "test-bucket",
             "Key": "something.json"
         },
     )
     obj = CfnginContext()
     obj.persistent_graph = Graph.from_dict({}, context=obj)
     stubber = Stubber(obj.s3_client)
     stubber.add_client_error("get_object", "NoSuchKey")
     with stubber:
         assert obj.unlock_persistent_graph("123")
Beispiel #4
0
 def test_put_persistent_graph_not_locked(self,
                                          mocker: MockerFixture) -> None:
     """Test put_persistent_graph not locked."""
     mocker.patch.object(
         CfnginContext,
         "persistent_graph_location",
         {
             "Bucket": "test-bucket",
             "Key": "something.json"
         },
     )
     mocker.patch.object(CfnginContext, "persistent_graph_locked", False)
     obj = CfnginContext()
     obj.persistent_graph = Graph.from_dict(self.persist_graph_raw,
                                            context=obj)
     with pytest.raises(PersistentGraphUnlocked):
         obj.put_persistent_graph("123")
Beispiel #5
0
 def test_put_persistent_graph_empty(self, mocker: MockerFixture) -> None:
     """Test put_persistent_graph empty."""
     mocker.patch.object(
         CfnginContext,
         "persistent_graph_location",
         {
             "Bucket": "test-bucket",
             "Key": "something.json"
         },
     )
     obj = CfnginContext()
     obj.persistent_graph = Graph.from_dict({}, context=obj)
     stubber = Stubber(obj.s3_client)
     stubber.add_response("delete_object", {},
                          obj.persistent_graph_location)
     with stubber:
         assert not obj.put_persistent_graph("123")
Beispiel #6
0
 def test_unlock_persistent_graph_lock_code_mismatch(
         self, mocker: MockerFixture) -> None:
     """Test unlock_persistent_graph lock code mismatch."""
     mocker.patch.object(
         CfnginContext,
         "persistent_graph_location",
         {
             "Bucket": "test-bucket",
             "Key": "something.json"
         },
     )
     mocker.patch.object(CfnginContext, "persistent_graph_locked", True)
     mocker.patch.object(CfnginContext, "persistent_graph_lock_code", "0")
     obj = CfnginContext()
     obj.persistent_graph = Graph.from_dict(self.persist_graph_raw,
                                            context=obj)
     with pytest.raises(PersistentGraphCannotUnlock):
         assert obj.unlock_persistent_graph("123")
Beispiel #7
0
 def test_put_persistent_graph(self, mocker: MockerFixture) -> None:
     """Test put_persistent_graph."""
     mocker.patch.object(
         CfnginContext,
         "persistent_graph_location",
         {
             "Bucket": "test-bucket",
             "Key": "something.json"
         },
     )
     mocker.patch.object(CfnginContext, "persistent_graph_locked", True)
     mocker.patch.object(CfnginContext, "persistent_graph_lock_code", "123")
     obj = CfnginContext()
     obj.persistent_graph = Graph.from_dict(self.persist_graph_raw,
                                            context=obj)
     stubber = Stubber(obj.s3_client)
     stubber.add_response(
         "put_object",
         {},
         {
             "Body":
             json.dumps(self.persist_graph_raw,
                        default=json_serial,
                        indent=4).encode(),
             "ServerSideEncryption":
             "AES256",
             "ACL":
             "bucket-owner-full-control",
             "ContentType":
             "application/json",
             "Tagging":
             "cfngin_lock_code=123",
             **obj.persistent_graph_location,
         },
     )
     with stubber:
         assert not obj.put_persistent_graph("123")