11import pytest
22from django .core .urlresolvers import reverse
33
4- from example .tests .utils import load_json
5-
64pytestmark = pytest .mark .django_db
75
86
@@ -14,9 +12,9 @@ def test_default_included_data_on_list(multiple_entries, client):
1412
1513def test_included_data_on_list (multiple_entries , client , query = '?include=comments&page_size=5' ):
1614 response = client .get (reverse ("entry-list" ) + query )
17- included = load_json ( response .content ).get ('included' )
15+ included = response .json ( ).get ('included' )
1816
19- assert len (load_json ( response .content )['data' ]) == len (multiple_entries ), (
17+ assert len (response .json ( )['data' ]) == len (multiple_entries ), (
2018 'Incorrect entry count'
2119 )
2220 assert [x .get ('type' ) for x in included ] == ['comments' , 'comments' ], (
@@ -34,7 +32,7 @@ def test_default_included_data_on_detail(single_entry, client):
3432
3533def test_included_data_on_detail (single_entry , client , query = '?include=comments' ):
3634 response = client .get (reverse ("entry-detail" , kwargs = {'pk' : single_entry .pk }) + query )
37- included = load_json ( response .content ).get ('included' )
35+ included = response .json ( ).get ('included' )
3836
3937 assert [x .get ('type' ) for x in included ] == ['comments' ], 'Detail included types are incorrect'
4038
@@ -48,7 +46,7 @@ def test_dynamic_related_data_is_included(single_entry, entry_factory, client):
4846 response = client .get (
4947 reverse ("entry-detail" , kwargs = {'pk' : single_entry .pk }) + '?include=featured'
5048 )
51- included = load_json ( response .content ).get ('included' )
49+ included = response .json ( ).get ('included' )
5250
5351 assert [x .get ('type' ) for x in included ] == ['entries' ], 'Dynamic included types are incorrect'
5452 assert len (included ) == 1 , 'The dynamically included blog entries are of an incorrect count'
@@ -59,7 +57,7 @@ def test_dynamic_many_related_data_is_included(single_entry, entry_factory, clie
5957 response = client .get (
6058 reverse ("entry-detail" , kwargs = {'pk' : single_entry .pk }) + '?include=suggested'
6159 )
62- included = load_json ( response .content ).get ('included' )
60+ included = response .json ( ).get ('included' )
6361
6462 assert included
6563 assert [x .get ('type' ) for x in included ] == ['entries' ], 'Dynamic included types are incorrect'
@@ -69,12 +67,11 @@ def test_missing_field_not_included(author_bio_factory, author_factory, client):
6967 # First author does not have a bio
7068 author = author_factory (bio = None )
7169 response = client .get (reverse ('author-detail' , args = [author .pk ]) + '?include=bio' )
72- data = load_json (response .content )
73- assert 'included' not in data
70+ assert 'included' not in response .json ()
7471 # Second author does
7572 author = author_factory ()
7673 response = client .get (reverse ('author-detail' , args = [author .pk ]) + '?include=bio' )
77- data = load_json ( response .content )
74+ data = response .json ( )
7875 assert 'included' in data
7976 assert len (data ['included' ]) == 1
8077 assert data ['included' ][0 ]['attributes' ]['body' ] == author .bio .body
@@ -83,9 +80,9 @@ def test_missing_field_not_included(author_bio_factory, author_factory, client):
8380def test_deep_included_data_on_list (multiple_entries , client ):
8481 response = client .get (reverse ("entry-list" ) + '?include=comments,comments.author,'
8582 'comments.author.bio,comments.writer&page_size=5' )
86- included = load_json ( response .content ).get ('included' )
83+ included = response .json ( ).get ('included' )
8784
88- assert len (load_json ( response .content )['data' ]) == len (multiple_entries ), (
85+ assert len (response .json ( )['data' ]) == len (multiple_entries ), (
8986 'Incorrect entry count'
9087 )
9188 assert [x .get ('type' ) for x in included ] == [
@@ -117,9 +114,9 @@ def test_deep_included_data_on_list(multiple_entries, client):
117114 # Also include entry authors
118115 response = client .get (reverse ("entry-list" ) + '?include=authors,comments,comments.author,'
119116 'comments.author.bio&page_size=5' )
120- included = load_json ( response .content ).get ('included' )
117+ included = response .json ( ).get ('included' )
121118
122- assert len (load_json ( response .content )['data' ]) == len (multiple_entries ), (
119+ assert len (response .json ( )['data' ]) == len (multiple_entries ), (
123120 'Incorrect entry count'
124121 )
125122 assert [x .get ('type' ) for x in included ] == [
@@ -138,7 +135,7 @@ def test_deep_included_data_on_detail(single_entry, client):
138135 # are returned along with the leaf nodes
139136 response = client .get (reverse ("entry-detail" , kwargs = {'pk' : single_entry .pk }) +
140137 '?include=comments,comments.author.bio' )
141- included = load_json ( response .content ).get ('included' )
138+ included = response .json ( ).get ('included' )
142139
143140 assert [x .get ('type' ) for x in included ] == ['authorBios' , 'authors' , 'comments' ], \
144141 'Detail included types are incorrect'
0 commit comments