From 9303c5e206d25f11df4edbd1c5a1c063efdbad5a Mon Sep 17 00:00:00 2001 From: Colin Maudry Date: Thu, 9 Jul 2026 20:01:57 +0200 Subject: [PATCH] feat(mcp): search_org accepte track=False pour ne pas polluer Matomo Co-Authored-By: Claude Sonnet 5 --- src/utils/search.py | 7 +++++-- tests/mcp/test_queries.py | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/mcp/test_queries.py diff --git a/src/utils/search.py b/src/utils/search.py index df998ad..57252ae 100644 --- a/src/utils/search.py +++ b/src/utils/search.py @@ -5,7 +5,9 @@ from src.utils.table import add_links from src.utils.tracking import track_search -def search_org(dff: pl.DataFrame, query: str, org_type: str) -> pl.DataFrame: +def search_org( + dff: pl.DataFrame, query: str, org_type: str, track: bool = True +) -> pl.DataFrame: """ Search in either 'acheteur' or 'titulaire' DataFrame. @@ -18,7 +20,8 @@ def search_org(dff: pl.DataFrame, query: str, org_type: str) -> pl.DataFrame: return dff.select(pl.lit(False).alias("matches")) # Enregistrement des recherche dans Matomo - track_search(query, "home_page_search") + if track: + track_search(query, "home_page_search") # Normalize query normalized_query = unidecode(query.strip()).upper() diff --git a/tests/mcp/test_queries.py b/tests/mcp/test_queries.py new file mode 100644 index 0000000..b560a73 --- /dev/null +++ b/tests/mcp/test_queries.py @@ -0,0 +1,21 @@ +import src.utils.search as search_mod +from src.utils.data import DF_ACHETEURS +from src.utils.search import search_org + + +def test_search_org_track_false_skips_track_search(monkeypatch): + calls = [] + monkeypatch.setattr(search_mod, "track_search", lambda q, c: calls.append((q, c))) + + search_org(DF_ACHETEURS, "ACHETEUR", "acheteur", track=False) + + assert calls == [] + + +def test_search_org_track_true_calls_track_search(monkeypatch): + calls = [] + monkeypatch.setattr(search_mod, "track_search", lambda q, c: calls.append((q, c))) + + search_org(DF_ACHETEURS, "ACHETEUR", "acheteur", track=True) + + assert calls == [("ACHETEUR", "home_page_search")]