FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-gitlab/tests/unit/objects/test_packages.py at v8.6.0 · python-gitlab/python-gitlab · GitHub
python-gitlab
python-gitlab
Repository navigation
Code
Issues
16
(16)
Pull requests
15
(15)
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-gitlab
/
tests
/
unit
/
objects
/
test_packages.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
425 lines (357 loc) · 12.6 KB
Breadcrumbs
python-gitlab
/
tests
/
unit
/
objects
/
test_packages.py
Copy path
File metadata and controls
425 lines (357 loc) · 12.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
"""
GitLab API: https://docs.gitlab.com/ce/api/packages.html
"""
import
re
import
pytest
import
responses
from
gitlab
import
exceptions
as
exc
from
gitlab
.
v4
.
objects
import
(
GenericPackage
,
GroupPackage
,
ProjectPackage
,
ProjectPackageFile
,
ProjectPackagePipeline
,
)
package_content
=
{
"id"
:
1
,
"name"
:
"com/mycompany/my-app"
,
"version"
:
"1.0-SNAPSHOT"
,
"package_type"
:
"maven"
,
"_links"
: {
"web_path"
:
"/namespace1/project1/-/packages/1"
,
"delete_api_path"
:
"/namespace1/project1/-/packages/1"
,
},
"created_at"
:
"2019-11-27T03:37:38.711Z"
,
"pipeline"
: {
"id"
:
123
,
"status"
:
"pending"
,
"ref"
:
"new-pipeline"
,
"sha"
:
"a91957a858320c0e17f3a0eca7cfacbff50ea29a"
,
"web_url"
:
"https://example.com/foo/bar/pipelines/47"
,
"created_at"
:
"2016-08-11T11:28:34.085Z"
,
"updated_at"
:
"2016-08-11T11:32:35.169Z"
,
"user"
: {
"name"
:
"Administrator"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
,
},
},
"versions"
: [
{
"id"
:
2
,
"version"
:
"2.0-SNAPSHOT"
,
"created_at"
:
"2020-04-28T04:42:11.573Z"
,
"pipeline"
: {
"id"
:
234
,
"status"
:
"pending"
,
"ref"
:
"new-pipeline"
,
"sha"
:
"a91957a858320c0e17f3a0eca7cfacbff50ea29a"
,
"web_url"
:
"https://example.com/foo/bar/pipelines/58"
,
"created_at"
:
"2016-08-11T11:28:34.085Z"
,
"updated_at"
:
"2016-08-11T11:32:35.169Z"
,
"user"
: {
"name"
:
"Administrator"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
,
},
},
}
],
}
package_file_content
=
[
{
"id"
:
25
,
"package_id"
:
1
,
"created_at"
:
"2018-11-07T15:25:52.199Z"
,
"file_name"
:
"my-app-1.5-20181107.152550-1.jar"
,
"size"
:
2421
,
"file_md5"
:
"58e6a45a629910c6ff99145a688971ac"
,
"file_sha1"
:
"ebd193463d3915d7e22219f52740056dfd26cbfe"
,
"pipelines"
: [
{
"id"
:
123
,
"status"
:
"pending"
,
"ref"
:
"new-pipeline"
,
"sha"
:
"a91957a858320c0e17f3a0eca7cfacbff50ea29a"
,
"web_url"
:
"https://example.com/foo/bar/pipelines/47"
,
"created_at"
:
"2016-08-11T11:28:34.085Z"
,
"updated_at"
:
"2016-08-11T11:32:35.169Z"
,
"user"
: {
"name"
:
"Administrator"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
,
},
}
],
},
{
"id"
:
26
,
"package_id"
:
1
,
"created_at"
:
"2018-11-07T15:25:56.776Z"
,
"file_name"
:
"my-app-1.5-20181107.152550-1.pom"
,
"size"
:
1122
,
"file_md5"
:
"d90f11d851e17c5513586b4a7e98f1b2"
,
"file_sha1"
:
"9608d068fe88aff85781811a42f32d97feb440b5"
,
},
{
"id"
:
27
,
"package_id"
:
1
,
"created_at"
:
"2018-11-07T15:26:00.556Z"
,
"file_name"
:
"maven-metadata.xml"
,
"size"
:
767
,
"file_md5"
:
"6dfd0cce1203145a927fef5e3a1c650c"
,
"file_sha1"
:
"d25932de56052d320a8ac156f745ece73f6a8cd2"
,
},
]
package_pipeline_content
=
[
{
"id"
:
123
,
"iid"
:
1
,
"project_id"
:
1
,
"sha"
:
"a91957a858320c0e17f3a0eca7cfacbff50ea29a"
,
"ref"
:
"new-pipeline"
,
"status"
:
"failed"
,
"source"
:
"push"
,
"created_at"
:
"2016-08-11T11:28:34.085Z"
,
"updated_at"
:
"2016-08-11T11:32:35.169Z"
,
"web_url"
:
"https://example.com/foo/bar/pipelines/47"
,
"user"
: {
"id"
:
1
,
"username"
:
"root"
,
"name"
:
"Administrator"
,
"state"
:
"active"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80
\u0026
d=identicon"
,
"web_url"
:
"http://gdk.test:3001/root"
,
},
},
{
"id"
:
234
,
"iid"
:
2
,
"project_id"
:
1
,
"sha"
:
"a91957a858320c0e17f3a0eca7cfacbff50ea29a"
,
"ref"
:
"new-pipeline"
,
"status"
:
"failed"
,
"source"
:
"push"
,
"created_at"
:
"2016-08-11T11:28:34.085Z"
,
"updated_at"
:
"2016-08-11T11:32:35.169Z"
,
"web_url"
:
"https://example.com/foo/bar/pipelines/58"
,
"user"
: {
"id"
:
1
,
"username"
:
"root"
,
"name"
:
"Administrator"
,
"state"
:
"active"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80
\u0026
d=identicon"
,
"web_url"
:
"http://gdk.test:3001/root"
,
},
},
]
package_name
=
"hello-world"
package_version
=
"v1.0.0"
file_name
=
"hello.tar.gz"
file_content
=
"package content"
package_url
=
f"http://localhost/api/v4/projects/1/packages/generic/
{
package_name
}
/
{
package_version
}
/
{
file_name
}
"
@
pytest
.
fixture
def
resp_list_packages
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
re
.
compile
(
r"http://localhost/api/v4/(groups|projects)/1/packages"
),
json
=
[
package_content
],
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
def
resp_get_package
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
"http://localhost/api/v4/projects/1/packages/1"
,
json
=
package_content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
def
resp_delete_package
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
DELETE
,
url
=
"http://localhost/api/v4/projects/1/packages/1"
,
status
=
204
,
)
yield
rsps
@
pytest
.
fixture
def
resp_delete_package_file
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
DELETE
,
url
=
"http://localhost/api/v4/projects/1/packages/1/package_files/1"
,
status
=
204
,
)
yield
rsps
@
pytest
.
fixture
def
resp_delete_package_file_list
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
re
.
compile
(
r"http://localhost/api/v4/projects/1/packages/1/package_files"
),
json
=
package_file_content
,
content_type
=
"application/json"
,
status
=
200
,
)
for
pkg_file_id
in
range
(
25
,
28
):
rsps
.
add
(
method
=
responses
.
DELETE
,
url
=
f"http://localhost/api/v4/projects/1/packages/1/package_files/
{
pkg_file_id
}
"
,
status
=
204
,
)
yield
rsps
@
pytest
.
fixture
def
resp_list_package_files
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
re
.
compile
(
r"http://localhost/api/v4/projects/1/packages/1/package_files"
),
json
=
package_file_content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
def
resp_list_package_pipelines
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
re
.
compile
(
r"http://localhost/api/v4/projects/1/packages/1/pipelines"
),
json
=
package_pipeline_content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
def
resp_upload_generic_package
(
created_content
):
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
PUT
,
url
=
package_url
,
json
=
created_content
,
content_type
=
"application/json"
,
status
=
201
,
)
yield
rsps
@
pytest
.
fixture
def
resp_download_generic_package
(
created_content
):
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
package_url
,
body
=
file_content
,
content_type
=
"application/octet-stream"
,
status
=
200
,
)
yield
rsps
def
test_list_project_packages
(
project
,
resp_list_packages
):
packages
=
project
.
packages
.
list
()
assert
isinstance
(
packages
,
list
)
assert
isinstance
(
packages
[
0
],
ProjectPackage
)
assert
packages
[
0
].
version
==
"1.0-SNAPSHOT"
def
test_list_group_packages
(
group
,
resp_list_packages
):
packages
=
group
.
packages
.
list
()
assert
isinstance
(
packages
,
list
)
assert
isinstance
(
packages
[
0
],
GroupPackage
)
assert
packages
[
0
].
version
==
"1.0-SNAPSHOT"
def
test_get_project_package
(
project
,
resp_get_package
):
package
=
project
.
packages
.
get
(
1
)
assert
isinstance
(
package
,
ProjectPackage
)
assert
package
.
version
==
"1.0-SNAPSHOT"
def
test_delete_project_package
(
project
,
resp_delete_package
):
package
=
project
.
packages
.
get
(
1
,
lazy
=
True
)
package
.
delete
()
def
test_list_project_package_files
(
project
,
resp_list_package_files
):
package
=
project
.
packages
.
get
(
1
,
lazy
=
True
)
package_files
=
package
.
package_files
.
list
()
assert
isinstance
(
package_files
,
list
)
assert
isinstance
(
package_files
[
0
],
ProjectPackageFile
)
assert
package_files
[
0
].
id
==
25
def
test_delete_project_package_file_from_package_object
(
project
,
resp_delete_package_file
):
package
=
project
.
packages
.
get
(
1
,
lazy
=
True
)
package
.
package_files
.
delete
(
1
)
def
test_delete_project_package_file_from_package_file_object
(
project
,
resp_delete_package_file_list
):
package
=
project
.
packages
.
get
(
1
,
lazy
=
True
)
for
package_file
in
package
.
package_files
.
list
():
package_file
.
delete
()
def
test_list_project_package_pipelines
(
project
,
resp_list_package_pipelines
):
package
=
project
.
packages
.
get
(
1
,
lazy
=
True
)
pipelines
=
package
.
pipelines
.
list
()
assert
isinstance
(
pipelines
,
list
)
assert
isinstance
(
pipelines
[
0
],
ProjectPackagePipeline
)
assert
pipelines
[
0
].
id
==
123
def
test_upload_generic_package
(
tmp_path
,
project
,
resp_upload_generic_package
):
path
=
tmp_path
/
file_name
path
.
write_text
(
file_content
,
encoding
=
"utf-8"
)
package
=
project
.
generic_packages
.
upload
(
package_name
=
package_name
,
package_version
=
package_version
,
file_name
=
file_name
,
path
=
path
,
)
assert
isinstance
(
package
,
GenericPackage
)
def
test_upload_generic_package_nonexistent_path
(
tmp_path
,
project
):
with
pytest
.
raises
(
exc
.
GitlabUploadError
):
project
.
generic_packages
.
upload
(
package_name
=
package_name
,
package_version
=
package_version
,
file_name
=
file_name
,
path
=
"bad"
,
)
def
test_upload_generic_package_no_file_and_no_data
(
tmp_path
,
project
):
path
=
tmp_path
/
file_name
path
.
write_text
(
file_content
,
encoding
=
"utf-8"
)
with
pytest
.
raises
(
exc
.
GitlabUploadError
):
project
.
generic_packages
.
upload
(
package_name
=
package_name
,
package_version
=
package_version
,
file_name
=
file_name
,
)
def
test_upload_generic_package_file_and_data
(
tmp_path
,
project
):
path
=
tmp_path
/
file_name
path
.
write_text
(
file_content
,
encoding
=
"utf-8"
)
with
pytest
.
raises
(
exc
.
GitlabUploadError
):
project
.
generic_packages
.
upload
(
package_name
=
package_name
,
package_version
=
package_version
,
file_name
=
file_name
,
path
=
path
,
data
=
path
.
read_bytes
(),
)
def
test_upload_generic_package_bytes
(
tmp_path
,
project
,
resp_upload_generic_package
):
path
=
tmp_path
/
file_name
path
.
write_text
(
file_content
,
encoding
=
"utf-8"
)
package
=
project
.
generic_packages
.
upload
(
package_name
=
package_name
,
package_version
=
package_version
,
file_name
=
file_name
,
data
=
path
.
read_bytes
(),
)
assert
isinstance
(
package
,
GenericPackage
)
def
test_upload_generic_package_file
(
tmp_path
,
project
,
resp_upload_generic_package
):
path
=
tmp_path
/
file_name
path
.
write_text
(
file_content
,
encoding
=
"utf-8"
)
package
=
project
.
generic_packages
.
upload
(
package_name
=
package_name
,
package_version
=
package_version
,
file_name
=
file_name
,
data
=
path
.
open
(
mode
=
"rb"
),
)
assert
isinstance
(
package
,
GenericPackage
)
def
test_download_generic_package
(
project
,
resp_download_generic_package
):
package
=
project
.
generic_packages
.
download
(
package_name
=
package_name
,
package_version
=
package_version
,
file_name
=
file_name
)
assert
isinstance
(
package
,
bytes
)
Back
|
FazBrowse Home
|
New Git URL