def test_add_flow_to_codecommit_storage(): storage = CodeCommit(repo="test/repo", path="flow.py", commit="master") f = Flow("test") assert f.name not in storage assert storage.add_flow(f) == "flow.py" assert f.name in storage
def test_add_flow_to_codecommit_already_added(): storage = CodeCommit(repo="test/repo", path="flow.py", commit="master") f = Flow("test") assert f.name not in storage assert storage.add_flow(f) == "flow.py" assert f.name in storage with pytest.raises(ValueError): storage.add_flow(f)
def test_get_flow_codecommit(monkeypatch): client = MagicMock() d = {"fileContent": b'import prefect; flow = prefect.Flow("test")'} client.__getitem__.side_effect = d.__getitem__ boto3 = MagicMock(get_file=MagicMock(return_value=client)) monkeypatch.setattr("prefect.storage.CodeCommit._boto3_client", boto3) f = Flow("test") monkeypatch.setattr( "prefect.storage.github.extract_flow_from_file", MagicMock(return_value=f), ) with pytest.raises(ValueError): storage = CodeCommit(repo="test/repo") storage.get_flow() storage = CodeCommit(repo="test/repo", path="flow", commit="master") assert f.name not in storage flow_location = storage.add_flow(f) new_flow = storage.get_flow(flow_location) assert new_flow.run()
def test_codecommit_client_property(monkeypatch): client = MagicMock() boto3 = MagicMock(client=MagicMock(return_value=client)) monkeypatch.setattr("boto3.client", boto3) storage = CodeCommit( repo="test/repo", client_options={ "endpoint_url": "http://some-endpoint", "use_ssl": False }, ) credentials = dict(ACCESS_KEY="id", SECRET_ACCESS_KEY="secret", SESSION_TOKEN="session") with context(secrets=dict(AWS_CREDENTIALS=credentials)): boto3_client = storage._boto3_client assert boto3_client boto3.assert_called_with( "codecommit", aws_access_key_id="id", aws_secret_access_key="secret", aws_session_token="session", endpoint_url="http://some-endpoint", use_ssl=False, )
def test_serialize_codecommit_storage(): storage = CodeCommit( repo="test/repo", path="flow.py", commit="master", client_options={"endpoint_url": "http://some-endpoint", "use_ssl": False}, secrets=["auth"], ) serialized_storage = storage.serialize() assert serialized_storage["type"] == "CodeCommit" assert serialized_storage["repo"] == "test/repo" assert serialized_storage["path"] == "flow.py" assert serialized_storage["commit"] == "master" assert serialized_storage["client_options"] == { "endpoint_url": "http://some-endpoint", "use_ssl": False, } assert serialized_storage["secrets"] == ["auth"]
def test_get_flow_codecommit(monkeypatch): client = MagicMock() d = {"fileContent": b'import prefect; flow = prefect.Flow("test")'} client.__getitem__.side_effect = d.__getitem__ boto3 = MagicMock(get_file=MagicMock(return_value=client)) monkeypatch.setattr("prefect.storage.CodeCommit._boto3_client", boto3) f = Flow("test") extract_flow_from_file = MagicMock(return_value=f) monkeypatch.setattr( "prefect.storage.codecommit.extract_flow_from_file", extract_flow_from_file, ) storage = CodeCommit(repo="test/repo", path="flow", commit="master") assert f.name not in storage storage.add_flow(f) new_flow = storage.get_flow(f.name) assert extract_flow_from_file.call_args[1]["flow_name"] == f.name assert new_flow.run()
def test_create_codecommit_storage_init_args(): storage = CodeCommit( repo="test/repo", path="flow.py", commit="master", client_options={"endpoint_url": "http://some-endpoint", "use_ssl": False}, secrets=["auth"], ) assert storage assert storage.flows == dict() assert storage.repo == "test/repo" assert storage.path == "flow.py" assert storage.commit == "master" assert storage.client_options == { "endpoint_url": "http://some-endpoint", "use_ssl": False, } assert storage.secrets == ["auth"]
}), run, ) assert env_vars["PREFECT__LOGGING__LEVEL"] == expected_logging_level @pytest.mark.parametrize( "storage", [ Local(directory="test"), GCS(bucket="test"), S3(bucket="test"), Azure(container="test"), GitLab("test/repo", path="path/to/flow.py"), Bitbucket(project="PROJECT", repo="test-repo", path="test-flow.py"), CodeCommit("test/repo", path="path/to/flow.py"), Webhook( build_request_kwargs={"url": "test-service/upload"}, build_request_http_method="POST", get_flow_request_kwargs={"url": "test-service/download"}, get_flow_request_http_method="GET", ), ], ) def test_local_agent_deploy_processes_valid_storage(storage, monkeypatch): popen = MagicMock() monkeypatch.setattr("prefect.agent.local.agent.Popen", popen) agent = LocalAgent() agent.deploy_flow(flow_run=GraphQLResult({ "flow":
def test_create_codecommit_storage(): storage = CodeCommit(repo="test/repo") assert storage assert storage.logger