|
| 1 | +from django.core.urlresolvers import reverse |
| 2 | +from django.conf import settings |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from ..views import EntryViewSet |
| 7 | +from rest_framework_json_api.pagination import PageNumberPagination |
| 8 | + |
| 9 | +from example.tests.utils import dump_json, redump_json |
| 10 | + |
| 11 | +pytestmark = pytest.mark.django_db |
| 12 | + |
| 13 | + |
| 14 | +def test_multiple_entries_no_pagination(rf, multiple_entries): |
| 15 | + |
| 16 | + expected = { |
| 17 | + "data": [ |
| 18 | + { |
| 19 | + "type": "posts", |
| 20 | + "id": "1", |
| 21 | + "attributes": |
| 22 | + { |
| 23 | + "headline": "The Absolute Minimum Every Software DeveloperAbsolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)", |
| 24 | + "bodyText": "Here goes the body text", |
| 25 | + "pubDate": None, |
| 26 | + "modDate": None |
| 27 | + }, |
| 28 | + "relationships": |
| 29 | + { |
| 30 | + "blog": { |
| 31 | + "data": {"type": "blogs", "id": "1"} |
| 32 | + }, |
| 33 | + "authors": { |
| 34 | + "meta": {"count": 1}, |
| 35 | + "data": [{"type": "authors", "id": "1"}] |
| 36 | + } |
| 37 | + } |
| 38 | + }, |
| 39 | + { |
| 40 | + "type": "posts", |
| 41 | + "id": "2", |
| 42 | + "attributes": |
| 43 | + { |
| 44 | + "headline": "Pragmatic Unicode", |
| 45 | + "bodyText": "Here goes the body text", |
| 46 | + "pubDate": None, |
| 47 | + "modDate": None |
| 48 | + }, |
| 49 | + "relationships": |
| 50 | + { |
| 51 | + "blog": { |
| 52 | + "data": {"type": "blogs", "id": "2"} |
| 53 | + }, |
| 54 | + "authors": { |
| 55 | + "meta": {"count": 1}, |
| 56 | + "data": [{"type": "authors", "id": "2"}] |
| 57 | + } |
| 58 | + } |
| 59 | + }, |
| 60 | + ] |
| 61 | + } |
| 62 | + |
| 63 | + class NoPagination(PageNumberPagination): |
| 64 | + page_size = None |
| 65 | + |
| 66 | + class NonPaginatedEntryViewSet(EntryViewSet): |
| 67 | + pagination_class = NoPagination |
| 68 | + |
| 69 | + request = rf.get( |
| 70 | + reverse("entry-list")) |
| 71 | + view = NonPaginatedEntryViewSet.as_view({'get': 'list'}) |
| 72 | + response = view(request) |
| 73 | + response.render() |
| 74 | + # print response.content |
| 75 | + content_dump = redump_json(response.content) |
| 76 | + expected_dump = dump_json(expected) |
| 77 | + |
| 78 | + assert content_dump == expected_dump |
0 commit comments