def test_prefers_passed_credentials_over_secrets(self, monkeypatch): gitlab = MagicMock() monkeypatch.setattr("prefect.utilities.git.Gitlab", gitlab) desired_credentials = {"GITLAB_ACCESS_TOKEN": "PROVIDED_KEY"} with set_temporary_config({"cloud.use_local_secrets": True}): with prefect.context(secrets=dict( GITlab_ACCESS_TOKEN="ACCESS_TOKEN")): get_gitlab_client(credentials=desired_credentials) assert gitlab.call_args[1]["private_token"] == "PROVIDED_KEY"
def test_uses_context_secrets(self, monkeypatch): gitlab = MagicMock() monkeypatch.setattr("prefect.utilities.git.Gitlab", gitlab) with set_temporary_config({"cloud.use_local_secrets": True}): with prefect.context(secrets=dict( GITLAB_ACCESS_TOKEN="ACCESS_TOKEN")): get_gitlab_client() assert gitlab.call_args[1]["private_token"] == "ACCESS_TOKEN"
def test_creds_default_to_environment(self, monkeypatch): if "GITLAB_ACCESS_TOKEN" in os.environ: del os.environ["GITLAB_ACCESS_TOKEN"] gitlab = MagicMock() monkeypatch.setattr("prefect.utilities.git.Gitlab", gitlab) get_gitlab_client() assert gitlab.call_args[1].get("private_token") is None monkeypatch.setenv("GITLAB_ACCESS_TOKEN", "TOKEN") get_gitlab_client() assert gitlab.call_args[1]["private_token"] == "TOKEN"
def _gitlab_client(self): # type: ignore from prefect.utilities.git import get_gitlab_client return get_gitlab_client(host=self.host)
def test_specify_host(self, monkeypatch): gitlab = MagicMock() monkeypatch.setattr("prefect.utilities.git.Gitlab", gitlab) get_gitlab_client(host="http://localhost:1234") assert gitlab.call_args[0][0] == "http://localhost:1234"
def test_default_to_cloud(self, monkeypatch): gitlab = MagicMock() monkeypatch.setattr("prefect.utilities.git.Gitlab", gitlab) get_gitlab_client() assert gitlab.call_args[0][0] == "https://gitlab.com"