Skip to content

Commit

Permalink
Merge pull request #397 from projectcaluma/user-is-active-filter
Browse files Browse the repository at this point in the history
feat: add "is_active" filter for user model
  • Loading branch information
David Vogt authored Jul 4, 2022
2 parents f2afc75 + 8efbdc0 commit 84fa0af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions emeis/core/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Meta:
"first_name": ["exact", "icontains", "contains"],
"last_name": ["exact", "icontains", "contains"],
"email": ["exact", "in"],
"is_active": ["exact"],
}


Expand Down
16 changes: 16 additions & 0 deletions emeis/core/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ def test_user_has_role(admin_client, acl_factory, filter_name, expect_result):
assert resp.status_code == status.HTTP_400_BAD_REQUEST


@pytest.mark.parametrize(
"filter_value, expect_count",
[("true", 4), ("false", 2)],
)
def test_user_is_active_filter(admin_client, user_factory, filter_value, expect_count):
user_factory.create_batch(3, is_active=True)
user_factory.create_batch(2, is_active=False)

resp = admin_client.get(
reverse("user-list"),
{"filter[is_active]": filter_value},
)

assert len(resp.json()["data"]) == expect_count


@pytest.mark.parametrize(
"filter_field, model_attr, expect_result",
[
Expand Down

0 comments on commit 84fa0af

Please sign in to comment.