From 8efbdc0a6cb3d5d0b74fa92aa9e5801f9ab270e5 Mon Sep 17 00:00:00 2001 From: Christian Zosel Date: Mon, 4 Jul 2022 13:34:00 +0200 Subject: [PATCH] feat: add "is_active" filter for user model --- emeis/core/filters.py | 1 + emeis/core/tests/test_filters.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/emeis/core/filters.py b/emeis/core/filters.py index fb58bf2..56443f7 100644 --- a/emeis/core/filters.py +++ b/emeis/core/filters.py @@ -60,6 +60,7 @@ class Meta: "first_name": ["exact", "icontains", "contains"], "last_name": ["exact", "icontains", "contains"], "email": ["exact", "in"], + "is_active": ["exact"], } diff --git a/emeis/core/tests/test_filters.py b/emeis/core/tests/test_filters.py index 66c90a3..73dfd15 100644 --- a/emeis/core/tests/test_filters.py +++ b/emeis/core/tests/test_filters.py @@ -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", [