-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filtering to IgnoredManagedGroupMembership list view
- Loading branch information
Showing
4 changed files
with
137 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django_filters import FilterSet | ||
|
||
from anvil_consortium_manager.forms import FilterForm | ||
|
||
from . import models | ||
|
||
|
||
class IgnoredManagedGroupMembershipFilter(FilterSet): | ||
class Meta: | ||
model = models.IgnoredManagedGroupMembership | ||
fields = {"group__name": ["icontains"], "ignored_email": ["icontains"]} | ||
form = FilterForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1669,6 +1669,119 @@ def test_view_with_two_objects(self): | |
self.assertIn("table", response.context_data) | ||
self.assertEqual(len(response.context_data["table"].rows), 2) | ||
|
||
def test_view_with_filter_group_name_return_no_object(self): | ||
factories.IgnoredManagedGroupMembershipFactory.create(group__name="foo") | ||
factories.IgnoredManagedGroupMembershipFactory.create(group__name="bar") | ||
self.client.force_login(self.user) | ||
response = self.client.get(self.get_url(), {"group__name__icontains": "abc"}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn("table", response.context_data) | ||
self.assertEqual(len(response.context_data["table"].rows), 0) | ||
|
||
def test_view_with_filter_group_name_returns_one_object_exact(self): | ||
instance = factories.IgnoredManagedGroupMembershipFactory.create(group__name="foo") | ||
factories.IgnoredManagedGroupMembershipFactory.create(group__name="bar") | ||
self.client.force_login(self.user) | ||
response = self.client.get(self.get_url(), {"group__name__icontains": "foo"}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn("table", response.context_data) | ||
self.assertEqual(len(response.context_data["table"].rows), 1) | ||
self.assertIn(instance, response.context_data["table"].data) | ||
|
||
def test_view_with_filter_group_name_returns_one_object_case_insensitive(self): | ||
instance = factories.IgnoredManagedGroupMembershipFactory.create(group__name="Foo") | ||
factories.IgnoredManagedGroupMembershipFactory.create(group__name="bar") | ||
self.client.force_login(self.user) | ||
response = self.client.get(self.get_url(), {"group__name__icontains": "foo"}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn("table", response.context_data) | ||
self.assertEqual(len(response.context_data["table"].rows), 1) | ||
self.assertIn(instance, response.context_data["table"].data) | ||
|
||
def test_view_with_filter_group_name_returns_one_object_case_contains(self): | ||
instance = factories.IgnoredManagedGroupMembershipFactory.create(group__name="foo") | ||
factories.IgnoredManagedGroupMembershipFactory.create(group__name="bar") | ||
self.client.force_login(self.user) | ||
response = self.client.get(self.get_url(), {"group__name__icontains": "oo"}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn("table", response.context_data) | ||
self.assertEqual(len(response.context_data["table"].rows), 1) | ||
self.assertIn(instance, response.context_data["table"].data) | ||
|
||
def test_view_with_filter_group_name_returns_multiple_objects(self): | ||
instance_1 = factories.IgnoredManagedGroupMembershipFactory.create(group__name="group1") | ||
instance_2 = factories.IgnoredManagedGroupMembershipFactory.create(group__name="group2") | ||
self.client.force_login(self.user) | ||
response = self.client.get(self.get_url(), {"group__name__icontains": "group"}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn("table", response.context_data) | ||
self.assertEqual(len(response.context_data["table"].rows), 2) | ||
self.assertIn(instance_1, response.context_data["table"].data) | ||
self.assertIn(instance_2, response.context_data["table"].data) | ||
|
||
def test_view_with_filter_email_return_no_object(self): | ||
factories.IgnoredManagedGroupMembershipFactory.create(ignored_email="[email protected]") | ||
factories.IgnoredManagedGroupMembershipFactory.create(ignored_email="bar") | ||
self.client.force_login(self.user) | ||
response = self.client.get(self.get_url(), {"ignored_email__icontains": "abc"}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn("table", response.context_data) | ||
self.assertEqual(len(response.context_data["table"].rows), 0) | ||
|
||
def test_view_with_filter_email_returns_one_object_exact(self): | ||
instance = factories.IgnoredManagedGroupMembershipFactory.create(ignored_email="[email protected]") | ||
factories.IgnoredManagedGroupMembershipFactory.create(ignored_email="[email protected]") | ||
self.client.force_login(self.user) | ||
response = self.client.get(self.get_url(), {"ignored_email__icontains": "[email protected]"}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn("table", response.context_data) | ||
self.assertEqual(len(response.context_data["table"].rows), 1) | ||
self.assertIn(instance, response.context_data["table"].data) | ||
|
||
def test_view_with_filter_email_returns_one_object_case_insensitive(self): | ||
instance = factories.IgnoredManagedGroupMembershipFactory.create(ignored_email="[email protected]") | ||
factories.IgnoredManagedGroupMembershipFactory.create(ignored_email="[email protected]") | ||
self.client.force_login(self.user) | ||
response = self.client.get(self.get_url(), {"ignored_email__icontains": "[email protected]"}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn("table", response.context_data) | ||
self.assertEqual(len(response.context_data["table"].rows), 1) | ||
self.assertIn(instance, response.context_data["table"].data) | ||
|
||
def test_view_with_filter_email_returns_one_object_case_contains(self): | ||
instance = factories.IgnoredManagedGroupMembershipFactory.create(ignored_email="[email protected]") | ||
factories.IgnoredManagedGroupMembershipFactory.create(ignored_email="[email protected]") | ||
self.client.force_login(self.user) | ||
response = self.client.get(self.get_url(), {"ignored_email__icontains": "oo"}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn("table", response.context_data) | ||
self.assertEqual(len(response.context_data["table"].rows), 1) | ||
self.assertIn(instance, response.context_data["table"].data) | ||
|
||
def test_view_with_filter_email_returns_multiple_objects(self): | ||
instance_1 = factories.IgnoredManagedGroupMembershipFactory.create(ignored_email="[email protected]") | ||
instance_2 = factories.IgnoredManagedGroupMembershipFactory.create(ignored_email="[email protected]") | ||
self.client.force_login(self.user) | ||
response = self.client.get(self.get_url(), {"ignored_email__icontains": "foo"}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn("table", response.context_data) | ||
self.assertEqual(len(response.context_data["table"].rows), 2) | ||
self.assertIn(instance_1, response.context_data["table"].data) | ||
self.assertIn(instance_2, response.context_data["table"].data) | ||
|
||
def test_view_with_filter_group_name_and_email(self): | ||
factories.IgnoredManagedGroupMembershipFactory.create(group__name="abc", ignored_email="[email protected]") | ||
instance = factories.IgnoredManagedGroupMembershipFactory.create( | ||
group__name="def", ignored_email="[email protected]" | ||
) | ||
factories.IgnoredManagedGroupMembershipFactory.create(group__name="def", ignored_email="[email protected]") | ||
self.client.force_login(self.user) | ||
response = self.client.get(self.get_url(), {"group__name__icontains": "def", "ignored_email__icontains": "foo"}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn("table", response.context_data) | ||
self.assertEqual(len(response.context_data["table"].rows), 1) | ||
self.assertIn(instance, response.context_data["table"].data) | ||
|
||
|
||
class IgnoredManagedGroupMembershipUpdateTest(TestCase): | ||
def setUp(self): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters