From 1520994a5ce5ec757e87666b3ae7d50a5dee9baa Mon Sep 17 00:00:00 2001 From: ChristopherSpelt Date: Thu, 21 Nov 2024 14:20:51 +0100 Subject: [PATCH] Bugfix in retrieving requirements corresponding to measures --- amt/api/routes/algorithm.py | 3 +++ tests/api/routes/test_algorithm.py | 8 -------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/amt/api/routes/algorithm.py b/amt/api/routes/algorithm.py index b2d38a1d..b482820c 100644 --- a/amt/api/routes/algorithm.py +++ b/amt/api/routes/algorithm.py @@ -428,6 +428,9 @@ async def find_requirement_tasks_by_measure_urn(system_card: SystemCard, measure measure = await measures_service.fetch_measures(measure_urn) for requirement_urn in measure[0].links: # TODO: This is because measure are linked to too many requirement not applicable in our use case + if requirement_urn not in requirement_mapper: + continue + if len(await requirements_service.fetch_requirements(requirement_urn)) > 0: requirement_tasks.append(requirement_mapper[requirement_urn]) diff --git a/tests/api/routes/test_algorithm.py b/tests/api/routes/test_algorithm.py index 6e84e90b..c83344b4 100644 --- a/tests/api/routes/test_algorithm.py +++ b/tests/api/routes/test_algorithm.py @@ -525,14 +525,6 @@ async def test_find_requirement_tasks_by_measure_urn() -> None: requirement_tasks = await find_requirement_tasks_by_measure_urn(test_algorithm.system_card, "urn:nl:ak:mtr:dat-01") assert len(requirement_tasks) == 2 - # empty requirements - test_algorithm.system_card.requirements = [] - with pytest.raises(KeyError): - # TODO: this is because it is not coded well change later - requirement_tasks = await find_requirement_tasks_by_measure_urn( - test_algorithm.system_card, "urn:nl:ak:mtr:dat-01" - ) - @pytest.mark.asyncio async def test_get_measure(client: AsyncClient, db: DatabaseTestUtils) -> None: