-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add complex filtering + pagination tests
- Loading branch information
Ryan P Kilby
committed
Dec 23, 2017
1 parent
abbc7fa
commit 59f0839
Showing
2 changed files
with
41 additions
and
2 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 |
---|---|---|
|
@@ -111,6 +111,7 @@ def setUpTestData(cls): | |
models.User.objects.create(username="user1", email="[email protected]") | ||
models.User.objects.create(username="user2", email="[email protected]") | ||
models.User.objects.create(username="user3", email="[email protected]") | ||
models.User.objects.create(username="user4", email="[email protected]") | ||
|
||
def test_valid(self): | ||
readable = '(username%3Duser1)|(email__contains%3Dexample.org)' | ||
|
@@ -119,7 +120,7 @@ def test_valid(self): | |
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertListEqual( | ||
[r['username'] for r in response.data], | ||
['user1', 'user3'] | ||
['user1', 'user3', 'user4'] | ||
) | ||
|
||
def test_invalid(self): | ||
|
@@ -130,3 +131,38 @@ def test_invalid(self): | |
self.assertDictEqual(response.data, { | ||
'filters': ["Invalid querystring operator. Matched: 'asdf'."], | ||
}) | ||
|
||
def test_pagination_compatibility(self): | ||
""" | ||
Ensure that complex-filtering does not interfere with additional query param processing. | ||
""" | ||
readable = '(email__contains%3Dexample.org)' | ||
|
||
# sanity check w/o pagination | ||
response = self.client.get('/ffcomplex-users/?filters=' + quote(readable), content_type='json') | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertListEqual( | ||
[r['username'] for r in response.data], | ||
['user3', 'user4'] | ||
) | ||
|
||
# sanity check w/o complex-filtering | ||
response = self.client.get('/ffcomplex-users/?page_size=1', content_type='json') | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertIn('results', response.data) | ||
self.assertListEqual( | ||
[r['username'] for r in response.data['results']], | ||
['user1'] | ||
) | ||
|
||
# pagination + complex-filtering | ||
response = self.client.get('/ffcomplex-users/?page_size=1&filters=' + quote(readable), content_type='json') | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertIn('results', response.data) | ||
self.assertListEqual( | ||
[r['username'] for r in response.data['results']], | ||
['user3'] | ||
) |
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