@@ -52,7 +52,7 @@ 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 )
5757
5858 session .register ("GET" , "/repos/foo/bar/actions/artifacts/789/zip" )(
@@ -70,12 +70,44 @@ def test_download_artifact(gh, session, zip_bytes):
7070 assert result == "bar"
7171
7272
73+ def test_download_artifact_from_page_2 (gh , session , zip_bytes ):
74+ artifacts_page_1 = [
75+ {"name" : "test" , "id" : 000 },
76+ ]
77+ artifacts_page_2 = [
78+ {"name" : "bar" , "id" : 456 },
79+ {"name" : "foo" , "id" : 789 },
80+ ]
81+ session .register ("GET" , "/repos/foo/bar/actions/runs/123/artifacts" )(
82+ json = {"artifacts" : artifacts_page_1 , "total_count" : 3 }
83+ )
84+ session .register (
85+ "GET" ,
86+ "/repos/foo/bar/actions/runs/123/artifacts" ,
87+ params = {"page" : "2" },
88+ )(json = {"artifacts" : artifacts_page_2 , "total_count" : 3 })
89+
90+ session .register ("GET" , "/repos/foo/bar/actions/artifacts/789/zip" )(
91+ content = zip_bytes (filename = "foo.txt" , content = "bar" )
92+ )
93+
94+ result = github .download_artifact (
95+ github = gh ,
96+ repository = "foo/bar" ,
97+ artifact_name = "foo" ,
98+ run_id = 123 ,
99+ filename = pathlib .Path ("foo.txt" ),
100+ )
101+
102+ assert result == "bar"
103+
104+
73105def test_download_artifact__no_artifact (gh , session ):
74106 artifacts = [
75107 {"name" : "bar" , "id" : 456 },
76108 ]
77109 session .register ("GET" , "/repos/foo/bar/actions/runs/123/artifacts" )(
78- json = {"artifacts" : artifacts }
110+ json = {"artifacts" : artifacts , "total_count" : 1 }
79111 )
80112
81113 with pytest .raises (github .NoArtifact ):
@@ -89,12 +121,15 @@ def test_download_artifact__no_artifact(gh, session):
89121
90122
91123def test_download_artifact__no_file (gh , session , zip_bytes ):
92- artifacts = [
93- {"name" : "foo" , "id" : 789 },
94- ]
124+ artifacts = [{"name" : "foo" , "id" : 789 }]
95125 session .register ("GET" , "/repos/foo/bar/actions/runs/123/artifacts" )(
96126 json = {"artifacts" : artifacts }
97127 )
128+ session .register (
129+ "GET" ,
130+ "/repos/foo/bar/actions/runs/123/artifacts" ,
131+ params = {"page" : "2" },
132+ )(json = {})
98133
99134 session .register ("GET" , "/repos/foo/bar/actions/artifacts/789/zip" )(
100135 content = zip_bytes (filename = "foo.txt" , content = "bar" )
@@ -109,6 +144,59 @@ def test_download_artifact__no_file(gh, session, zip_bytes):
109144 )
110145
111146
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+
112200def test_get_branch_from_workflow_run (gh , session ):
113201 json = {
114202 "head_branch" : "other" ,
0 commit comments