diff --git a/backend/tests/test_sprint227_statbel_population_preflight.py b/backend/tests/test_sprint227_statbel_population_preflight.py index 37cc5251..6ad625cb 100644 --- a/backend/tests/test_sprint227_statbel_population_preflight.py +++ b/backend/tests/test_sprint227_statbel_population_preflight.py @@ -107,6 +107,7 @@ def geometry_archive( date: str = "2025-01-01", municipality_mismatch: bool = False, repairable_invalid: bool = False, + include_crs_token_in_member: bool = True, ) -> bytes: payload = { "type": "FeatureCollection", @@ -133,10 +134,14 @@ def geometry_archive( } payload["features"][0]["properties"]["ms_area_ha"] = 2.0 buffer = io.BytesIO() + member_stem = ( + "sh_statbel_statistical_sectors_31370_20250101" + if include_crs_token_in_member + else "sh_statbel_statistical_sectors_20250101" + ) with zipfile.ZipFile(buffer, "w", compression=zipfile.ZIP_DEFLATED) as archive: archive.writestr( - "sh_statbel_statistical_sectors_31370_20250101.geojson/" - "sh_statbel_statistical_sectors_31370_20250101.geojson", + f"{member_stem}.geojson/{member_stem}.geojson", json.dumps(payload), ) return buffer.getvalue() @@ -225,6 +230,18 @@ def test_preflight_supports_the_complete_national_scope() -> None: assert accounting["accounted_population_total"] == 243 +def test_preflight_accepts_real_archive_member_without_repeated_crs_token(tmp_path: Path) -> None: + result = validate( + tmp_path, + geometry_content=geometry_archive(include_crs_token_in_member=False), + ) + + assert result.manifest["status"] == "passed" + assert result.manifest["artifacts"]["geometry"]["member"].endswith( + "/sh_statbel_statistical_sectors_20250101.geojson" + ) + + def test_national_preflight_rejects_an_unscoped_baseline(tmp_path: Path) -> None: with pytest.raises(PREFLIGHT.StatbelPreflightError) as exc_info: PREFLIGHT.validate_statbel_release( diff --git a/scripts/statbel_population_preflight.py b/scripts/statbel_population_preflight.py index 0c978ceb..97174bcb 100644 --- a/scripts/statbel_population_preflight.py +++ b/scripts/statbel_population_preflight.py @@ -56,7 +56,7 @@ POPULATION_MEMBER_PATTERN = re.compile( re.IGNORECASE, ) GEOMETRY_MEMBER_PATTERN = re.compile( - r"^sh_statbel_statistical_sectors_31370_(20[0-9]{2})0101\.geojson$", + r"^sh_statbel_statistical_sectors_(?:31370_)?(20[0-9]{2})0101\.geojson$", re.IGNORECASE, ) POPULATION_SOURCE_PATTERN = re.compile(