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,83 @@
|
||||
import pytest
|
||||
import respx
|
||||
from django.core.management import call_command
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from accounts.models import User
|
||||
from assessments.geocoding import Location
|
||||
|
||||
WAL_LOCATION = Location(lat=50.668, lon=4.617, postal_code="1348", region="WAL")
|
||||
BXL_LOCATION = Location(lat=50.846, lon=4.352, postal_code="1000", region="BXL")
|
||||
|
||||
NOMINATIM = "https://nominatim.openstreetmap.org/search"
|
||||
IRCELINE = "https://geo.irceline.be/rio/wms"
|
||||
WALONMAP = "https://geoservices.wallonie.be/arcgis/rest/services"
|
||||
ROAD = f"{WALONMAP}/INDUSTRIES_SERVICES/BRUIT_MROAD_2017/MapServer/1/query"
|
||||
RAIL = f"{WALONMAP}/INDUSTRIES_SERVICES/BRUIT_MRAIL_2017/MapServer/1/query"
|
||||
AIRPORT = f"{WALONMAP}/INDUSTRIES_SERVICES/BRUIT_AEROPORTS/MapServer/1/query"
|
||||
FLOOD = f"{WALONMAP}/EAU/ALEA_INOND/MapServer/2/query"
|
||||
|
||||
|
||||
def arcgis(*attributes):
|
||||
return {"features": [{"attributes": a} for a in attributes]}
|
||||
|
||||
|
||||
def irceline(value):
|
||||
features = [] if value is None else [{"properties": {"value": value}}]
|
||||
return {"type": "FeatureCollection", "features": features}
|
||||
|
||||
|
||||
def nominatim(postcode, lat="50.6696831", lon="4.6159504"):
|
||||
return [{"lat": lat, "lon": lon, "address": {"postcode": postcode}}]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_http():
|
||||
with respx.mock(assert_all_called=False) as router:
|
||||
yield router
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_irceline(mock_http):
|
||||
"""irCELine : PM2,5 7,1 (> 5), PM10 12 (ok), NO2 27 (> 10), O3 50,1."""
|
||||
values = {"pm25": 7.1, "pm10": 12.0, "no2": 27.0, "o3": 50.1}
|
||||
|
||||
def respond(request):
|
||||
layer = request.url.params["LAYERS"].split("_")[0]
|
||||
return respx.MockResponse(200, json=irceline(values[layer]))
|
||||
|
||||
mock_http.get(IRCELINE).mock(side_effect=respond)
|
||||
return mock_http
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def seeded(db):
|
||||
call_command("seed_factors", stdout=open("/dev/null", "w")) # noqa: SIM115
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user(db):
|
||||
return User.objects.create_user(
|
||||
"medecin@exemple.be",
|
||||
"un-mot-de-passe-solide",
|
||||
first_name="Jean",
|
||||
last_name="Dupont",
|
||||
status=User.Status.ACTIVE,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def api(user):
|
||||
client = APIClient()
|
||||
client.force_authenticate(user)
|
||||
return client
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clear_cache():
|
||||
"""Le compteur de limitation de débit de DRF est stocké dans le cache."""
|
||||
from django.core.cache import cache
|
||||
|
||||
cache.clear()
|
||||
yield
|
||||
cache.clear()
|
||||
Reference in new issue
Block a user