@@ -52,13 +52,8 @@ def test_download_artifact(gh, session, zip_bytes):
5252 {"name" : "foo" , "id" : 789 },
5353 ]
5454 session .register ("GET" , "/repos/foo/bar/actions/runs/123/artifacts" )(
55- json = {"artifacts" : artifacts }
55+ json = {"artifacts" : artifacts , "total_count" : 2 }
5656 )
57- session .register (
58- "GET" ,
59- "/repos/foo/bar/actions/runs/123/artifacts" ,
60- params = {"page" : "2" },
61- )(json = {})
6257
6358 session .register ("GET" , "/repos/foo/bar/actions/artifacts/789/zip" )(
6459 content = zip_bytes (filename = "foo.txt" , content = "bar" )
@@ -84,18 +79,13 @@ def test_download_artifact_from_page_2(gh, session, zip_bytes):
8479 {"name" : "foo" , "id" : 789 },
8580 ]
8681 session .register ("GET" , "/repos/foo/bar/actions/runs/123/artifacts" )(
87- json = {"artifacts" : artifacts_page_1 }
82+ json = {"artifacts" : artifacts_page_1 , "total_count" : 3 }
8883 )
8984 session .register (
9085 "GET" ,
9186 "/repos/foo/bar/actions/runs/123/artifacts" ,
9287 params = {"page" : "2" },
93- )(json = {"artifacts" : artifacts_page_2 })
94- session .register (
95- "GET" ,
96- "/repos/foo/bar/actions/runs/123/artifacts" ,
97- params = {"page" : "3" },
98- )(json = {})
88+ )(json = {"artifacts" : artifacts_page_2 , "total_count" : 3 })
9989
10090 session .register ("GET" , "/repos/foo/bar/actions/artifacts/789/zip" )(
10191 content = zip_bytes (filename = "foo.txt" , content = "bar" )
@@ -117,13 +107,8 @@ def test_download_artifact__no_artifact(gh, session):
117107 {"name" : "bar" , "id" : 456 },
118108 ]
119109 session .register ("GET" , "/repos/foo/bar/actions/runs/123/artifacts" )(
120- json = {"artifacts" : artifacts }
110+ json = {"artifacts" : artifacts , "total_count" : 1 }
121111 )
122- session .register (
123- "GET" ,
124- "/repos/foo/bar/actions/runs/123/artifacts" ,
125- params = {"page" : "2" },
126- )(json = {})
127112
128113 with pytest .raises (github .NoArtifact ):
129114 github .download_artifact (
@@ -136,9 +121,7 @@ def test_download_artifact__no_artifact(gh, session):
136121
137122
138123def test_download_artifact__no_file (gh , session , zip_bytes ):
139- artifacts = [
140- {"name" : "foo" , "id" : 789 },
141- ]
124+ artifacts = [{"name" : "foo" , "id" : 789 }]
142125 session .register ("GET" , "/repos/foo/bar/actions/runs/123/artifacts" )(
143126 json = {"artifacts" : artifacts }
144127 )
@@ -161,6 +144,59 @@ def test_download_artifact__no_file(gh, session, zip_bytes):
161144 )
162145
163146
147+ def test_fetch_artifacts_empty_response (gh , session ):
148+ session .register ("GET" , "/repos/foo/bar/actions/runs/123/artifacts" )(
149+ json = {"artifacts" : [], "total_count" : 0 }
150+ )
151+
152+ repo_path = gh .repos ("foo/bar" )
153+
154+ result = github ._fetch_artifacts (
155+ repo_path = repo_path ,
156+ run_id = 123 ,
157+ )
158+
159+ assert not list (result )
160+
161+
162+ def test_fetch_artifacts_single_page (gh , session ):
163+ artifacts = [{"name" : "bar" , "id" : 456 }]
164+
165+ session .register ("GET" , "/repos/foo/bar/actions/runs/123/artifacts" )(
166+ json = {"artifacts" : artifacts , "total_count" : 1 }
167+ )
168+
169+ repo_path = gh .repos ("foo/bar" )
170+
171+ result = github ._fetch_artifacts (
172+ repo_path = repo_path ,
173+ run_id = 123 ,
174+ )
175+
176+ assert list (result ) == artifacts
177+
178+
179+ def test_fetch_artifacts_multiple_pages (gh , session ):
180+ artifacts_page_1 = [{"name" : "bar" , "id" : 456 }]
181+ artifacts_page_2 = [{"name" : "bar" , "id" : 789 }]
182+
183+ session .register ("GET" , "/repos/foo/bar/actions/runs/123/artifacts" )(
184+ json = {"artifacts" : artifacts_page_1 , "total_count" : 2 }
185+ )
186+ session .register (
187+ "GET" , "/repos/foo/bar/actions/runs/123/artifacts" , params = {"page" : "2" }
188+ )(json = {"artifacts" : artifacts_page_2 , "total_count" : 2 })
189+
190+ repo_path = gh .repos ("foo/bar" )
191+
192+ result = github ._fetch_artifacts (
193+ repo_path = repo_path ,
194+ run_id = 123 ,
195+ )
196+
197+ assert list (result ) == artifacts_page_1 + artifacts_page_2
198+
199+
164200def test_get_branch_from_workflow_run (gh , session ):
165201 json = {
166202 "head_branch" : "other" ,
0 commit comments