def test_creds_secret_can_be_overwritten_create_branch(self, monkeypatch): task = CreateBranch(token_secret="MY_SECRET") req = MagicMock() monkeypatch.setattr("prefect.tasks.github.repos.requests", req) with set_temporary_config({"cloud.use_local_secrets": True}): with prefect.context(secrets=dict(MY_SECRET={"key": 42})): with pytest.raises(ValueError): task.run(repo="org/repo", branch_name="new") assert req.get.call_args[1]["headers"][ "AUTHORIZATION"] == "token {'key': 42}"
def test_creds_are_pulled_from_secret_at_runtime_create_branch( self, monkeypatch): task = CreateBranch(token_secret="GITHUB_ACCESS_TOKEN") req = MagicMock() monkeypatch.setattr("prefect.tasks.github.repos.requests", req) with prefect.context(secrets=dict(GITHUB_ACCESS_TOKEN={"key": 42})): with pytest.raises(ValueError, match="not found"): task.run(repo="org/repo", branch_name="new") assert req.get.call_args[1]["headers"][ "AUTHORIZATION"] == "token {'key': 42}"
def test_base_name_is_filtered_for(monkeypatch): task = CreateBranch(base="BOB", branch_name="NEWBRANCH") payload = [{"ref": "refs/heads/BOB", "object": {"sha": "salty"}}] req = MagicMock(get=MagicMock(return_value=MagicMock(json=MagicMock( return_value=payload)))) monkeypatch.setattr("prefect.tasks.github.repos.requests", req) task.run(repo="org/repo", token={"key": 42}) assert req.post.call_args[1]["json"] == { "ref": "refs/heads/NEWBRANCH", "sha": "salty", }
def test_creds_are_pulled_from_secret_at_runtime_create_branch( self, monkeypatch): task = CreateBranch() req = MagicMock() monkeypatch.setattr("prefect.tasks.github.repos.requests", req) with set_temporary_config({"cloud.use_local_secrets": True}): with prefect.context(secrets=dict( GITHUB_ACCESS_TOKEN={"key": 42})): with pytest.raises(ValueError) as exc: task.run(repo="org/repo", branch_name="new") assert req.get.call_args[1]["headers"][ "AUTHORIZATION"] == "token {'key': 42}" assert "not found" in str(exc.value)
def test_base_name_is_filtered_for(monkeypatch): task = CreateBranch(base="BOB", branch_name="NEWBRANCH") payload = [{"ref": "refs/heads/BOB", "object": {"sha": "salty"}}] req = MagicMock(get=MagicMock(return_value=MagicMock(json=MagicMock( return_value=payload)))) monkeypatch.setattr("prefect.tasks.github.repos.requests", req) with set_temporary_config({"cloud.use_local_secrets": True}): with prefect.context(secrets=dict(GITHUB_ACCESS_TOKEN={"key": 42})): task.run(repo="org/repo") assert req.post.call_args[1]["json"] == { "ref": "refs/heads/NEWBRANCH", "sha": "salty", }
def test_base_name_is_filtered_for(monkeypatch): task = CreateBranch(base="BOB", branch_name="NEWBRANCH") payload = [{"ref": "refs/heads/BOB", "object": {"sha": "salty"}}] get = MagicMock(return_value=MagicMock(json=MagicMock( return_value=payload))) post = MagicMock() monkeypatch.setattr(requests, "get", get) monkeypatch.setattr(requests, "post", post) task.run(repo="org/repo", token={"key": 42}) assert post.call_args[1]["json"] == { "ref": "refs/heads/NEWBRANCH", "sha": "salty", }
def test_branch_name_is_required_eventually(self): task = CreateBranch(repo="org/bob") with pytest.raises(ValueError) as exc: task.run() assert "branch name" in str(exc.value)
def test_repo_is_required_eventually(self): task = CreateBranch(branch_name="bob") with pytest.raises(ValueError) as exc: task.run() assert "repo" in str(exc.value)
def test_branch_name_is_required_eventually(self): task = CreateBranch(repo="org/bob") with pytest.raises(ValueError, match="branch name"): task.run()
def test_repo_is_required_eventually(self): task = CreateBranch(branch_name="bob") with pytest.raises(ValueError, match="repo"): task.run()