-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from cloudblue/LITE-24280_support_get_rql_filt…
…er_class LITE-24280: Add support for get_rql_filter_class() in views
- Loading branch information
Showing
9 changed files
with
219 additions
and
23 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
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
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
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
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,72 @@ | ||
# | ||
# Copyright © 2022 Ingram Micro Inc. All rights reserved. | ||
# | ||
|
||
import pytest | ||
|
||
from rest_framework.reverse import reverse | ||
from rest_framework.status import HTTP_200_OK | ||
|
||
from tests.dj_rf.models import Author, Book, Publisher | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_detail_default(api_client, clear_cache): | ||
publisher = Publisher.objects.create(name='publisher') | ||
author = Author.objects.create(name='auth', publisher=publisher) | ||
book = Book.objects.create(author=author, status=Book.PLANNING, amazon_rating=5.0) | ||
|
||
response = api_client.get(reverse('dynamicfiltercls-detail', [book.pk])) | ||
|
||
assert response.status_code == HTTP_200_OK | ||
assert 'author' in response.data | ||
assert 'status' in response.data | ||
assert 'amazon_rating' in response.data | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_detail_exclude_fields(api_client, clear_cache): | ||
publisher = Publisher.objects.create(name='publisher') | ||
author = Author.objects.create(name='auth', publisher=publisher) | ||
book = Book.objects.create(author=author, status=Book.PLANNING, amazon_rating=5.0) | ||
|
||
response = api_client.get( | ||
reverse('dynamicfiltercls-detail', [book.pk]) | ||
+ '?select(-author,-status,-amazon_rating)', | ||
) | ||
|
||
assert response.status_code == HTTP_200_OK | ||
assert 'author' not in response.data | ||
assert 'status' not in response.data | ||
assert 'amazon_rating' not in response.data | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_list_default(api_client, clear_cache): | ||
publisher = Publisher.objects.create(name='publisher') | ||
author = Author.objects.create(name='auth', publisher=publisher) | ||
Book.objects.create(author=author, status=Book.PLANNING, amazon_rating=5.0) | ||
|
||
response = api_client.get(reverse('dynamicfiltercls-list')) | ||
|
||
assert response.status_code == HTTP_200_OK | ||
assert 'author' not in response.data[0] | ||
assert 'status' not in response.data[0] | ||
assert 'amazon_rating' not in response.data[0] | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_list_include_fields(api_client, clear_cache): | ||
publisher = Publisher.objects.create(name='publisher') | ||
author = Author.objects.create(name='auth', publisher=publisher) | ||
Book.objects.create(author=author, status=Book.PLANNING, amazon_rating=5.0) | ||
|
||
response = api_client.get( | ||
reverse('dynamicfiltercls-list') | ||
+ '?select(author,status,amazon_rating)', | ||
) | ||
|
||
assert response.status_code == HTTP_200_OK | ||
assert 'author' in response.data[0] | ||
assert 'status' in response.data[0] | ||
assert 'amazon_rating' in response.data[0] |
Oops, something went wrong.