77from rest_framework .test import APITestCase
88from rest_framework .test import force_authenticate
99
10- from rest_framework_json_api .utils import format_relation_name
10+ from rest_framework_json_api .utils import format_resource_type
1111from example .models import Blog , Entry , Comment , Author
1212
1313from .. import views
@@ -49,7 +49,7 @@ def setUp(self):
4949 def test_get_entry_relationship_blog (self ):
5050 url = reverse ('entry-relationships' , kwargs = {'pk' : self .first_entry .id , 'related_field' : 'blog' })
5151 response = self .client .get (url )
52- expected_data = {'type' : format_relation_name ('Blog' ), 'id' : str (self .first_entry .blog .id )}
52+ expected_data = {'type' : format_resource_type ('Blog' ), 'id' : str (self .first_entry .blog .id )}
5353
5454 assert response .data == expected_data
5555
@@ -60,8 +60,8 @@ def test_get_entry_relationship_invalid_field(self):
6060
6161 def test_get_blog_relationship_entry_set (self ):
6262 response = self .client .get ('/blogs/{}/relationships/entry_set' .format (self .blog .id ))
63- expected_data = [{'type' : format_relation_name ('Entry' ), 'id' : str (self .first_entry .id )},
64- {'type' : format_relation_name ('Entry' ), 'id' : str (self .second_entry .id )}]
63+ expected_data = [{'type' : format_resource_type ('Entry' ), 'id' : str (self .first_entry .id )},
64+ {'type' : format_resource_type ('Entry' ), 'id' : str (self .second_entry .id )}]
6565
6666 assert response .data == expected_data
6767
@@ -90,14 +90,14 @@ def test_get_to_many_relationship_self_link(self):
9090 response = self .client .get (url )
9191 expected_data = {
9292 'links' : {'self' : 'http://testserver/authors/1/relationships/comment_set' },
93- 'data' : [{'id' : str (self .second_comment .id ), 'type' : format_relation_name ('Comment' )}]
93+ 'data' : [{'id' : str (self .second_comment .id ), 'type' : format_resource_type ('Comment' )}]
9494 }
9595 assert json .loads (response .content .decode ('utf-8' )) == expected_data
9696
9797 def test_patch_to_one_relationship (self ):
9898 url = '/entries/{}/relationships/blog' .format (self .first_entry .id )
9999 request_data = {
100- 'data' : {'type' : format_relation_name ('Blog' ), 'id' : str (self .other_blog .id )}
100+ 'data' : {'type' : format_resource_type ('Blog' ), 'id' : str (self .other_blog .id )}
101101 }
102102 response = self .client .patch (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
103103 assert response .status_code == 200 , response .content .decode ()
@@ -108,7 +108,7 @@ def test_patch_to_one_relationship(self):
108108 def test_patch_to_many_relationship (self ):
109109 url = '/blogs/{}/relationships/entry_set' .format (self .first_entry .id )
110110 request_data = {
111- 'data' : [{'type' : format_relation_name ('Entry' ), 'id' : str (self .first_entry .id )}, ]
111+ 'data' : [{'type' : format_resource_type ('Entry' ), 'id' : str (self .first_entry .id )}, ]
112112 }
113113 response = self .client .patch (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
114114 assert response .status_code == 200 , response .content .decode ()
@@ -119,23 +119,23 @@ def test_patch_to_many_relationship(self):
119119 def test_post_to_one_relationship_should_fail (self ):
120120 url = '/entries/{}/relationships/blog' .format (self .first_entry .id )
121121 request_data = {
122- 'data' : {'type' : format_relation_name ('Blog' ), 'id' : str (self .other_blog .id )}
122+ 'data' : {'type' : format_resource_type ('Blog' ), 'id' : str (self .other_blog .id )}
123123 }
124124 response = self .client .post (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
125125 assert response .status_code == 405 , response .content .decode ()
126126
127127 def test_post_to_many_relationship_with_no_change (self ):
128128 url = '/entries/{}/relationships/comment_set' .format (self .first_entry .id )
129129 request_data = {
130- 'data' : [{'type' : format_relation_name ('Comment' ), 'id' : str (self .first_comment .id )}, ]
130+ 'data' : [{'type' : format_resource_type ('Comment' ), 'id' : str (self .first_comment .id )}, ]
131131 }
132132 response = self .client .post (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
133133 assert response .status_code == 204 , response .content .decode ()
134134
135135 def test_post_to_many_relationship_with_change (self ):
136136 url = '/entries/{}/relationships/comment_set' .format (self .first_entry .id )
137137 request_data = {
138- 'data' : [{'type' : format_relation_name ('Comment' ), 'id' : str (self .second_comment .id )}, ]
138+ 'data' : [{'type' : format_resource_type ('Comment' ), 'id' : str (self .second_comment .id )}, ]
139139 }
140140 response = self .client .post (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
141141 assert response .status_code == 200 , response .content .decode ()
@@ -145,7 +145,7 @@ def test_post_to_many_relationship_with_change(self):
145145 def test_delete_to_one_relationship_should_fail (self ):
146146 url = '/entries/{}/relationships/blog' .format (self .first_entry .id )
147147 request_data = {
148- 'data' : {'type' : format_relation_name ('Blog' ), 'id' : str (self .other_blog .id )}
148+ 'data' : {'type' : format_resource_type ('Blog' ), 'id' : str (self .other_blog .id )}
149149 }
150150 response = self .client .delete (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
151151 assert response .status_code == 405 , response .content .decode ()
@@ -169,23 +169,23 @@ def test_delete_relationship_overriding_with_none(self):
169169 def test_delete_to_many_relationship_with_no_change (self ):
170170 url = '/entries/{}/relationships/comment_set' .format (self .first_entry .id )
171171 request_data = {
172- 'data' : [{'type' : format_relation_name ('Comment' ), 'id' : str (self .second_comment .id )}, ]
172+ 'data' : [{'type' : format_resource_type ('Comment' ), 'id' : str (self .second_comment .id )}, ]
173173 }
174174 response = self .client .delete (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
175175 assert response .status_code == 204 , response .content .decode ()
176176
177177 def test_delete_one_to_many_relationship_with_not_null_constraint (self ):
178178 url = '/entries/{}/relationships/comment_set' .format (self .first_entry .id )
179179 request_data = {
180- 'data' : [{'type' : format_relation_name ('Comment' ), 'id' : str (self .first_comment .id )}, ]
180+ 'data' : [{'type' : format_resource_type ('Comment' ), 'id' : str (self .first_comment .id )}, ]
181181 }
182182 response = self .client .delete (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
183183 assert response .status_code == 409 , response .content .decode ()
184184
185185 def test_delete_to_many_relationship_with_change (self ):
186186 url = '/authors/{}/relationships/comment_set' .format (self .author .id )
187187 request_data = {
188- 'data' : [{'type' : format_relation_name ('Comment' ), 'id' : str (self .second_comment .id )}, ]
188+ 'data' : [{'type' : format_resource_type ('Comment' ), 'id' : str (self .second_comment .id )}, ]
189189 }
190190 response = self .client .delete (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
191191 assert response .status_code == 200 , response .content .decode ()
0 commit comments