diff --git a/src/services/organisation_service.py b/src/services/organisation_service.py index 1c5091a..73f4132 100644 --- a/src/services/organisation_service.py +++ b/src/services/organisation_service.py @@ -497,10 +497,7 @@ async def fetch_cabinet_flow(self, president_id: str, dates: Sequence[str], max_ } """ - if len(dates) > max_dates: - raise BadRequestError(f"Too many dates requested, only {max_dates} dates are allowed") - - if len(dates) == 1: + if len(dates) < 2: raise ValueError("At least 2 dates required for the comparison") try: diff --git a/test/test_organisation_service.py b/test/test_organisation_service.py index a6b93f9..81ce7ef 100644 --- a/test/test_organisation_service.py +++ b/test/test_organisation_service.py @@ -785,18 +785,39 @@ async def test_fetch_and_map_relations_with_errors( @pytest.mark.asyncio -async def test_fetch_cabinet_flow_too_many_dates(organisation_service): +@pytest.mark.parametrize("num_dates", [3, 5, 10]) +async def test_fetch_cabinet_flow_multiple_dates(organisation_service, num_dates): president_id = "pres1" - dates = ["2024-09-23", "2024-09-24", "2024-09-25", "2024-09-26"] + dates = [f"2024-09-{20+i}" for i in range(num_dates)] - with pytest.raises(BadRequestError): - await organisation_service.fetch_cabinet_flow(president_id, dates) + mock_returns = [] + for _ in range(num_dates): + mock_returns.append([{"ministerId": "min1", "departmentId": "dep1"}]) + + organisation_service.get_ministers_and_departments = AsyncMock( + side_effect=mock_returns + ) + + mock_entity = MagicMock() + mock_entity.id = "min1" + mock_entity.name = "Minister 1" + organisation_service.opengin_service.get_entities = AsyncMock( + return_value=[mock_entity] + ) + + result = await organisation_service.fetch_cabinet_flow( + president_id=president_id, dates=dates, max_dates=num_dates + ) + + assert len(result["dates"]) == num_dates + assert len(result["nodes"]) == num_dates + assert len(result["links"]) == num_dates - 1 @pytest.mark.asyncio -async def test_fetch_cabinet_flow_single_date_fails(organisation_service): +@pytest.mark.parametrize("dates", [[], ["2024-09-23"]]) +async def test_fetch_cabinet_flow_insufficient_dates(organisation_service, dates): president_id = "pres1" - dates = ["2024-09-23"] with pytest.raises(ValueError): await organisation_service.fetch_cabinet_flow(president_id, dates)