Files
PRISM/backend/tests/test_geocoding.py
T
boris.waaubandClaude Opus 5.5 22bddcf202 Initialise le back-end Django de la Phase 1
- Modèles : utilisateur (e-mail comme identifiant, statut, n° INAMI),
  traces d'e-mails, facteurs, sources, classes de seuil, contenus
  validés avec historique et références numérotées ; rôles par groupes.
- Modules de facteur appelés en parallèle (httpx) : bruit et inondation
  Wallonie via WalOnMap, qualité de l'air via irCELine ; Bruxelles et
  radon signalés indisponibles en attendant leurs sources.
- Géocodage Nominatim (Best Address à raccorder), région déduite du
  code postal ; aucune adresse stockée ni journalisée.
- API REST : POST /api/v1/assessments/, GET /api/v1/factors/,
  documentation OpenAPI sur /api/docs/.
- Docker Compose (Python 3.12, PostgreSQL 17, Mailpit), uv, ruff,
  pytest (66 tests, HTTP mocké avec respx), CLAUDE.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 10:40:58 +01:00

54 lines
1.7 KiB
Python

import httpx
import pytest
from assessments.geocoding import AddressNotFound, GeocodingError, OutOfCoverage, geocode
from assessments.geocoding.base import region_from_postal_code
from .conftest import NOMINATIM, nominatim
@pytest.mark.parametrize(
("postal_code", "region"),
[
("1000", "BXL"),
("1210", "BXL"),
("1348", "WAL"),
("4000", "WAL"),
("7999", "WAL"),
("2000", None),
("9000", None),
("", None),
],
)
def test_region_from_postal_code(postal_code, region):
assert region_from_postal_code(postal_code) == region
async def test_geocode_wallonia(mock_http):
mock_http.get(NOMINATIM).respond(json=nominatim("1348"))
async with httpx.AsyncClient() as client:
location = await geocode(client, "Place de l'Université 1, 1348 Louvain-la-Neuve")
assert location.region == "WAL"
assert location.lat == pytest.approx(50.6697)
async def test_geocode_not_found(mock_http):
mock_http.get(NOMINATIM).respond(json=[])
async with httpx.AsyncClient() as client:
with pytest.raises(AddressNotFound):
await geocode(client, "rue inexistante")
async def test_geocode_flanders_is_out_of_coverage(mock_http):
mock_http.get(NOMINATIM).respond(json=nominatim("9000"))
async with httpx.AsyncClient() as client:
with pytest.raises(OutOfCoverage):
await geocode(client, "Korenmarkt 1, 9000 Gent")
async def test_geocode_service_down(mock_http):
mock_http.get(NOMINATIM).respond(503)
async with httpx.AsyncClient() as client:
with pytest.raises(GeocodingError):
await geocode(client, "Place de l'Université 1, 1348 Louvain-la-Neuve")