- Routes /api/v1/auth/login/, logout/ et me/ (session Django + CSRF, message générique en cas d'échec, limitation de débit) ; me/ dépose le cookie CSRF pour le front. La 2FA viendra ensuite. - Qualité de l'air : chaque ligne de détail indique si la valeur guide OMS est dépassée (pastille des maquettes), libellés NO₂ et O₃. - Origine du serveur Vite ajoutée aux origines CSRF de confiance. - 19 tests pour les routes d'authentification (85 au total). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99 lines
3.5 KiB
Python
99 lines
3.5 KiB
Python
import httpx
|
|
import pytest
|
|
|
|
from assessments.providers.air import AirProvider
|
|
from assessments.providers.base import SourceUnavailable
|
|
from assessments.providers.flood import FloodProvider
|
|
from assessments.providers.noise import NoiseProvider
|
|
from assessments.providers.radon import RadonProvider
|
|
|
|
from .conftest import AIRPORT, BXL_LOCATION, FLOOD, RAIL, ROAD, WAL_LOCATION, arcgis
|
|
|
|
|
|
async def fetch(provider, location=WAL_LOCATION):
|
|
async with httpx.AsyncClient() as client:
|
|
return await provider.fetch(client, location)
|
|
|
|
|
|
async def test_noise_takes_loudest_source(mock_http):
|
|
mock_http.get(ROAD).respond(
|
|
json=arcgis(
|
|
{"DB_LOW": 55, "DB_HIGHT": 59, "CLASSE": "de 55 à 59"},
|
|
{"DB_LOW": 65, "DB_HIGHT": 69, "CLASSE": "de 65 à 69"},
|
|
)
|
|
)
|
|
mock_http.get(RAIL).respond(json=arcgis({"DB_LOW": 60, "DB_HIGHT": 64, "CLASSE": "de 60 à 64"}))
|
|
mock_http.get(AIRPORT).respond(json=arcgis())
|
|
|
|
result = await fetch(NoiseProvider())
|
|
|
|
assert result.status == "ok"
|
|
assert result.source_value == "65-69"
|
|
assert result.details[0] == {"label": "Route", "value": "de 65 à 69 dB(A)"}
|
|
assert result.details[2]["value"] == "aucune exposition détectée"
|
|
|
|
|
|
async def test_noise_without_exposure(mock_http):
|
|
for url in (ROAD, RAIL, AIRPORT):
|
|
mock_http.get(url).respond(json=arcgis())
|
|
result = await fetch(NoiseProvider())
|
|
assert (result.status, result.source_value) == ("ok", "aucune")
|
|
|
|
|
|
async def test_noise_arcgis_error_raises(mock_http):
|
|
mock_http.get(ROAD).respond(json={"error": {"code": 400}})
|
|
mock_http.get(RAIL).respond(json=arcgis())
|
|
mock_http.get(AIRPORT).respond(json=arcgis())
|
|
with pytest.raises(SourceUnavailable):
|
|
await fetch(NoiseProvider())
|
|
|
|
|
|
async def test_noise_brussels_not_connected():
|
|
with pytest.raises(SourceUnavailable):
|
|
await fetch(NoiseProvider(), BXL_LOCATION)
|
|
|
|
|
|
async def test_air_counts_who_exceedances(mock_irceline):
|
|
result = await fetch(AirProvider())
|
|
assert result.status == "ok"
|
|
assert result.source_value == "2"
|
|
assert result.summary == "2 dépassements des valeurs guides OMS 2021 (moyennes annuelles)"
|
|
assert result.details[0] == {
|
|
"label": "PM2,5",
|
|
"value": "7,1 µg/m³ (seuil 5)",
|
|
"status": "exceeded",
|
|
}
|
|
assert result.details[1] == {"label": "PM10", "value": "12,0 µg/m³ (seuil 15)", "status": "ok"}
|
|
assert result.details[3] == {"label": "O₃", "value": "50,1 µg/m³"}
|
|
|
|
|
|
async def test_air_wms_exception_raises(mock_http):
|
|
from .conftest import IRCELINE
|
|
|
|
mock_http.get(IRCELINE).respond(200, text="<ServiceExceptionReport/>")
|
|
with pytest.raises(SourceUnavailable):
|
|
await fetch(AirProvider())
|
|
|
|
|
|
async def test_flood_takes_highest_hazard(mock_http):
|
|
mock_http.get(FLOOD).respond(
|
|
json=arcgis(
|
|
{"VALEUR": "Aléa faible", "CODEALEA": 10, "TYPEALEA": "Ruissellement"},
|
|
{"VALEUR": "Aléa élevé", "CODEALEA": 30, "TYPEALEA": "Débordement"},
|
|
)
|
|
)
|
|
result = await fetch(FloodProvider())
|
|
assert result.source_value == "Aléa élevé"
|
|
assert result.details[0] == {"label": "Débordement", "value": "Aléa élevé"}
|
|
|
|
|
|
async def test_flood_outside_hazard_zone(mock_http):
|
|
mock_http.get(FLOOD).respond(json=arcgis())
|
|
result = await fetch(FloodProvider())
|
|
assert (result.status, result.source_value) == ("ok", "aucun")
|
|
|
|
|
|
async def test_radon_not_connected():
|
|
with pytest.raises(SourceUnavailable):
|
|
await fetch(RadonProvider())
|