@@ -67,21 +67,41 @@ def test_get_root_url(monkeypatch):
6767
6868
6969def test_get_artifact_url (monkeypatch ):
70+ tc .get_root_url .cache_clear ()
7071 task_id = "abc"
7172 path = "public/log.txt"
73+ expected = "https://tc.example.com/api/queue/v1/task/abc/artifacts/public/log.txt"
74+ expected_proxy = (
75+ "https://taskcluster-proxy.net/api/queue/v1/task/abc/artifacts/public/log.txt"
76+ )
7277
73- # Test with default root URL
78+ # Test with default root URL (no proxy)
7479 tc .get_root_url .cache_clear ()
75- expected = "https://tc.example.com/api/queue/v1/task/abc/artifacts/public/log.txt"
7680 assert tc .get_artifact_url (task_id , path ) == expected
7781
78- # Test with proxy URL (takes priority )
82+ # Test that proxy URL is NOT used by default (since use_proxy defaults to False )
7983 monkeypatch .setenv ("TASKCLUSTER_PROXY_URL" , "https://taskcluster-proxy.net" )
8084 tc .get_root_url .cache_clear ()
81- expected_proxy = (
82- "https://taskcluster-proxy.net/api/queue/v1/task/abc/artifacts/public/log.txt"
85+ assert tc .get_artifact_url (task_id , path ) == expected
86+
87+ # Test with use_proxy=True (should use proxy URL)
88+ assert tc .get_artifact_url (task_id , path , use_proxy = True ) == expected_proxy
89+
90+ # Test with use_proxy=True but no proxy available (not in a task)
91+ monkeypatch .delenv ("TASKCLUSTER_PROXY_URL" )
92+ monkeypatch .delenv ("TASK_ID" , raising = False )
93+ tc .get_root_url .cache_clear ()
94+ with pytest .raises (RuntimeError ) as exc :
95+ tc .get_artifact_url (task_id , path , use_proxy = True )
96+ assert "taskcluster-proxy is not available when not executing in a task" in str (
97+ exc .value
8398 )
84- assert tc .get_artifact_url (task_id , path ) == expected_proxy
99+
100+ # Test with use_proxy=True but proxy not enabled (in a task without proxy)
101+ monkeypatch .setenv ("TASK_ID" , "some-task-id" )
102+ with pytest .raises (RuntimeError ) as exc :
103+ tc .get_artifact_url (task_id , path , use_proxy = True )
104+ assert "taskcluster-proxy is not enabled for this task" in str (exc .value )
85105
86106
87107def test_get_artifact (responses , root_url ):
0 commit comments