From a382370767f7925e32988b4d829d126f0672466a Mon Sep 17 00:00:00 2001 From: Colin Maudry Date: Wed, 22 Apr 2026 23:39:13 +0200 Subject: [PATCH] =?UTF-8?q?feat(observatoire):=20filtres=20d'=C3=A9galit?= =?UTF-8?q?=C3=A9=20simples=20dans=20dashboard=5Ffilters=5Fto=5Fsql=20(#72?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/table_sql.py | 15 +++++++++++ tests/test_dashboard_filters_to_sql.py | 36 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/utils/table_sql.py b/src/utils/table_sql.py index f67cff9..3aa826f 100644 --- a/src/utils/table_sql.py +++ b/src/utils/table_sql.py @@ -134,4 +134,19 @@ def dashboard_filters_to_sql( clauses.append('"dateNotification" > ?') params.append(datetime.now() - timedelta(days=365)) + if dashboard_marche_type: + clauses.append('"type" = ?') + params.append(dashboard_marche_type) + + if dashboard_marche_innovant and dashboard_marche_innovant != "all": + clauses.append('"marcheInnovant" = ?') + params.append(dashboard_marche_innovant) + + if ( + dashboard_marche_sous_traitance_declaree + and dashboard_marche_sous_traitance_declaree != "all" + ): + clauses.append('"sousTraitanceDeclaree" = ?') + params.append(dashboard_marche_sous_traitance_declaree) + return " AND ".join(clauses), params diff --git a/tests/test_dashboard_filters_to_sql.py b/tests/test_dashboard_filters_to_sql.py index a9ca535..5d542eb 100644 --- a/tests/test_dashboard_filters_to_sql.py +++ b/tests/test_dashboard_filters_to_sql.py @@ -16,3 +16,39 @@ def test_year_filter_overrides_default_window(): where_sql, params = dashboard_filters_to_sql(dashboard_year="2025") assert where_sql == 'YEAR("dateNotification") = ?' assert params == [2025] + + +def test_marche_type_equality(): + where_sql, params = dashboard_filters_to_sql( + dashboard_year="2025", + dashboard_marche_type="Marché", + ) + assert where_sql == 'YEAR("dateNotification") = ? AND "type" = ?' + assert params == [2025, "Marché"] + + +def test_innovant_value_all_is_skipped(): + where_sql, params = dashboard_filters_to_sql( + dashboard_year="2025", + dashboard_marche_innovant="all", + ) + assert where_sql == 'YEAR("dateNotification") = ?' + assert params == [2025] + + +def test_innovant_value_oui_adds_clause(): + where_sql, params = dashboard_filters_to_sql( + dashboard_year="2025", + dashboard_marche_innovant="oui", + ) + assert where_sql == 'YEAR("dateNotification") = ? AND "marcheInnovant" = ?' + assert params == [2025, "oui"] + + +def test_sous_traitance_value_non_adds_clause(): + where_sql, params = dashboard_filters_to_sql( + dashboard_year="2025", + dashboard_marche_sous_traitance_declaree="non", + ) + assert where_sql == 'YEAR("dateNotification") = ? AND "sousTraitanceDeclaree" = ?' + assert params == [2025, "non"]