-
Notifications
You must be signed in to change notification settings - Fork 299
fixed rendering of non paginated responses #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,16 @@ class GenericViewSet(TestBase): | |
""" | ||
Test expected responses coming from a Generic ViewSet | ||
""" | ||
|
||
def setUp(self): | ||
super(GenericViewSet, self).setUp() | ||
|
||
setattr(settings, 'JSON_API_FORMAT_KEYS', 'dasherize') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The attributes used in the JSON were dasherized so this is needed. Previously, the tests passed by coincidence due to another test changing the format to 'dasherize'. |
||
|
||
def tearDown(self): | ||
|
||
setattr(settings, 'JSON_API_FORMAT_KEYS', 'camelize') | ||
|
||
def test_default_rest_framework_behavior(self): | ||
""" | ||
This is more of an example really, showing default behavior | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from django.core.urlresolvers import reverse | ||
from django.conf import settings | ||
|
||
import pytest | ||
|
||
from ..views import EntryViewSet | ||
from rest_framework_json_api.pagination import PageNumberPagination | ||
|
||
from example.tests.utils import dump_json, redump_json | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
def test_multiple_entries_no_pagination(rf, multiple_entries): | ||
|
||
expected = { | ||
"data": [ | ||
{ | ||
"type": "posts", | ||
"id": "1", | ||
"attributes": | ||
{ | ||
"headline": "The Absolute Minimum Every Software DeveloperAbsolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)", | ||
"bodyText": "Here goes the body text", | ||
"pubDate": None, | ||
"modDate": None | ||
}, | ||
"relationships": | ||
{ | ||
"blog": { | ||
"data": {"type": "blogs", "id": "1"} | ||
}, | ||
"authors": { | ||
"meta": {"count": 1}, | ||
"data": [{"type": "authors", "id": "1"}] | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "posts", | ||
"id": "2", | ||
"attributes": | ||
{ | ||
"headline": "Pragmatic Unicode", | ||
"bodyText": "Here goes the body text", | ||
"pubDate": None, | ||
"modDate": None | ||
}, | ||
"relationships": | ||
{ | ||
"blog": { | ||
"data": {"type": "blogs", "id": "2"} | ||
}, | ||
"authors": { | ||
"meta": {"count": 1}, | ||
"data": [{"type": "authors", "id": "2"}] | ||
} | ||
} | ||
}, | ||
] | ||
} | ||
|
||
class NoPagination(PageNumberPagination): | ||
page_size = None | ||
|
||
class NonPaginatedEntryViewSet(EntryViewSet): | ||
pagination_class = NoPagination | ||
|
||
request = rf.get( | ||
reverse("entry-list")) | ||
view = NonPaginatedEntryViewSet.as_view({'get': 'list'}) | ||
response = view(request) | ||
response.render() | ||
# print response.content | ||
content_dump = redump_json(response.content) | ||
expected_dump = dump_json(expected) | ||
|
||
assert content_dump == expected_dump |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,19 +6,6 @@ | |
pytestmark = pytest.mark.django_db | ||
|
||
|
||
@pytest.fixture | ||
def single_entry(author_factory, entry_factory): | ||
|
||
author = author_factory(name="Joel Spolsky") | ||
entry = entry_factory( | ||
headline=("The Absolute Minimum Every Software Developer" | ||
"Absolutely, Positively Must Know About Unicode " | ||
"and Character Sets (No Excuses!)"), | ||
blog__name='Joel on Software', | ||
authors=(author, ) | ||
) | ||
|
||
|
||
def test_pagination_with_single_entry(single_entry, client): | ||
|
||
expected = { | ||
|
@@ -29,9 +16,9 @@ def test_pagination_with_single_entry(single_entry, client): | |
"attributes": | ||
{ | ||
"headline": "The Absolute Minimum Every Software DeveloperAbsolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)", | ||
"body-text": "Here goes the body text", | ||
"pub-date": None, | ||
"mod-date": None | ||
"bodyText": "Here goes the body text", | ||
"pubDate": None, | ||
"modDate": None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why removing this test ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixtures and the new fixture I used were moved to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops - my bad 👍 |
||
}, | ||
"relationships": | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,9 @@ class PageNumberPagination(BasePagination): | |
A json-api compatible pagination format | ||
""" | ||
|
||
page_size_query_param = 'page_size' | ||
max_page_size = 100 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this there ?
From There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved those from the settings. Pagination configuration from Drf >= 3.1 should be set in the pagination class. Putting them in the view or settings as per Drf < 3.1 now produces a 'deprecation warning' and I think it will produce an error from Drf 3.3. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HA! good catch ! Thanks for that! |
||
def build_link(self, index): | ||
if not index: | ||
return None | ||
|