|
6 | 6 | import pytest |
7 | 7 | import responses |
8 | 8 |
|
| 9 | +from gitlab import exceptions as exc |
9 | 10 | from gitlab.v4.objects import ( |
10 | 11 | GenericPackage, |
11 | 12 | GroupPackage, |
@@ -281,6 +282,74 @@ def test_upload_generic_package(tmp_path, project, resp_upload_generic_package): |
281 | 282 | assert isinstance(package, GenericPackage) |
282 | 283 |
|
283 | 284 |
|
| 285 | +def test_upload_generic_package_nonexistent_path(tmp_path, project): |
| 286 | + with pytest.raises(exc.GitlabUploadError): |
| 287 | + project.generic_packages.upload( |
| 288 | + package_name=package_name, |
| 289 | + package_version=package_version, |
| 290 | + file_name=file_name, |
| 291 | + path="bad", |
| 292 | + ) |
| 293 | + |
| 294 | + |
| 295 | +def test_upload_generic_package_no_file_and_no_data(tmp_path, project): |
| 296 | + path = tmp_path / file_name |
| 297 | + |
| 298 | + path.write_text(file_content, encoding="utf-8") |
| 299 | + |
| 300 | + with pytest.raises(exc.GitlabUploadError): |
| 301 | + project.generic_packages.upload( |
| 302 | + package_name=package_name, |
| 303 | + package_version=package_version, |
| 304 | + file_name=file_name, |
| 305 | + ) |
| 306 | + |
| 307 | + |
| 308 | +def test_upload_generic_package_file_and_data(tmp_path, project): |
| 309 | + path = tmp_path / file_name |
| 310 | + |
| 311 | + path.write_text(file_content, encoding="utf-8") |
| 312 | + |
| 313 | + with pytest.raises(exc.GitlabUploadError): |
| 314 | + project.generic_packages.upload( |
| 315 | + package_name=package_name, |
| 316 | + package_version=package_version, |
| 317 | + file_name=file_name, |
| 318 | + path=path, |
| 319 | + data=path.read_bytes(), |
| 320 | + ) |
| 321 | + |
| 322 | + |
| 323 | +def test_upload_generic_package_bytes(tmp_path, project, resp_upload_generic_package): |
| 324 | + path = tmp_path / file_name |
| 325 | + |
| 326 | + path.write_text(file_content, encoding="utf-8") |
| 327 | + |
| 328 | + package = project.generic_packages.upload( |
| 329 | + package_name=package_name, |
| 330 | + package_version=package_version, |
| 331 | + file_name=file_name, |
| 332 | + data=path.read_bytes(), |
| 333 | + ) |
| 334 | + |
| 335 | + assert isinstance(package, GenericPackage) |
| 336 | + |
| 337 | + |
| 338 | +def test_upload_generic_package_file(tmp_path, project, resp_upload_generic_package): |
| 339 | + path = tmp_path / file_name |
| 340 | + |
| 341 | + path.write_text(file_content, encoding="utf-8") |
| 342 | + |
| 343 | + package = project.generic_packages.upload( |
| 344 | + package_name=package_name, |
| 345 | + package_version=package_version, |
| 346 | + file_name=file_name, |
| 347 | + data=path.open(mode="rb"), |
| 348 | + ) |
| 349 | + |
| 350 | + assert isinstance(package, GenericPackage) |
| 351 | + |
| 352 | + |
284 | 353 | def test_download_generic_package(project, resp_download_generic_package): |
285 | 354 | package = project.generic_packages.download( |
286 | 355 | package_name=package_name, |
|
0 commit comments