From 4688e41da5300d789ed50bdd6af34d7d481767c8 Mon Sep 17 00:00:00 2001 From: Falk Date: Fri, 17 Feb 2023 13:42:51 +0100 Subject: [PATCH] feat(filters): add number multi value filter --- timed/projects/filters.py | 2 ++ timed/projects/tests/test_project.py | 14 ++++++++++++++ timed/projects/tests/test_task.py | 14 ++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/timed/projects/filters.py b/timed/projects/filters.py index 420f6d52..a26c2971 100644 --- a/timed/projects/filters.py +++ b/timed/projects/filters.py @@ -30,6 +30,7 @@ class ProjectFilterSet(FilterSet): archived = NumberFilter(field_name="archived") has_manager = NumberFilter(method="filter_has_manager") has_reviewer = NumberFilter(method="filter_has_reviewer") + customer = NumberInFilter(field_name="customer") def filter_has_manager(self, queryset, name, value): if not value: # pragma: no cover @@ -115,6 +116,7 @@ class TaskFilterSet(FilterSet): my_most_frequent = MyMostFrequentTaskFilter() archived = NumberFilter(field_name="archived") + project = NumberInFilter(field_name="project") class Meta: """Meta information for the task filter set.""" diff --git a/timed/projects/tests/test_project.py b/timed/projects/tests/test_project.py index 8f48d91c..febb48d4 100644 --- a/timed/projects/tests/test_project.py +++ b/timed/projects/tests/test_project.py @@ -154,6 +154,20 @@ def test_project_filter(internal_employee_client): assert len(json["data"]) == 1 +def test_project_multi_number_value_filter(internal_employee_client): + proj1, proj2, *_ = ProjectFactory.create_batch(4) + + url = reverse("project-list") + + response = internal_employee_client.get( + url, {"customer": (",").join([str(proj1.customer.id), str(proj2.customer.id)])} + ) + assert response.status_code == status.HTTP_200_OK + + json = response.json() + assert len(json["data"]) == 2 + + def test_project_update_billed_flag(internal_employee_client, report_factory): report = report_factory.create() project = report.task.project diff --git a/timed/projects/tests/test_task.py b/timed/projects/tests/test_task.py index 6d1b79f0..8fa56049 100644 --- a/timed/projects/tests/test_task.py +++ b/timed/projects/tests/test_task.py @@ -229,3 +229,17 @@ def test_task_list_no_employment(auth_client, is_customer, customer_visible, exp json = response.json() assert len(json["data"]) == expected + + +def test_task_multi_number_value_filter(internal_employee_client): + task1, task2, *_ = TaskFactory.create_batch(4) + + url = reverse("task-list") + + response = internal_employee_client.get( + url, {"project": (",").join([str(task1.project.id), str(task2.project.id)])} + ) + assert response.status_code == status.HTTP_200_OK + + json = response.json() + assert len(json["data"]) == 2