|
1 | | -# from django.core.urlresolvers import reverse |
2 | | -# from django.conf import settings |
3 | | -# |
4 | | -# import pytest |
5 | | -# |
6 | | -# from example.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 | | -# # rf == request_factory |
15 | | -# def test_multiple_entries_no_pagination(multiple_entries, rf): |
16 | | -# |
17 | | -# expected = { |
18 | | -# "data": [ |
19 | | -# { |
20 | | -# "type": "posts", |
21 | | -# "id": "1", |
22 | | -# "attributes": |
23 | | -# { |
24 | | -# "headline": multiple_entries[0].headline, |
25 | | -# "bodyText": multiple_entries[0].body_text, |
26 | | -# "pubDate": None, |
27 | | -# "modDate": None |
28 | | -# }, |
29 | | -# "meta": { |
30 | | -# "bodyFormat": "text" |
31 | | -# }, |
32 | | -# "relationships": |
33 | | -# { |
34 | | -# "blog": { |
35 | | -# "data": {"type": "blogs", "id": "1"} |
36 | | -# }, |
37 | | -# "authors": { |
38 | | -# "meta": {"count": 1}, |
39 | | -# "data": [{"type": "authors", "id": "1"}] |
40 | | -# }, |
41 | | -# "comments": { |
42 | | -# "meta": {"count": 1}, |
43 | | -# "data": [{"type": "comments", "id": "1"}] |
44 | | -# }, |
45 | | -# "suggested": { |
46 | | -# "data": [{"type": "entries", "id": "2"}] |
47 | | -# } |
48 | | -# } |
49 | | -# }, |
50 | | -# { |
51 | | -# "type": "posts", |
52 | | -# "id": "2", |
53 | | -# "attributes": |
54 | | -# { |
55 | | -# "headline": multiple_entries[1].headline, |
56 | | -# "bodyText": multiple_entries[1].body_text, |
57 | | -# "pubDate": None, |
58 | | -# "modDate": None |
59 | | -# }, |
60 | | -# "meta": { |
61 | | -# "bodyFormat": "text" |
62 | | -# }, |
63 | | -# "relationships": |
64 | | -# { |
65 | | -# "blog": { |
66 | | -# "data": {"type": "blogs", "id": "2"} |
67 | | -# }, |
68 | | -# "authors": { |
69 | | -# "meta": {"count": 1}, |
70 | | -# "data": [{"type": "authors", "id": "2"}] |
71 | | -# }, |
72 | | -# "comments": { |
73 | | -# "meta": {"count": 1}, |
74 | | -# "data": [{"type": "comments", "id": "2"}] |
75 | | -# }, |
76 | | -# "suggested": { |
77 | | -# "data": [{"type": "entries", "id": "1"}] |
78 | | -# } |
79 | | -# } |
80 | | -# }, |
81 | | -# ] |
82 | | -# } |
83 | | -# |
84 | | -# class NoPagination(PageNumberPagination): |
85 | | -# page_size = None |
86 | | -# |
87 | | -# class NonPaginatedEntryViewSet(EntryViewSet): |
88 | | -# pagination_class = NoPagination |
89 | | -# |
90 | | -# request = rf.get( |
91 | | -# reverse("entry-list")) |
92 | | -# view = NonPaginatedEntryViewSet.as_view({'get': 'list'}) |
93 | | -# response = view(request) |
94 | | -# response.render() |
95 | | -# |
96 | | -# content_dump = redump_json(response.content) |
97 | | -# expected_dump = dump_json(expected) |
98 | | -# |
99 | | -# assert content_dump == expected_dump |
| 1 | +from django.core.urlresolvers import reverse |
| 2 | +from django.conf import settings |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from example.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 | +# rf == request_factory |
| 15 | +def test_multiple_entries_no_pagination(multiple_entries, rf): |
| 16 | + |
| 17 | + expected = { |
| 18 | + "data": [ |
| 19 | + { |
| 20 | + "type": "posts", |
| 21 | + "id": "1", |
| 22 | + "attributes": |
| 23 | + { |
| 24 | + "headline": multiple_entries[0].headline, |
| 25 | + "bodyText": multiple_entries[0].body_text, |
| 26 | + "pubDate": None, |
| 27 | + "modDate": None |
| 28 | + }, |
| 29 | + "meta": { |
| 30 | + "bodyFormat": "text" |
| 31 | + }, |
| 32 | + "relationships": |
| 33 | + { |
| 34 | + "blog": { |
| 35 | + "data": {"type": "blogs", "id": "1"} |
| 36 | + }, |
| 37 | + "authors": { |
| 38 | + "meta": {"count": 1}, |
| 39 | + "data": [{"type": "authors", "id": "1"}] |
| 40 | + }, |
| 41 | + "comments": { |
| 42 | + "meta": {"count": 1}, |
| 43 | + "data": [{"type": "comments", "id": "1"}] |
| 44 | + }, |
| 45 | + "suggested": { |
| 46 | + "data": [{"type": "entries", "id": "2"}] |
| 47 | + } |
| 48 | + } |
| 49 | + }, |
| 50 | + { |
| 51 | + "type": "posts", |
| 52 | + "id": "2", |
| 53 | + "attributes": |
| 54 | + { |
| 55 | + "headline": multiple_entries[1].headline, |
| 56 | + "bodyText": multiple_entries[1].body_text, |
| 57 | + "pubDate": None, |
| 58 | + "modDate": None |
| 59 | + }, |
| 60 | + "meta": { |
| 61 | + "bodyFormat": "text" |
| 62 | + }, |
| 63 | + "relationships": |
| 64 | + { |
| 65 | + "blog": { |
| 66 | + "data": {"type": "blogs", "id": "2"} |
| 67 | + }, |
| 68 | + "authors": { |
| 69 | + "meta": {"count": 1}, |
| 70 | + "data": [{"type": "authors", "id": "2"}] |
| 71 | + }, |
| 72 | + "comments": { |
| 73 | + "meta": {"count": 1}, |
| 74 | + "data": [{"type": "comments", "id": "2"}] |
| 75 | + }, |
| 76 | + "suggested": { |
| 77 | + "data": [{"type": "entries", "id": "1"}] |
| 78 | + } |
| 79 | + } |
| 80 | + }, |
| 81 | + ] |
| 82 | + } |
| 83 | + |
| 84 | + class NoPagination(PageNumberPagination): |
| 85 | + page_size = None |
| 86 | + |
| 87 | + class NonPaginatedEntryViewSet(EntryViewSet): |
| 88 | + pagination_class = NoPagination |
| 89 | + |
| 90 | + request = rf.get( |
| 91 | + reverse("entry-list")) |
| 92 | + view = NonPaginatedEntryViewSet.as_view({'get': 'list'}) |
| 93 | + response = view(request) |
| 94 | + response.render() |
| 95 | + |
| 96 | + content_dump = redump_json(response.content) |
| 97 | + expected_dump = dump_json(expected) |
| 98 | + |
| 99 | + assert content_dump == expected_dump |
0 commit comments