forked from django-json-api/django-rest-framework-json-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_pagination.py
87 lines (81 loc) · 3.33 KB
/
test_pagination.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from unittest import mock
import pytest
from django.urls import reverse
pytestmark = pytest.mark.django_db
@mock.patch(
"rest_framework_json_api.utils" ".get_default_included_resources_from_serializer",
new=lambda s: [],
)
def test_pagination_with_single_entry(single_entry, client):
expected = {
"data": [
{
"type": "entries",
"id": "1",
"attributes": {
"headline": single_entry.headline,
"bodyText": single_entry.body_text,
"pubDate": None,
"modDate": None,
},
"meta": {"bodyFormat": "text"},
"relationships": {
"blog": {"data": {"type": "blogs", "id": "1"}},
"blogHyperlinked": {
"links": {
"related": "http://testserver/entries/1/blog",
"self": "http://testserver/entries/1/relationships/blog_hyperlinked", # noqa: B950
}
},
"authors": {
"meta": {"count": 1},
"data": [{"type": "authors", "id": "1"}],
},
"comments": {
"meta": {"count": 1},
"data": [{"type": "comments", "id": "1"}],
},
"commentsHyperlinked": {
"links": {
"related": "http://testserver/entries/1/comments",
"self": "http://testserver/entries/1/relationships/comments_hyperlinked", # noqa: B950
}
},
"suggested": {
"data": [],
"links": {
"related": "http://testserver/entries/1/suggested/",
"self": "http://testserver/entries/1/relationships/suggested",
},
"meta": {"count": 0},
},
"suggestedHyperlinked": {
"links": {
"related": "http://testserver/entries/1/suggested/",
"self": "http://testserver/entries/1"
"/relationships/suggested_hyperlinked",
}
},
"featuredHyperlinked": {
"links": {
"related": "http://testserver/entries/1/featured",
"self": "http://testserver/entries/1/relationships/featured_hyperlinked", # noqa: B950
}
},
"tags": {
"meta": {"count": 1},
"data": [{"id": "1", "type": "taggedItems"}],
},
},
}
],
"links": {
"first": "http://testserver/entries?page%5Bnumber%5D=1",
"last": "http://testserver/entries?page%5Bnumber%5D=1",
"next": None,
"prev": None,
},
"meta": {"pagination": {"page": 1, "pages": 1, "count": 1}},
}
response = client.get(reverse("entry-list"))
assert expected == response.json()