From 5f5056027a96ada0bd758164101d420fb843ce6d Mon Sep 17 00:00:00 2001 From: Omar Selo Date: Wed, 9 Oct 2024 13:47:05 +0000 Subject: [PATCH] Get environment reviews endpoint returns latest builds reviews only --- .../controllers/artefacts/artefacts.py | 6 ++++- .../controllers/artefacts/test_artefacts.py | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/backend/test_observer/controllers/artefacts/artefacts.py b/backend/test_observer/controllers/artefacts/artefacts.py index be1a2f5d..e343be53 100644 --- a/backend/test_observer/controllers/artefacts/artefacts.py +++ b/backend/test_observer/controllers/artefacts/artefacts.py @@ -190,7 +190,11 @@ def get_environment_reviews( ) ), ): - return [review for build in artefact.builds for review in build.environment_reviews] + return [ + review + for build in artefact.latest_builds + for review in build.environment_reviews + ] @router.patch( diff --git a/backend/tests/controllers/artefacts/test_artefacts.py b/backend/tests/controllers/artefacts/test_artefacts.py index 74895dd1..94cb7648 100644 --- a/backend/tests/controllers/artefacts/test_artefacts.py +++ b/backend/tests/controllers/artefacts/test_artefacts.py @@ -473,6 +473,30 @@ def test_get_with_two_environment_reviews( ] +def test_get_only_consideres_latest_builds( + test_client: TestClient, generator: DataGenerator +): + a = generator.gen_artefact("beta") + ab1 = generator.gen_artefact_build(a, revision=1) + ab2 = generator.gen_artefact_build(a, revision=2) + e1 = generator.gen_environment("env1") + e2 = generator.gen_environment("env2") + generator.gen_artefact_build_environment_review(ab1.id, e1.id) + review2 = generator.gen_artefact_build_environment_review(ab2.id, e2.id) + + response = test_client.get(f"/v1/artefacts/{a.id}/environment-reviews") + assert response.status_code == 200 + assert response.json() == [ + { + "id": review2.id, + "review_decision": review2.review_decision, + "review_comment": review2.review_comment, + "environment_id": review2.environment_id, + "artefact_build_id": review2.artefact_build_id, + }, + ] + + def test_review_an_environment(test_client: TestClient, generator: DataGenerator): a = generator.gen_artefact("beta") ab = generator.gen_artefact_build(a)