Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
feat(filters): add number multi value filter
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabauke committed Feb 20, 2023
1 parent 79a8316 commit 4688e41
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions timed/projects/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
14 changes: 14 additions & 0 deletions timed/projects/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions timed/projects/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4688e41

Please sign in to comment.