Deploy test / deploy (push) Successful in 1m33s
- R1 : FreeOTP+ en premier dans le texte de la 2FA - R2 : commande seed_thresholds (21 classes de seuil par défaut, valeurs relevées sur les couches WalOnMap réelles, idempotente, --force) pour que `level` et `color` soient renseignés ; elle n'écrase jamais une classe ajustée dans l'admin. Les pastilles restaient grises car aucune classe n'existait en base - R3 : fond de carte tile.openstreetmap.be - tests (back et front), fixtures wallonia/brussels déplacées dans conftest, README, CLAUDE.md et spécifications mis à jour Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
109 lines
3.2 KiB
Python
109 lines
3.2 KiB
Python
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"
|
|
RADON = (
|
|
"https://services2.arcgis.com/u7PyKqO7hEPx3GAs/arcgis/rest/services/"
|
|
"RadonRiskMap1x1km/FeatureServer/0/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 wallonia(mock_irceline):
|
|
"""Adresse wallonne : bruit 65-69 dB, air 2 dépassements, inondation en panne."""
|
|
mock_irceline.get(NOMINATIM).respond(json=nominatim("1348"))
|
|
mock_irceline.get(ROAD).respond(
|
|
json=arcgis({"DB_LOW": 65, "DB_HIGHT": 69, "CLASSE": "de 65 à 69"})
|
|
)
|
|
mock_irceline.get(RAIL).respond(json=arcgis())
|
|
mock_irceline.get(AIRPORT).respond(json=arcgis())
|
|
mock_irceline.get(FLOOD).respond(503)
|
|
mock_irceline.get(RADON).respond(json=arcgis({"gridcode": 3}))
|
|
return mock_irceline
|
|
|
|
|
|
@pytest.fixture
|
|
def brussels(mock_irceline):
|
|
mock_irceline.get(NOMINATIM).respond(json=nominatim("1000", lat="50.846", lon="4.352"))
|
|
mock_irceline.get(RADON).respond(json=arcgis({"gridcode": 1}))
|
|
return mock_irceline
|
|
|
|
|
|
@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()
|