Fix regional flood area pagination
This commit is contained in:
@@ -42,9 +42,11 @@ class FakeSession:
|
||||
def __init__(self, module):
|
||||
self.module = module
|
||||
self.posts: list[tuple[str, dict[str, Any]]] = []
|
||||
self.gets: list[tuple[str, dict[str, Any]]] = []
|
||||
self.headers: dict[str, str] = {}
|
||||
|
||||
def get(self, url: str, **_kwargs):
|
||||
def get(self, url: str, **kwargs):
|
||||
self.gets.append((url, kwargs.get("params") or {}))
|
||||
if url.endswith("/api/v1/projects"):
|
||||
return FakeResponse({"data": {"items": [{"id": "project-1", "name": "Kempen Regional Workbench"}]}})
|
||||
if url.endswith("/areas"):
|
||||
@@ -67,7 +69,10 @@ class FakeSession:
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"total": 1,
|
||||
"limit": kwargs.get("params", {}).get("limit", 50),
|
||||
"offset": kwargs.get("params", {}).get("offset", 0),
|
||||
}
|
||||
)
|
||||
if url.endswith("/datasets/flood-hazard/products"):
|
||||
@@ -137,6 +142,7 @@ def test_regional_flood_operator_dry_run_uses_canonical_registry(monkeypatch, ca
|
||||
assert '"status": "dry_run"' in output
|
||||
assert '"planned_acquisitions": 1' in output
|
||||
assert fake_session.posts == []
|
||||
assert any(params.get("limit") == 200 for url, params in fake_session.gets if url.endswith("/areas"))
|
||||
|
||||
|
||||
def test_regional_flood_operator_calls_acquisition_and_selection(monkeypatch, capsys) -> None:
|
||||
|
||||
@@ -131,13 +131,23 @@ def resolve_areas(
|
||||
project_id: str,
|
||||
members: Sequence[ScopeMember],
|
||||
) -> list[ResolvedArea]:
|
||||
areas = unwrap(
|
||||
session.get(
|
||||
f"{base_url}/api/v1/projects/{project_id}/areas",
|
||||
params={"limit": 500, "offset": 0},
|
||||
timeout=60,
|
||||
areas: list[dict[str, Any]] = []
|
||||
limit = 200
|
||||
offset = 0
|
||||
while True:
|
||||
page = unwrap(
|
||||
session.get(
|
||||
f"{base_url}/api/v1/projects/{project_id}/areas",
|
||||
params={"limit": limit, "offset": offset},
|
||||
timeout=60,
|
||||
)
|
||||
)
|
||||
)["items"]
|
||||
page_items = list(page["items"])
|
||||
areas.extend(page_items)
|
||||
total = int(page.get("total", len(areas)))
|
||||
if len(areas) >= total or len(page_items) < limit:
|
||||
break
|
||||
offset += limit
|
||||
resolved: list[ResolvedArea] = []
|
||||
missing: list[str] = []
|
||||
for member in members:
|
||||
|
||||
Reference in New Issue
Block a user