|
18 | 18 | BuildPromotionRequest, |
19 | 19 | BuildPromotionResult, |
20 | 20 | BuildProperties, |
| 21 | + BuildRuns, |
| 22 | + Run, |
21 | 23 | ) |
22 | 24 |
|
23 | 25 | URL = "http://localhost:8080/artifactory" |
24 | 26 | AUTH = ("user", "password_or_apiKey") |
25 | 27 |
|
| 28 | +BUILD_RUNS = BuildRuns( |
| 29 | + uri=f"{URL}/api/build/build_name", |
| 30 | + buildsNumbers=[ |
| 31 | + Run(uri="/number", started="2025-09-05T19:55:09.593+0000"), |
| 32 | + Run(uri="/other", started="2025-09-05T19:55:28.040+0000"), |
| 33 | + ], |
| 34 | +) |
26 | 35 | BUILD_INFO = BuildInfo(uri=f"{URL}/api/build/build_name/number") |
27 | 36 | BUILD_LIST_RESPONSE = BuildListResponse(uri=f"{URL}/api/build") |
28 | 37 | BUILD_NOT_FOUND_ERROR = BuildError(errors=[{"status": 404, "message": "Not found"}]) |
|
44 | 53 | NOT_FOUND_EXCEPTION_BODY = requests.exceptions.HTTPError(response=NOT_FOUND_HTTP_RESPONSE) |
45 | 54 |
|
46 | 55 |
|
| 56 | +@responses.activate |
| 57 | +def test_get_build_numbers_success(mocker): |
| 58 | + responses.add( |
| 59 | + responses.GET, |
| 60 | + f"{URL}/api/build/build_name", |
| 61 | + json=BUILD_RUNS.model_dump(), |
| 62 | + status=200, |
| 63 | + ) |
| 64 | + |
| 65 | + artifactory_build = ArtifactoryBuild(AuthModel(url=URL, auth=AUTH)) |
| 66 | + mocker.spy(artifactory_build, "get_build_runs") |
| 67 | + get_build_runs = artifactory_build.get_build_runs("build_name") |
| 68 | + |
| 69 | + assert isinstance(get_build_runs, BuildRuns) |
| 70 | + assert get_build_runs == BUILD_RUNS |
| 71 | + |
| 72 | + |
| 73 | +@responses.activate |
| 74 | +def test_get_build_numbers_error(mocker): |
| 75 | + responses.add( |
| 76 | + responses.GET, |
| 77 | + f"{URL}/api/build/non_build", |
| 78 | + body=NOT_FOUND_EXCEPTION_BODY, |
| 79 | + status=404, |
| 80 | + ) |
| 81 | + artifactory_build = ArtifactoryBuild(AuthModel(url=URL, auth=AUTH)) |
| 82 | + mocker.spy(artifactory_build, "get_build_runs") |
| 83 | + with pytest.raises(BuildNotFoundError): |
| 84 | + artifactory_build.get_build_runs("non_build") |
| 85 | + |
| 86 | + |
47 | 87 | @responses.activate |
48 | 88 | def test_get_build_info_success(mocker): |
49 | 89 | responses.add( |
|
0 commit comments