5
5
from django .urls import reverse
6
6
from django .utils import timezone
7
7
8
+ from example .models import Author , Blog , Entry
8
9
from rest_framework_json_api .serializers import ResourceIdentifierObjectSerializer , ModelSerializer
9
10
from rest_framework_json_api .utils import format_resource_type
10
11
11
- from example .models import Author , Blog , Entry
12
-
13
12
pytestmark = pytest .mark .django_db
14
13
15
14
@@ -35,17 +34,14 @@ def setUp(self):
35
34
def test_forward_relationship_not_loaded_when_not_included (self ):
36
35
MockRequest = namedtuple ('Request' , ['query_params' ])
37
36
request_without_includes = MockRequest ({})
38
- to_representation_was_called = False
39
37
40
38
class BlogSerializer (ModelSerializer ):
41
39
class Meta :
42
40
model = Blog
43
41
fields = '__all__'
44
42
45
43
def to_representation (self , instance ):
46
- nonlocal to_representation_was_called
47
- to_representation_was_called = True
48
- return super ().to_representation (instance )
44
+ raise Exception ('to_representation of BlogSerializer was called' )
49
45
50
46
class EntrySerializer (ModelSerializer ):
51
47
blog = BlogSerializer ()
@@ -60,7 +56,6 @@ class Meta:
60
56
61
57
serializer = EntrySerializer (context = {'request' : request_without_includes })
62
58
serializer .to_representation (self .entry )
63
- self .assertFalse (to_representation_was_called )
64
59
65
60
def test_data_in_correct_format_when_instantiated_with_blog_object (self ):
66
61
serializer = ResourceIdentifierObjectSerializer (instance = self .blog )
0 commit comments