File tree 1 file changed +7
-3
lines changed
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 1
1
from collections import OrderedDict
2
- from unittest .mock import patch
3
2
4
3
import pytest
5
4
from django .test import TestCase
18
17
from example .models import Author , Blog , Entry
19
18
from example .serializers import BlogSerializer
20
19
20
+ try :
21
+ from unittest import mock
22
+ except ImportError :
23
+ import mock
24
+
21
25
factory = APIRequestFactory ()
22
26
pytestmark = pytest .mark .django_db
23
27
@@ -44,7 +48,7 @@ def setUp(self):
44
48
)
45
49
46
50
def test_forward_relationship_not_loaded_when_not_included (self ):
47
- with patch ('example.serializers.BlogSerializer.to_representation' ) as mock :
51
+ with mock . patch ('example.serializers.BlogSerializer.to_representation' ) as mocked_serializer :
48
52
class EntrySerializer (ModelSerializer ):
49
53
blog = BlogSerializer ()
50
54
@@ -56,7 +60,7 @@ class Meta:
56
60
serializer = EntrySerializer (context = {'request' : request_without_includes })
57
61
serializer .to_representation (self .entry )
58
62
59
- mock .assert_not_called ()
63
+ mocked_serializer .assert_not_called ()
60
64
61
65
def test_forward_relationship_optimization_correct_representation (self ):
62
66
class EntrySerializer (ModelSerializer ):
You can’t perform that action at this time.
0 commit comments