88pytestmark = pytest .mark .django_db
99
1010
11- def test_model_resource_name_on_list (single_entry , client ):
12- response = client .get (reverse ("renamed-authors-list" ))
11+ class _PatchedModel :
12+ class JSONAPIMeta :
13+ resource_name = "resource_name_from_JSONAPIMeta"
14+
15+
16+ def test_match_model_resource_name_on_list (single_entry , client ):
17+ models .Comment .__bases__ += (_PatchedModel ,)
18+ response = client .get (reverse ("comment-list" ))
1319 data = load_json (response .content )['data' ]
1420 # name should be super-author instead of model name RenamedAuthor
15- assert [x .get ('type' ) for x in data ] == ['super-author' ], 'List included types are incorrect'
21+ assert [x .get ('type' ) for x in data ] == ['resource_name_from_JSONAPIMeta' ], 'List included types are incorrect'
22+
1623
1724@pytest .mark .usefixtures ("single_entry" )
1825class ResourceNameConsistencyTest (APITestCase ):
19-
26+
2027 def test_type_match_on_included_and_inline_base (self ):
2128 self ._check_relationship_and_included_comment_type_are_the_same (reverse ("entry-list" ))
2229
2330 def test_type_match_on_included_and_inline_with_JSONAPIMeta (self ):
24- models .Comment .__bases__ += (self . _PatchedModel ,)
31+ models .Comment .__bases__ += (_PatchedModel ,)
2532
2633 self ._check_relationship_and_included_comment_type_are_the_same (reverse ("entry-list" ))
2734
@@ -31,7 +38,7 @@ def test_type_match_on_included_and_inline_with_serializer_resource_name(self):
3138 self ._check_relationship_and_included_comment_type_are_the_same (reverse ("entry-list" ))
3239
3340 def test_type_match_on_included_and_inline_with_serializer_resource_name_and_JSONAPIMeta (self ):
34- models .Comment .__bases__ += (self . _PatchedModel ,)
41+ models .Comment .__bases__ += (_PatchedModel ,)
3542 serializers .CommentSerializer .Meta .resource_name = "resource_name_from_serializer"
3643
3744 self ._check_relationship_and_included_comment_type_are_the_same (reverse ("entry-list" ))
@@ -45,12 +52,12 @@ def test_resource_and_relationship_type_match_with_serializer_resource_name(self
4552 self ._check_resource_and_relationship_comment_type_match ()
4653
4754 def test_resource_and_relationship_type_match_with_JSONAPIMeta (self ):
48- models .Comment .__bases__ += (self . _PatchedModel ,)
55+ models .Comment .__bases__ += (_PatchedModel ,)
4956
5057 self ._check_resource_and_relationship_comment_type_match ()
5158
5259 def test_resource_and_relationship_type_match_with_serializer_resource_name_and_JSONAPIMeta (self ):
53- models .Comment .__bases__ += (self . _PatchedModel ,)
60+ models .Comment .__bases__ += (_PatchedModel ,)
5461 serializers .CommentSerializer .Meta .resource_name = "resource_name_from_serializer"
5562
5663 self ._check_resource_and_relationship_comment_type_match ()
@@ -81,9 +88,3 @@ def tearDown(self):
8188 delattr (serializers .CommentSerializer .Meta , "resource_name" )
8289 except AttributeError :
8390 pass
84-
85- class _PatchedModel :
86-
87- class JSONAPIMeta :
88- resource_name = "resource_name_from_JSONAPIMeta"
89-
0 commit comments