Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/services/organisation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
33 changes: 27 additions & 6 deletions test/test_organisation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading