From a9d9594a318f6b34350404d3f9cad1c74b1a8985 Mon Sep 17 00:00:00 2001 From: Colin Maudry Date: Thu, 9 Jul 2026 21:43:26 +0200 Subject: [PATCH] =?UTF-8?q?test(mcp):=20combler=20les=20lacunes=20de=20cou?= =?UTF-8?q?verture=20relev=C3=A9es=20par=20la=20revue=20finale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/mcp/queries.py | 2 +- tests/mcp/test_queries.py | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/mcp/queries.py b/src/mcp/queries.py index 2716363..14833d3 100644 --- a/src/mcp/queries.py +++ b/src/mcp/queries.py @@ -175,7 +175,7 @@ def compute_org_stats(org_type: str, org_id: str) -> dict: return { "identite": identite, "nb_marches": 0, - "montant_total": 0, + "montant_total": 0.0, "repartition_annuelle": [], f"top_{other}s": [], "top_cpv": [], diff --git a/tests/mcp/test_queries.py b/tests/mcp/test_queries.py index 83605b6..6dafde9 100644 --- a/tests/mcp/test_queries.py +++ b/tests/mcp/test_queries.py @@ -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