Skip to content

Commit 7ee1bc7

Browse files
committed
Added skip test code execution when coreapi is not installed
1 parent fde309d commit 7ee1bc7

File tree

1 file changed

+76
-28
lines changed

1 file changed

+76
-28
lines changed

tests/schemas/test_coreapi.py

+76-28
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,15 @@ def test_anonymous_request(self):
173173
url='/example/',
174174
action='get',
175175
fields=[
176-
coreapi.Field('page', required=False, location='query', schema=coreschema.Integer(title='Page', description='A page number within the paginated result set.')),
177-
coreapi.Field('page_size', required=False, location='query', schema=coreschema.Integer(title='Page size', description='Number of results to return per page.')),
178-
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.'))
176+
coreapi.Field('page', required=False, location='query',
177+
schema=coreschema.Integer(title='Page',
178+
description='A page number within the paginated result set.')),
179+
coreapi.Field('page_size', required=False, location='query',
180+
schema=coreschema.Integer(title='Page size',
181+
description='Number of results to return per page.')),
182+
coreapi.Field('ordering', required=False, location='query',
183+
schema=coreschema.String(title='Ordering',
184+
description='Which field to use when ordering the results.'))
179185
]
180186
),
181187
'custom_list_action': coreapi.Link(
@@ -201,7 +207,9 @@ def test_anonymous_request(self):
201207
action='get',
202208
fields=[
203209
coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
204-
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.'))
210+
coreapi.Field('ordering', required=False, location='query',
211+
schema=coreschema.String(title='Ordering',
212+
description='Which field to use when ordering the results.'))
205213
]
206214
)
207215
}
@@ -223,17 +231,24 @@ def test_authenticated_request(self):
223231
url='/example/',
224232
action='get',
225233
fields=[
226-
coreapi.Field('page', required=False, location='query', schema=coreschema.Integer(title='Page', description='A page number within the paginated result set.')),
227-
coreapi.Field('page_size', required=False, location='query', schema=coreschema.Integer(title='Page size', description='Number of results to return per page.')),
228-
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.'))
234+
coreapi.Field('page', required=False, location='query',
235+
schema=coreschema.Integer(title='Page',
236+
description='A page number within the paginated result set.')),
237+
coreapi.Field('page_size', required=False, location='query',
238+
schema=coreschema.Integer(title='Page size',
239+
description='Number of results to return per page.')),
240+
coreapi.Field('ordering', required=False, location='query',
241+
schema=coreschema.String(title='Ordering',
242+
description='Which field to use when ordering the results.'))
229243
]
230244
),
231245
'create': coreapi.Link(
232246
url='/example/',
233247
action='post',
234248
encoding='application/json',
235249
fields=[
236-
coreapi.Field('a', required=True, location='form', schema=coreschema.String(title='A', description='A field description')),
250+
coreapi.Field('a', required=True, location='form',
251+
schema=coreschema.String(title='A', description='A field description')),
237252
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B'))
238253
]
239254
),
@@ -242,7 +257,9 @@ def test_authenticated_request(self):
242257
action='get',
243258
fields=[
244259
coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
245-
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.'))
260+
coreapi.Field('ordering', required=False, location='query',
261+
schema=coreschema.String(title='Ordering',
262+
description='Which field to use when ordering the results.'))
246263
]
247264
),
248265
'custom_action': coreapi.Link(
@@ -273,8 +290,10 @@ def test_authenticated_request(self):
273290
description='A custom action using both list field and list serializer in the serializer.',
274291
fields=[
275292
coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
276-
coreapi.Field('a', required=True, location='form', schema=coreschema.Array(title='A', items=coreschema.Integer())),
277-
coreapi.Field('b', required=True, location='form', schema=coreschema.Array(title='B', items=coreschema.String())),
293+
coreapi.Field('a', required=True, location='form',
294+
schema=coreschema.Array(title='A', items=coreschema.Integer())),
295+
coreapi.Field('b', required=True, location='form',
296+
schema=coreschema.Array(title='B', items=coreschema.String())),
278297
]
279298
),
280299
'custom_list_action': coreapi.Link(
@@ -310,7 +329,8 @@ def test_authenticated_request(self):
310329
description='A description of the post method on the custom action.',
311330
encoding='application/json',
312331
fields=[
313-
coreapi.Field('a', required=True, location='form', schema=coreschema.String(title='A', description='A field description')),
332+
coreapi.Field('a', required=True, location='form',
333+
schema=coreschema.String(title='A', description='A field description')),
314334
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B'))
315335
]
316336
),
@@ -320,7 +340,8 @@ def test_authenticated_request(self):
320340
description='A description of the put method on the custom action from mapping.',
321341
encoding='application/json',
322342
fields=[
323-
coreapi.Field('a', required=True, location='form', schema=coreschema.String(title='A', description='A field description')),
343+
coreapi.Field('a', required=True, location='form',
344+
schema=coreschema.String(title='A', description='A field description')),
324345
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B'))
325346
]
326347
),
@@ -331,9 +352,12 @@ def test_authenticated_request(self):
331352
encoding='application/json',
332353
fields=[
333354
coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
334-
coreapi.Field('a', required=True, location='form', schema=coreschema.String(title='A', description=('A field description'))),
355+
coreapi.Field('a', required=True, location='form',
356+
schema=coreschema.String(title='A', description=('A field description'))),
335357
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B')),
336-
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.'))
358+
coreapi.Field('ordering', required=False, location='query',
359+
schema=coreschema.String(title='Ordering',
360+
description='Which field to use when ordering the results.'))
337361
]
338362
),
339363
'partial_update': coreapi.Link(
@@ -342,17 +366,22 @@ def test_authenticated_request(self):
342366
encoding='application/json',
343367
fields=[
344368
coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
345-
coreapi.Field('a', required=False, location='form', schema=coreschema.String(title='A', description='A field description')),
369+
coreapi.Field('a', required=False, location='form',
370+
schema=coreschema.String(title='A', description='A field description')),
346371
coreapi.Field('b', required=False, location='form', schema=coreschema.String(title='B')),
347-
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.'))
372+
coreapi.Field('ordering', required=False, location='query',
373+
schema=coreschema.String(title='Ordering',
374+
description='Which field to use when ordering the results.'))
348375
]
349376
),
350377
'delete': coreapi.Link(
351378
url='/example/{id}/',
352379
action='delete',
353380
fields=[
354381
coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
355-
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.'))
382+
coreapi.Field('ordering', required=False, location='query',
383+
schema=coreschema.String(title='Ordering',
384+
description='Which field to use when ordering the results.'))
356385
]
357386
)
358387
}
@@ -597,9 +626,15 @@ def test_schema_for_regular_views(self):
597626
url='/example1/',
598627
action='get',
599628
fields=[
600-
coreapi.Field('page', required=False, location='query', schema=coreschema.Integer(title='Page', description='A page number within the paginated result set.')),
601-
coreapi.Field('page_size', required=False, location='query', schema=coreschema.Integer(title='Page size', description='Number of results to return per page.')),
602-
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.'))
629+
coreapi.Field('page', required=False, location='query',
630+
schema=coreschema.Integer(title='Page',
631+
description='A page number within the paginated result set.')),
632+
coreapi.Field('page_size', required=False, location='query',
633+
schema=coreschema.Integer(title='Page size',
634+
description='Number of results to return per page.')),
635+
coreapi.Field('ordering', required=False, location='query',
636+
schema=coreschema.String(title='Ordering',
637+
description='Which field to use when ordering the results.'))
603638
]
604639
),
605640
'custom_list_action': coreapi.Link(
@@ -625,7 +660,9 @@ def test_schema_for_regular_views(self):
625660
action='get',
626661
fields=[
627662
coreapi.Field('id', required=True, location='path', schema=coreschema.String()),
628-
coreapi.Field('ordering', required=False, location='query', schema=coreschema.String(title='Ordering', description='Which field to use when ordering the results.'))
663+
coreapi.Field('ordering', required=False, location='query',
664+
schema=coreschema.String(title='Ordering',
665+
description='Which field to use when ordering the results.'))
629666
]
630667
)
631668
}
@@ -706,8 +743,10 @@ def test_schema_for_regular_views(self):
706743
action='post',
707744
encoding='application/json',
708745
fields=[
709-
coreapi.Field('name', required=True, location='form', schema=coreschema.String(title='Name')),
710-
coreapi.Field('target', required=True, location='form', schema=coreschema.Integer(description='Target', title='Target')),
746+
coreapi.Field('name', required=True, location='form',
747+
schema=coreschema.String(title='Name')),
748+
coreapi.Field('target', required=True, location='form',
749+
schema=coreschema.Integer(description='Target', title='Target')),
711750
]
712751
)
713752
}
@@ -752,8 +791,10 @@ def test_schema_for_regular_views(self):
752791
action='post',
753792
encoding='application/json',
754793
fields=[
755-
coreapi.Field('name', required=True, location='form', schema=coreschema.String(title='Name')),
756-
coreapi.Field('targets', required=True, location='form', schema=coreschema.Array(title='Targets', items=coreschema.Integer())),
794+
coreapi.Field('name', required=True, location='form',
795+
schema=coreschema.String(title='Name')),
796+
coreapi.Field('targets', required=True, location='form',
797+
schema=coreschema.Array(title='Targets', items=coreschema.Integer())),
757798
]
758799
)
759800
}
@@ -769,6 +810,7 @@ def test_action_not_coerced_for_get_and_head(self):
769810
"""
770811
Ensure that action name is preserved when action map contains "head".
771812
"""
813+
772814
class CustomViewSet(GenericViewSet):
773815
serializer_class = EmptySerializer
774816

@@ -856,7 +898,8 @@ class CustomView(APIView):
856898
assert isinstance(view.schema, CustomViewInspector)
857899

858900
def test_set_custom_inspector_class_via_settings(self):
859-
with override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'tests.schemas.test_coreapi.CustomViewInspector'}):
901+
with override_settings(
902+
REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'tests.schemas.test_coreapi.CustomViewInspector'}):
860903
view = APIView()
861904
assert isinstance(view.schema, CustomViewInspector)
862905

@@ -963,7 +1006,6 @@ def extra_action(self, pk, **kwargs):
9631006

9641007
@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
9651008
def test_view_with_manual_schema(self):
966-
9671009
path = '/example'
9681010
method = 'get'
9691011
base_url = None
@@ -1198,6 +1240,7 @@ class TestURLNamingCollisions(TestCase):
11981240
"""
11991241
Ref: https://github.com/encode/django-rest-framework/issues/4704
12001242
"""
1243+
12011244
def test_manually_routing_nested_routes(self):
12021245
@api_view(["GET"])
12031246
def simple_fbv(request):
@@ -1444,6 +1487,11 @@ def test_schema_handles_exception():
14441487

14451488

14461489
class CoreapiDeprecationTestCase(TestCase):
1490+
def __init__(self, *args, **kwargs):
1491+
if not coreapi:
1492+
pytest.skip("coreapi is not installed")
1493+
super().__init__(*args, **kwargs)
1494+
14471495
def assert_deprecation_warning(self, obj):
14481496
with pytest.warns(RemovedInDRF317Warning) as warning_list:
14491497
obj.get_schema_fields({})

0 commit comments

Comments
 (0)