8
8
pytestmark = pytest .mark .django_db
9
9
10
10
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" ))
13
19
data = load_json (response .content )['data' ]
14
20
# 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
+
16
23
17
24
@pytest .mark .usefixtures ("single_entry" )
18
25
class ResourceNameConsistencyTest (APITestCase ):
19
-
26
+
20
27
def test_type_match_on_included_and_inline_base (self ):
21
28
self ._check_relationship_and_included_comment_type_are_the_same (reverse ("entry-list" ))
22
29
23
30
def test_type_match_on_included_and_inline_with_JSONAPIMeta (self ):
24
- models .Comment .__bases__ += (self . _PatchedModel ,)
31
+ models .Comment .__bases__ += (_PatchedModel ,)
25
32
26
33
self ._check_relationship_and_included_comment_type_are_the_same (reverse ("entry-list" ))
27
34
@@ -31,7 +38,7 @@ def test_type_match_on_included_and_inline_with_serializer_resource_name(self):
31
38
self ._check_relationship_and_included_comment_type_are_the_same (reverse ("entry-list" ))
32
39
33
40
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 ,)
35
42
serializers .CommentSerializer .Meta .resource_name = "resource_name_from_serializer"
36
43
37
44
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
45
52
self ._check_resource_and_relationship_comment_type_match ()
46
53
47
54
def test_resource_and_relationship_type_match_with_JSONAPIMeta (self ):
48
- models .Comment .__bases__ += (self . _PatchedModel ,)
55
+ models .Comment .__bases__ += (_PatchedModel ,)
49
56
50
57
self ._check_resource_and_relationship_comment_type_match ()
51
58
52
59
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 ,)
54
61
serializers .CommentSerializer .Meta .resource_name = "resource_name_from_serializer"
55
62
56
63
self ._check_resource_and_relationship_comment_type_match ()
@@ -81,9 +88,3 @@ def tearDown(self):
81
88
delattr (serializers .CommentSerializer .Meta , "resource_name" )
82
89
except AttributeError :
83
90
pass
84
-
85
- class _PatchedModel :
86
-
87
- class JSONAPIMeta :
88
- resource_name = "resource_name_from_JSONAPIMeta"
89
-
0 commit comments