55
66from rest_framework .test import APITestCase
77
8- from rest_framework_json_api .utils import format_relation_name
8+ from rest_framework_json_api .utils import format_resource_type
99from example .models import Blog , Entry , Comment , Author
1010
1111
@@ -44,7 +44,7 @@ def setUp(self):
4444 def test_get_entry_relationship_blog (self ):
4545 url = reverse ('entry-relationships' , kwargs = {'pk' : self .first_entry .id , 'related_field' : 'blog' })
4646 response = self .client .get (url )
47- expected_data = {'type' : format_relation_name ('Blog' ), 'id' : str (self .first_entry .blog .id )}
47+ expected_data = {'type' : format_resource_type ('Blog' ), 'id' : str (self .first_entry .blog .id )}
4848
4949 assert response .data == expected_data
5050
@@ -55,8 +55,8 @@ def test_get_entry_relationship_invalid_field(self):
5555
5656 def test_get_blog_relationship_entry_set (self ):
5757 response = self .client .get ('/blogs/{}/relationships/entry_set' .format (self .blog .id ))
58- expected_data = [{'type' : format_relation_name ('Entry' ), 'id' : str (self .first_entry .id )},
59- {'type' : format_relation_name ('Entry' ), 'id' : str (self .second_entry .id )}]
58+ expected_data = [{'type' : format_resource_type ('Entry' ), 'id' : str (self .first_entry .id )},
59+ {'type' : format_resource_type ('Entry' ), 'id' : str (self .second_entry .id )}]
6060
6161 assert response .data == expected_data
6262
@@ -85,14 +85,14 @@ def test_get_to_many_relationship_self_link(self):
8585 response = self .client .get (url )
8686 expected_data = {
8787 'links' : {'self' : 'http://testserver/authors/1/relationships/comment_set' },
88- 'data' : [{'id' : str (self .second_comment .id ), 'type' : format_relation_name ('Comment' )}]
88+ 'data' : [{'id' : str (self .second_comment .id ), 'type' : format_resource_type ('Comment' )}]
8989 }
9090 assert json .loads (response .content .decode ('utf-8' )) == expected_data
9191
9292 def test_patch_to_one_relationship (self ):
9393 url = '/entries/{}/relationships/blog' .format (self .first_entry .id )
9494 request_data = {
95- 'data' : {'type' : format_relation_name ('Blog' ), 'id' : str (self .other_blog .id )}
95+ 'data' : {'type' : format_resource_type ('Blog' ), 'id' : str (self .other_blog .id )}
9696 }
9797 response = self .client .patch (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
9898 assert response .status_code == 200 , response .content .decode ()
@@ -103,7 +103,7 @@ def test_patch_to_one_relationship(self):
103103 def test_patch_to_many_relationship (self ):
104104 url = '/blogs/{}/relationships/entry_set' .format (self .first_entry .id )
105105 request_data = {
106- 'data' : [{'type' : format_relation_name ('Entry' ), 'id' : str (self .first_entry .id )}, ]
106+ 'data' : [{'type' : format_resource_type ('Entry' ), 'id' : str (self .first_entry .id )}, ]
107107 }
108108 response = self .client .patch (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
109109 assert response .status_code == 200 , response .content .decode ()
@@ -114,23 +114,23 @@ def test_patch_to_many_relationship(self):
114114 def test_post_to_one_relationship_should_fail (self ):
115115 url = '/entries/{}/relationships/blog' .format (self .first_entry .id )
116116 request_data = {
117- 'data' : {'type' : format_relation_name ('Blog' ), 'id' : str (self .other_blog .id )}
117+ 'data' : {'type' : format_resource_type ('Blog' ), 'id' : str (self .other_blog .id )}
118118 }
119119 response = self .client .post (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
120120 assert response .status_code == 405 , response .content .decode ()
121121
122122 def test_post_to_many_relationship_with_no_change (self ):
123123 url = '/entries/{}/relationships/comment_set' .format (self .first_entry .id )
124124 request_data = {
125- 'data' : [{'type' : format_relation_name ('Comment' ), 'id' : str (self .first_comment .id )}, ]
125+ 'data' : [{'type' : format_resource_type ('Comment' ), 'id' : str (self .first_comment .id )}, ]
126126 }
127127 response = self .client .post (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
128128 assert response .status_code == 204 , response .content .decode ()
129129
130130 def test_post_to_many_relationship_with_change (self ):
131131 url = '/entries/{}/relationships/comment_set' .format (self .first_entry .id )
132132 request_data = {
133- 'data' : [{'type' : format_relation_name ('Comment' ), 'id' : str (self .second_comment .id )}, ]
133+ 'data' : [{'type' : format_resource_type ('Comment' ), 'id' : str (self .second_comment .id )}, ]
134134 }
135135 response = self .client .post (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
136136 assert response .status_code == 200 , response .content .decode ()
@@ -140,7 +140,7 @@ def test_post_to_many_relationship_with_change(self):
140140 def test_delete_to_one_relationship_should_fail (self ):
141141 url = '/entries/{}/relationships/blog' .format (self .first_entry .id )
142142 request_data = {
143- 'data' : {'type' : format_relation_name ('Blog' ), 'id' : str (self .other_blog .id )}
143+ 'data' : {'type' : format_resource_type ('Blog' ), 'id' : str (self .other_blog .id )}
144144 }
145145 response = self .client .delete (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
146146 assert response .status_code == 405 , response .content .decode ()
@@ -164,23 +164,23 @@ def test_delete_relationship_overriding_with_none(self):
164164 def test_delete_to_many_relationship_with_no_change (self ):
165165 url = '/entries/{}/relationships/comment_set' .format (self .first_entry .id )
166166 request_data = {
167- 'data' : [{'type' : format_relation_name ('Comment' ), 'id' : str (self .second_comment .id )}, ]
167+ 'data' : [{'type' : format_resource_type ('Comment' ), 'id' : str (self .second_comment .id )}, ]
168168 }
169169 response = self .client .delete (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
170170 assert response .status_code == 204 , response .content .decode ()
171171
172172 def test_delete_one_to_many_relationship_with_not_null_constraint (self ):
173173 url = '/entries/{}/relationships/comment_set' .format (self .first_entry .id )
174174 request_data = {
175- 'data' : [{'type' : format_relation_name ('Comment' ), 'id' : str (self .first_comment .id )}, ]
175+ 'data' : [{'type' : format_resource_type ('Comment' ), 'id' : str (self .first_comment .id )}, ]
176176 }
177177 response = self .client .delete (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
178178 assert response .status_code == 409 , response .content .decode ()
179179
180180 def test_delete_to_many_relationship_with_change (self ):
181181 url = '/authors/{}/relationships/comment_set' .format (self .author .id )
182182 request_data = {
183- 'data' : [{'type' : format_relation_name ('Comment' ), 'id' : str (self .second_comment .id )}, ]
183+ 'data' : [{'type' : format_resource_type ('Comment' ), 'id' : str (self .second_comment .id )}, ]
184184 }
185185 response = self .client .delete (url , data = json .dumps (request_data ), content_type = 'application/vnd.api+json' )
186186 assert response .status_code == 200 , response .content .decode ()
0 commit comments