Page GRB references for operator samples
GeoIntel CI / docs-smoke (push) Has been cancelled
GeoIntel CI / contract-smoke (push) Has been cancelled

This commit is contained in:
Codex
2026-07-09 15:02:12 +02:00
parent 77c45937c6
commit a63d4eaadc
8 changed files with 254 additions and 12 deletions
@@ -123,6 +123,81 @@ def test_background_candidate_can_write_empty_reference_geojson(tmp_path: Path,
assert '"sample_role": "background_candidate"' in payload
def test_fetch_reference_follows_grb_next_links_until_complete(tmp_path: Path, monkeypatch) -> None:
module = load_sample_preparer()
requested: list[tuple[str, dict | None]] = []
def feature(feature_id: str) -> dict:
return {
"type": "Feature",
"id": feature_id,
"geometry": {"type": "Polygon", "coordinates": []},
"properties": {},
}
class FeatureResponse:
def __init__(self, payload: dict) -> None:
self.payload = payload
def raise_for_status(self) -> None:
return None
def json(self) -> dict:
return self.payload
class FakeRequests:
Request = module.requests.Request if module.requests else object
@staticmethod
def get(url, params=None, timeout=120):
requested.append((url, params))
if len(requested) == 1:
return FeatureResponse(
{
"type": "FeatureCollection",
"features": [feature("GBG.1")],
"numberReturned": 1,
"links": [
{
"rel": "next",
"type": "application/geo+json",
"href": "https://example.test/grb?page=2",
}
],
}
)
return FeatureResponse(
{
"type": "FeatureCollection",
"features": [feature("GBG.2")],
"numberReturned": 1,
"links": [],
}
)
monkeypatch.setattr(module, "requests", FakeRequests)
monkeypatch.setattr(module, "prepared_url", lambda url, params: f"{url}?prepared=true")
sample = module.OperatorSample(
slug="urban",
display_name="Urban",
center_lon=5.0,
center_lat=51.0,
)
source_url, feature_count = module.fetch_reference(sample, tmp_path / "urban.geojson", [4.9, 50.9, 5.1, 51.1])
payload = (tmp_path / "urban.geojson").read_text(encoding="utf-8")
assert source_url.endswith("?prepared=true")
assert feature_count == 2
assert requested == [
(module.GRB_GBG_URL, {"f": "application/geo+json", "limit": "1000", "bbox": "4.90000000,50.90000000,5.10000000,51.10000000"}),
("https://example.test/grb?page=2", None),
]
assert '"id": "GBG.1"' in payload
assert '"id": "GBG.2"' in payload
def test_reference_sample_still_rejects_empty_grb_response(tmp_path: Path, monkeypatch) -> None:
module = load_sample_preparer()