test(mcp): combler les lacunes de couverture relevées par la revue finale

Ajoute des tests de bout en bout pour les filtres montant/date/cpv, le
chemin titulaire de search_organisations, et la pagination (page>1,
clamping page=0). Normalise montant_total en float dans les deux
branches de compute_org_stats.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Colin Maudry
2026-07-09 21:43:26 +02:00
parent 082d3e24b1
commit 24bc1c08c1
2 changed files with 42 additions and 1 deletions
+41
View File
@@ -39,6 +39,19 @@ def test_search_organisations_finds_known_acheteur():
assert "<" not in first["nom"] # Défense : aucun markup HTML ne s'échappe
def test_search_organisations_finds_known_titulaire():
result = search_organisations("TITULAIRE", "titulaire")
assert any(r["id"] == "345" for r in result)
first = next(r for r in result if r["id"] == "345")
assert set(first.keys()) == {"id", "nom", "departement"}
# Vérifier que le nom a été extrait en texte plain (HTML strippé),
# même chemin SIRET/non-SIRET différent de celui du test acheteur.
assert first["id"] == "345"
assert first["nom"] == "TITULAIRE 1"
assert "<" not in first["id"]
assert "<" not in first["nom"]
def test_search_organisations_invalid_type_raises():
with pytest.raises(ValueError):
search_organisations("x", "autre")
@@ -87,6 +100,34 @@ def test_search_marches_bad_filter_returns_error():
assert "error" in result
def test_search_marches_montant_min_filters_correctly():
assert search_marches(montant_min=100)["meta"]["total"] == 0
assert search_marches(montant_min=1)["meta"]["total"] >= 1
def test_search_marches_date_min_max_filters_correctly():
assert search_marches(date_min="2025-01-01")["meta"]["total"] >= 1
assert search_marches(date_min="2025-01-02")["meta"]["total"] == 0
assert search_marches(date_max="2025-01-01")["meta"]["total"] >= 1
assert search_marches(date_max="2024-12-31")["meta"]["total"] == 0
def test_search_marches_cpv_filters_correctly():
assert search_marches(cpv="716")["meta"]["total"] >= 1
assert search_marches(cpv="999")["meta"]["total"] == 0
def test_search_marches_page_2_is_empty_with_correct_meta():
result = search_marches(acheteur_id="123", page=2)
assert result["meta"]["page"] == 2
assert result["marches"] == []
def test_search_marches_page_zero_is_clamped_to_one():
result = search_marches(acheteur_id="123", page=0)
assert result["meta"]["page"] == 1
def test_compute_org_stats_acheteur_known():
stats = compute_org_stats("acheteur", "123")
assert stats["nb_marches"] >= 1