7
7
8
8
9
9
def test_default_included_data_on_list (multiple_entries , client ):
10
- return test_included_data_on_list (multiple_entries = multiple_entries , client = client , query = '?page_size=5' )
10
+ return test_included_data_on_list (
11
+ multiple_entries = multiple_entries , client = client , query = '?page_size=5'
12
+ )
11
13
12
14
13
15
def test_included_data_on_list (multiple_entries , client , query = '?include=comments&page_size=5' ):
14
16
response = client .get (reverse ("entry-list" ) + query )
15
17
included = load_json (response .content ).get ('included' )
16
18
17
- assert len (load_json (response .content )['data' ]) == len (multiple_entries ), 'Incorrect entry count'
18
- assert [x .get ('type' ) for x in included ] == ['comments' , 'comments' ], 'List included types are incorrect'
19
+ assert len (load_json (response .content )['data' ]) == len (multiple_entries ), (
20
+ 'Incorrect entry count'
21
+ )
22
+ assert [x .get ('type' ) for x in included ] == ['comments' , 'comments' ], (
23
+ 'List included types are incorrect'
24
+ )
19
25
20
26
comment_count = len ([resource for resource in included if resource ["type" ] == "comments" ])
21
27
expected_comment_count = sum ([entry .comments .count () for entry in multiple_entries ])
@@ -39,7 +45,9 @@ def test_included_data_on_detail(single_entry, client, query='?include=comments'
39
45
40
46
def test_dynamic_related_data_is_included (single_entry , entry_factory , client ):
41
47
entry_factory ()
42
- response = client .get (reverse ("entry-detail" , kwargs = {'pk' : single_entry .pk }) + '?include=featured' )
48
+ response = client .get (
49
+ reverse ("entry-detail" , kwargs = {'pk' : single_entry .pk }) + '?include=featured'
50
+ )
43
51
included = load_json (response .content ).get ('included' )
44
52
45
53
assert [x .get ('type' ) for x in included ] == ['entries' ], 'Dynamic included types are incorrect'
@@ -48,7 +56,9 @@ def test_dynamic_related_data_is_included(single_entry, entry_factory, client):
48
56
49
57
def test_dynamic_many_related_data_is_included (single_entry , entry_factory , client ):
50
58
entry_factory ()
51
- response = client .get (reverse ("entry-detail" , kwargs = {'pk' : single_entry .pk }) + '?include=suggested' )
59
+ response = client .get (
60
+ reverse ("entry-detail" , kwargs = {'pk' : single_entry .pk }) + '?include=suggested'
61
+ )
52
62
included = load_json (response .content ).get ('included' )
53
63
54
64
assert included
@@ -58,12 +68,12 @@ def test_dynamic_many_related_data_is_included(single_entry, entry_factory, clie
58
68
def test_missing_field_not_included (author_bio_factory , author_factory , client ):
59
69
# First author does not have a bio
60
70
author = author_factory (bio = None )
61
- response = client .get (reverse ('author-detail' , args = [author .pk ])+ '?include=bio' )
71
+ response = client .get (reverse ('author-detail' , args = [author .pk ]) + '?include=bio' )
62
72
data = load_json (response .content )
63
73
assert 'included' not in data
64
74
# Second author does
65
75
author = author_factory ()
66
- response = client .get (reverse ('author-detail' , args = [author .pk ])+ '?include=bio' )
76
+ response = client .get (reverse ('author-detail' , args = [author .pk ]) + '?include=bio' )
67
77
data = load_json (response .content )
68
78
assert 'included' in data
69
79
assert len (data ['included' ]) == 1
@@ -75,7 +85,9 @@ def test_deep_included_data_on_list(multiple_entries, client):
75
85
'comments.author.bio&page_size=5' )
76
86
included = load_json (response .content ).get ('included' )
77
87
78
- assert len (load_json (response .content )['data' ]) == len (multiple_entries ), 'Incorrect entry count'
88
+ assert len (load_json (response .content )['data' ]) == len (multiple_entries ), (
89
+ 'Incorrect entry count'
90
+ )
79
91
assert [x .get ('type' ) for x in included ] == [
80
92
'authorBios' , 'authorBios' , 'authors' , 'authors' , 'comments' , 'comments'
81
93
], 'List included types are incorrect'
@@ -99,7 +111,9 @@ def test_deep_included_data_on_list(multiple_entries, client):
99
111
'comments.author.bio&page_size=5' )
100
112
included = load_json (response .content ).get ('included' )
101
113
102
- assert len (load_json (response .content )['data' ]) == len (multiple_entries ), 'Incorrect entry count'
114
+ assert len (load_json (response .content )['data' ]) == len (multiple_entries ), (
115
+ 'Incorrect entry count'
116
+ )
103
117
assert [x .get ('type' ) for x in included ] == [
104
118
'authorBios' , 'authorBios' , 'authors' , 'authors' , 'authors' , 'authors' ,
105
119
'comments' , 'comments' ], 'List included types are incorrect'
0 commit comments