Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/taskgraph/util/taskcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_taskcluster_client(service: str):
if "TASKCLUSTER_PROXY_URL" in os.environ:
options = {"rootUrl": os.environ["TASKCLUSTER_PROXY_URL"]}
else:
options = taskcluster.optionsFromEnvironment()
options = taskcluster.optionsFromEnvironment({"rootUrl": get_root_url()})

return getattr(taskcluster, service[0].upper() + service[1:])(options)

Expand Down
55 changes: 47 additions & 8 deletions test/test_util_taskcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import datetime
import os
from unittest.mock import MagicMock

import pytest

Expand All @@ -19,13 +19,8 @@ def root_url():
@pytest.fixture(autouse=True)
def mock_environ(monkeypatch, root_url):
# Ensure user specified environment variables don't interfere with URLs.
monkeypatch.setattr(
os,
"environ",
{
"TASKCLUSTER_ROOT_URL": root_url,
},
)
monkeypatch.setenv("TASKCLUSTER_ROOT_URL", root_url)
monkeypatch.delenv("TASKCLUSTER_PROXY_URL", raising=False)


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -566,3 +561,47 @@ def test_get_ancestors_string(responses, root_url):
"eee": "task-eee",
}
assert got == expected, f"got: {got}, expected: {expected}"


def test_get_taskcluster_client(monkeypatch, root_url):
tc.get_root_url.cache_clear()
tc.get_taskcluster_client.cache_clear()
service_mock = MagicMock()
monkeypatch.setattr("taskcluster.Foo", service_mock, raising=False)

# No environment and no default → error
monkeypatch.delenv("TASKCLUSTER_ROOT_URL", raising=False)
monkeypatch.delenv("TASKCLUSTER_PROXY_URL", raising=False)
monkeypatch.setattr(tc, "PRODUCTION_TASKCLUSTER_ROOT_URL", None)
with pytest.raises(RuntimeError):
tc.get_taskcluster_client("foo")
service_mock.assert_not_called()

tc.get_root_url.cache_clear()
tc.get_taskcluster_client.cache_clear()
service_mock.reset_mock()

# No environment, use default
monkeypatch.setattr(
tc, "PRODUCTION_TASKCLUSTER_ROOT_URL", "http://taskcluster-prod"
)
tc.get_taskcluster_client("foo")
service_mock.assert_called_once_with({"rootUrl": "http://taskcluster-prod"})

tc.get_root_url.cache_clear()
tc.get_taskcluster_client.cache_clear()
service_mock.reset_mock()

# root url from environment
monkeypatch.setenv("TASKCLUSTER_ROOT_URL", "http://taskcluster-env")
tc.get_taskcluster_client("foo")
service_mock.assert_called_once_with({"rootUrl": "http://taskcluster-env"})

tc.get_root_url.cache_clear()
tc.get_taskcluster_client.cache_clear()
service_mock.reset_mock()

# proxy url from environment
monkeypatch.setenv("TASKCLUSTER_PROXY_URL", "http://taskcluster-proxy")
tc.get_taskcluster_client("foo")
service_mock.assert_called_once_with({"rootUrl": "http://taskcluster-proxy"})
Loading