feat(observatoire): filtres d'égalité simples dans dashboard_filters_to_sql (#72)
This commit is contained in:
@@ -134,4 +134,19 @@ def dashboard_filters_to_sql(
|
|||||||
clauses.append('"dateNotification" > ?')
|
clauses.append('"dateNotification" > ?')
|
||||||
params.append(datetime.now() - timedelta(days=365))
|
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
|
return " AND ".join(clauses), params
|
||||||
|
|||||||
@@ -16,3 +16,39 @@ def test_year_filter_overrides_default_window():
|
|||||||
where_sql, params = dashboard_filters_to_sql(dashboard_year="2025")
|
where_sql, params = dashboard_filters_to_sql(dashboard_year="2025")
|
||||||
assert where_sql == 'YEAR("dateNotification") = ?'
|
assert where_sql == 'YEAR("dateNotification") = ?'
|
||||||
assert params == [2025]
|
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"]
|
||||||
|
|||||||
Reference in New Issue
Block a user