@@ -30,9 +30,12 @@ class EntrySerializer(serializers.Serializer):
3030 comment = CommentSerializer (required = False )
3131 headline = serializers .CharField (allow_null = True , required = True )
3232 body_text = serializers .CharField ()
33- author = serializers .ResourceRelatedField (
33+ main_author = serializers .ResourceRelatedField (
3434 queryset = Author .objects .all (), required = False
3535 )
36+ authors = serializers .ResourceRelatedField (
37+ queryset = Author .objects .all (), required = False , many = True
38+ )
3639
3740 def validate (self , attrs ):
3841 body_text = attrs ["body_text" ]
@@ -195,7 +198,31 @@ def test_many_third_level_dict_errors(client, some_blog, snapshot):
195198 assert snapshot == perform_error_test (client , data )
196199
197200
198- def test_relationship_errors_has_correct_pointers (client , some_blog , snapshot ):
201+ def test_relationship_errors_has_correct_pointers_with_camelize (
202+ client , some_blog , snapshot
203+ ):
204+ data = {
205+ "data" : {
206+ "type" : "entries" ,
207+ "attributes" : {
208+ "blog" : some_blog .pk ,
209+ "bodyText" : "body_text" ,
210+ "headline" : "headline" ,
211+ },
212+ "relationships" : {
213+ "mainAuthor" : {"data" : {"id" : "INVALID_ID" , "type" : "authors" }},
214+ "authors" : {"data" : [{"id" : "INVALID_ID" , "type" : "authors" }]},
215+ },
216+ }
217+ }
218+
219+ assert snapshot == perform_error_test (client , data )
220+
221+
222+ @override_settings (JSON_API_FORMAT_FIELD_NAMES = "dasherize" )
223+ def test_relationship_errors_has_correct_pointers_with_dasherize (
224+ client , some_blog , snapshot
225+ ):
199226 data = {
200227 "data" : {
201228 "type" : "entries" ,
@@ -205,7 +232,30 @@ def test_relationship_errors_has_correct_pointers(client, some_blog, snapshot):
205232 "headline" : "headline" ,
206233 },
207234 "relationships" : {
208- "author" : {"data" : {"id" : "INVALID_ID" , "type" : "authors" }}
235+ "main-author" : {"data" : {"id" : "INVALID_ID" , "type" : "authors" }},
236+ "authors" : {"data" : [{"id" : "INVALID_ID" , "type" : "authors" }]},
237+ },
238+ }
239+ }
240+
241+ assert snapshot == perform_error_test (client , data )
242+
243+
244+ @override_settings (JSON_API_FORMAT_FIELD_NAMES = None )
245+ def test_relationship_errors_has_correct_pointers_with_no_formatting (
246+ client , some_blog , snapshot
247+ ):
248+ data = {
249+ "data" : {
250+ "type" : "entries" ,
251+ "attributes" : {
252+ "blog" : some_blog .pk ,
253+ "body_text" : "body_text" ,
254+ "headline" : "headline" ,
255+ },
256+ "relationships" : {
257+ "main_author" : {"data" : {"id" : "INVALID_ID" , "type" : "authors" }},
258+ "authors" : {"data" : [{"id" : "INVALID_ID" , "type" : "authors" }]},
209259 },
210260 }
211261 }
0 commit comments