@@ -52,7 +52,7 @@ def test_download_artifact(gh, session, zip_bytes):
52
52
{"name" : "foo" , "id" : 789 },
53
53
]
54
54
session .register ("GET" , "/repos/foo/bar/actions/runs/123/artifacts" )(
55
- json = {"artifacts" : artifacts }
55
+ json = {"artifacts" : artifacts , "total_count" : 2 }
56
56
)
57
57
58
58
session .register ("GET" , "/repos/foo/bar/actions/artifacts/789/zip" )(
@@ -70,12 +70,44 @@ def test_download_artifact(gh, session, zip_bytes):
70
70
assert result == "bar"
71
71
72
72
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
+
73
105
def test_download_artifact__no_artifact (gh , session ):
74
106
artifacts = [
75
107
{"name" : "bar" , "id" : 456 },
76
108
]
77
109
session .register ("GET" , "/repos/foo/bar/actions/runs/123/artifacts" )(
78
- json = {"artifacts" : artifacts }
110
+ json = {"artifacts" : artifacts , "total_count" : 1 }
79
111
)
80
112
81
113
with pytest .raises (github .NoArtifact ):
@@ -89,12 +121,15 @@ def test_download_artifact__no_artifact(gh, session):
89
121
90
122
91
123
def test_download_artifact__no_file (gh , session , zip_bytes ):
92
- artifacts = [
93
- {"name" : "foo" , "id" : 789 },
94
- ]
124
+ artifacts = [{"name" : "foo" , "id" : 789 }]
95
125
session .register ("GET" , "/repos/foo/bar/actions/runs/123/artifacts" )(
96
126
json = {"artifacts" : artifacts }
97
127
)
128
+ session .register (
129
+ "GET" ,
130
+ "/repos/foo/bar/actions/runs/123/artifacts" ,
131
+ params = {"page" : "2" },
132
+ )(json = {})
98
133
99
134
session .register ("GET" , "/repos/foo/bar/actions/artifacts/789/zip" )(
100
135
content = zip_bytes (filename = "foo.txt" , content = "bar" )
@@ -109,6 +144,59 @@ def test_download_artifact__no_file(gh, session, zip_bytes):
109
144
)
110
145
111
146
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
+
112
200
def test_get_branch_from_workflow_run (gh , session ):
113
201
json = {
114
202
"head_branch" : "other" ,
0 commit comments