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>
This commit is contained in:
1 parent
30186d8cf2
commit
22bddcf202
55 files changed
+3198
-1
No files matched your search
@@ -0,0 +1,53 @@
|
||||
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")
|
||||
Reference in new issue
Block a user