4
4
from collections import OrderedDict
5
5
from enum import Enum
6
6
from json import dumps
7
+ import functools
7
8
8
9
# from drf_spectacular.renderers import OpenApiJsonRenderer
9
10
from unittest .mock import ANY , MagicMock , call , patch
150
151
IMPORTER_MOCK_RETURN_VALUE = None , 0 , 0 , 0 , 0 , 0 , MagicMock ()
151
152
REIMPORTER_MOCK_RETURN_VALUE = None , 0 , 0 , 0 , 0 , 0 , MagicMock ()
152
153
153
-
154
+ @ functools . cache
154
155
def get_open_api3_json_schema ():
155
156
generator_class = spectacular_settings .DEFAULT_GENERATOR_CLASS
156
157
generator = generator_class ()
@@ -163,11 +164,6 @@ def get_open_api3_json_schema():
163
164
return schema
164
165
165
166
166
- # use ugly global to avoid generating the schema for every test/method (as it's slow)
167
- global open_api3_json_schema
168
- open_api3_json_schema = get_open_api3_json_schema ()
169
-
170
-
171
167
def skipIfNotSubclass (baseclass ):
172
168
def decorate (f ):
173
169
def wrapper (self , * args , ** kwargs ):
@@ -363,7 +359,7 @@ def setUp(self):
363
359
self .client = APIClient ()
364
360
self .client .credentials (HTTP_AUTHORIZATION = "Token " + token .key )
365
361
self .url = reverse (self .viewname + "-list" )
366
- self .schema = open_api3_json_schema
362
+ self .schema = get_open_api3_json_schema ()
367
363
368
364
def setUp_not_authorized (self ):
369
365
testuser = User .objects .get (id = 3 )
@@ -465,7 +461,7 @@ def test_detail_configuration_not_authorized(self):
465
461
class ListRequestTest (RESTEndpointTest ):
466
462
@skipIfNotSubclass (ListModelMixin )
467
463
def test_list (self ):
468
- # print(open_api3_json_schema )
464
+ # print(get_open_api3_json_schema() )
469
465
# validator = ResponseValidator(spec)
470
466
471
467
check_for_tags = False
0 commit comments