Skip to content

Commit 67677c0

Browse files
committed
remove securitySchemes
also remove DRF 3.9
1 parent ddf2637 commit 67677c0

File tree

6 files changed

+28
-390
lines changed

6 files changed

+28
-390
lines changed

.travis.yml

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,85 +6,63 @@ matrix:
66
allow_failures:
77
- env: TOXENV=py35-django111-drfmaster
88
- env: TOXENV=py36-django111-drfmaster
9-
- env: TOXENV=py35-django21-drfmaster-oauth12
10-
- env: TOXENV=py36-django21-drfmaster-oauth12
11-
- env: TOXENV=py37-django21-drfmaster-oauth12
12-
- env: TOXENV=py35-django22-drfmaster-oauth12
13-
- env: TOXENV=py36-django22-drfmaster-oauth12
14-
- env: TOXENV=py37-django22-drfmaster-oauth12
9+
- env: TOXENV=py35-django21-drfmaster
10+
- env: TOXENV=py36-django21-drfmaster
11+
- env: TOXENV=py37-django21-drfmaster
12+
- env: TOXENV=py35-django22-drfmaster
13+
- env: TOXENV=py36-django22-drfmaster
14+
- env: TOXENV=py37-django22-drfmaster
1515

1616
include:
1717
- python: 3.6
1818
env: TOXENV=flake8
1919

20-
- python: 3.5
21-
env: TOXENV=py35-django111-drf39
2220
- python: 3.5
2321
env: TOXENV=py35-django111-drf310
2422
- python: 3.5
2523
env: TOXENV=py35-django111-drfmaster
2624
- python: 3.5
27-
env: TOXENV=py35-django21-drf39-oauth12
28-
- python: 3.5
29-
env: TOXENV=py35-django21-drf310-oauth12
25+
env: TOXENV=py35-django21-drf310
3026
- python: 3.5
31-
env: TOXENV=py35-django21-drfmaster-oauth12
32-
- python: 3.5
33-
dist: xenial
34-
env: TOXENV=py35-django22-drf39-oauth12
27+
env: TOXENV=py35-django21-drfmaster
3528
- python: 3.5
3629
dist: xenial
37-
env: TOXENV=py35-django22-drf310-oauth12
30+
env: TOXENV=py35-django22-drf310
3831
- python: 3.5
3932
dist: xenial
40-
env: TOXENV=py35-django22-drfmaster-oauth12
33+
env: TOXENV=py35-django22-drfmaster
4134

42-
- python: 3.6
43-
env: TOXENV=py36-django111-drf39
4435
- python: 3.6
4536
env: TOXENV=py36-django111-drf310
4637
- python: 3.6
4738
env: TOXENV=py36-django111-drfmaster
4839
- python: 3.6
49-
env: TOXENV=py36-django21-drf39-oauth12
50-
- python: 3.6
51-
env: TOXENV=py36-django21-drf310-oauth12
52-
- python: 3.6
53-
env: TOXENV=py36-django21-drfmaster-oauth12
40+
env: TOXENV=py36-django21-drf310
5441
- python: 3.6
55-
dist: xenial
56-
env: TOXENV=py36-django22-drf39-oauth12
42+
env: TOXENV=py36-django21-drfmaster
5743
- python: 3.6
5844
dist: xenial
59-
env: TOXENV=py36-django22-drf310-oauth12
45+
env: TOXENV=py36-django22-drf310
6046
- python: 3.6
6147
dist: xenial
62-
env: TOXENV=py36-django22-drfmaster-oauth12
48+
env: TOXENV=py36-django22-drfmaster
6349

6450
- python: 3.7
6551
dist: xenial
6652
sudo: required
67-
env: TOXENV=py37-django21-drf39-oauth12
68-
- python: 3.7
69-
dist: xenial
70-
sudo: required
71-
env: TOXENV=py37-django21-drf310-oauth12
72-
- python: 3.7
73-
dist: xenial
74-
sudo: required
75-
env: TOXENV=py37-django21-drfmaster-oauth12
53+
env: TOXENV=py37-django21-drf310
7654
- python: 3.7
7755
dist: xenial
7856
sudo: required
79-
env: TOXENV=py37-django22-drf39-oauth12
57+
env: TOXENV=py37-django21-drfmaster
8058
- python: 3.7
8159
dist: xenial
8260
sudo: required
83-
env: TOXENV=py37-django22-drf310-oauth12
61+
env: TOXENV=py37-django22-drf310
8462
- python: 3.7
8563
dist: xenial
8664
sudo: required
87-
env: TOXENV=py37-django22-drfmaster-oauth12
65+
env: TOXENV=py37-django22-drfmaster
8866
install:
8967
- pip install tox
9068
script:

example/tests/snapshots/snap_test_openapi.py

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,7 @@
178178
},
179179
"description": "not found"
180180
}
181-
},
182-
"security": [
183-
{
184-
"cookieAuth": []
185-
},
186-
{
187-
"basicAuth": []
188-
}
189-
]
181+
}
190182
}'''
191183

192184
snapshots['test_path_with_id_parameter 1'] = '''{
@@ -348,15 +340,7 @@
348340
},
349341
"description": "not found"
350342
}
351-
},
352-
"security": [
353-
{
354-
"cookieAuth": []
355-
},
356-
{
357-
"basicAuth": []
358-
}
359-
]
343+
}
360344
}'''
361345

362346
snapshots['test_post_request 1'] = '''{
@@ -588,15 +572,7 @@
588572
},
589573
"description": "[Conflict](https://jsonapi.org/format/#crud-creating-responses-409)"
590574
}
591-
},
592-
"security": [
593-
{
594-
"cookieAuth": []
595-
},
596-
{
597-
"basicAuth": []
598-
}
599-
]
575+
}
600576
}'''
601577

602578
snapshots['test_patch_request 1'] = '''{
@@ -822,15 +798,7 @@
822798
},
823799
"description": "[Conflict]([Conflict](https://jsonapi.org/format/#crud-updating-responses-409)"
824800
}
825-
},
826-
"security": [
827-
{
828-
"cookieAuth": []
829-
},
830-
{
831-
"basicAuth": []
832-
}
833-
]
801+
}
834802
}'''
835803

836804
snapshots['test_delete_request 1'] = '''{
@@ -890,13 +858,5 @@
890858
},
891859
"description": "[Resource does not exist](https://jsonapi.org/format/#crud-deleting-responses-404)"
892860
}
893-
},
894-
"security": [
895-
{
896-
"cookieAuth": []
897-
},
898-
{
899-
"basicAuth": []
900-
}
901-
]
861+
}
902862
}'''

example/tests/test_openapi.py

Lines changed: 1 addition & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
11
# largely based on DRF's test_openapi
22
import json
33

4-
import pytest
54
from django.conf.urls import url
65
from django.test import RequestFactory, override_settings
7-
from rest_condition import And, Not, Or
8-
from rest_framework import VERSION as DRFVERSION
9-
from rest_framework.authentication import BasicAuthentication, SessionAuthentication
10-
from rest_framework.permissions import (
11-
AllowAny,
12-
DjangoModelPermissions,
13-
IsAdminUser,
14-
IsAuthenticated
15-
)
166
from rest_framework.request import Request
177

18-
from rest_framework_json_api.optional import OAuth2Authentication, TokenMatchesOASRequirements
8+
from rest_framework_json_api.schemas.openapi import AutoSchema, SchemaGenerator
199
from rest_framework_json_api.views import ModelViewSet
2010

2111
from example import models, serializers, views
2212

23-
drf_version = tuple(int(x) for x in DRFVERSION.split('.'))
24-
25-
if drf_version >= (3, 10):
26-
from rest_framework_json_api.schemas.openapi import AutoSchema, SchemaGenerator
27-
28-
pytestmark = pytest.mark.skipif(drf_version < (3, 10), reason="requires DRF 3.10 or higher")
29-
3013

3114
def create_request(path):
3215
factory = RequestFactory()
@@ -131,127 +114,6 @@ def test_delete_request(snapshot):
131114
snapshot.assert_match(json.dumps(operation, indent=2, sort_keys=True))
132115

133116

134-
@pytest.mark.skipif(TokenMatchesOASRequirements is None, reason="requires oauth")
135-
class OauthProtectedAuthorViewSet(views.AuthorViewSet):
136-
authentication_classes = (OAuth2Authentication, BasicAuthentication,
137-
SessionAuthentication)
138-
permission_classes = (TokenMatchesOASRequirements, IsAuthenticated)
139-
required_alternate_scopes = {
140-
'GET': [['scope1', 'scope2'], ['scope3', 'scope4']],
141-
}
142-
143-
144-
oauth2_server = 'oauth.example.com'
145-
oauth2_config = {
146-
'authorization_endpoint': oauth2_server + '/authorize',
147-
'token_endpoint': oauth2_server + '/token',
148-
'scopes_supported': ['scope1', 'scope2', 'scope3', 'scope4'],
149-
'grant_types_supported': ['implicit', 'authorization_code', 'client_credentials',
150-
'password'],
151-
}
152-
153-
154-
@pytest.mark.skipif(TokenMatchesOASRequirements is None, reason="requires oauth")
155-
def test_schema_security_list():
156-
"""
157-
Checks for security objects
158-
"""
159-
160-
path = '/authors/'
161-
method = 'GET'
162-
163-
view = create_view_with_kw(
164-
OauthProtectedAuthorViewSet,
165-
method,
166-
create_request(path),
167-
{'get': 'list'}
168-
)
169-
inspector = AutoSchema()
170-
inspector.view = view
171-
172-
with override_settings(OAUTH2_CONFIG=oauth2_config):
173-
operation = inspector.get_operation(path, method)
174-
175-
assert 'security' in operation
176-
assert len(operation['security']) == 4
177-
assert operation['security'][0] == {'oauth': ['scope1', 'scope2']}
178-
assert operation['security'][1] == {'oauth': ['scope3', 'scope4']}
179-
assert operation['security'][2] == {'basicAuth': []}
180-
assert operation['security'][3] == {'cookieAuth': []}
181-
182-
183-
@pytest.mark.skipif(TokenMatchesOASRequirements is None, reason="requires oauth")
184-
def test_schema_security_drf_condition():
185-
"""
186-
Checks for security objects with DRF bitwise conditional operators
187-
"""
188-
class DRF_Cond_ViewSet(OauthProtectedAuthorViewSet):
189-
# this is a crazy example just to make sure all the recursive code is covered
190-
permission_classes = [
191-
(IsAuthenticated & DjangoModelPermissions) |
192-
~(TokenMatchesOASRequirements & AllowAny),
193-
~AllowAny | (IsAdminUser & IsAuthenticated),
194-
(TokenMatchesOASRequirements & AllowAny) |
195-
(IsAuthenticated & DjangoModelPermissions),
196-
~TokenMatchesOASRequirements
197-
]
198-
199-
path = '/authors/'
200-
method = 'GET'
201-
202-
view = create_view_with_kw(
203-
DRF_Cond_ViewSet,
204-
method,
205-
create_request(path),
206-
{'get': 'list'}
207-
)
208-
inspector = AutoSchema()
209-
inspector.view = view
210-
211-
with override_settings(OAUTH2_CONFIG=oauth2_config):
212-
operation = inspector.get_operation(path, method)
213-
214-
assert 'security' in operation
215-
assert {'oauth': ['scope1', 'scope2']} in operation['security']
216-
assert {'oauth': ['scope3', 'scope4']} in operation['security']
217-
assert {'basicAuth': []} in operation['security']
218-
assert {'cookieAuth': []} in operation['security']
219-
220-
221-
@pytest.mark.skipif(TokenMatchesOASRequirements is None, reason="requires oauth")
222-
def test_schema_security_rest_condition():
223-
"""
224-
Checks for security objects with rest_condition operator methods
225-
"""
226-
class Rest_Cond_ViewSet(OauthProtectedAuthorViewSet):
227-
permission_classes = [
228-
Or(
229-
And(IsAuthenticated, DjangoModelPermissions),
230-
And(Not(TokenMatchesOASRequirements), AllowAny)),
231-
]
232-
233-
path = '/authors/'
234-
method = 'GET'
235-
236-
view = create_view_with_kw(
237-
Rest_Cond_ViewSet,
238-
method,
239-
create_request(path),
240-
{'get': 'list'}
241-
)
242-
inspector = AutoSchema()
243-
inspector.view = view
244-
245-
with override_settings(OAUTH2_CONFIG=oauth2_config):
246-
operation = inspector.get_operation(path, method)
247-
248-
assert 'security' in operation
249-
assert {'oauth': ['scope1', 'scope2']} in operation['security']
250-
assert {'oauth': ['scope3', 'scope4']} in operation['security']
251-
assert {'basicAuth': []} in operation['security']
252-
assert {'cookieAuth': []} in operation['security']
253-
254-
255117
@override_settings(REST_FRAMEWORK={
256118
'DEFAULT_SCHEMA_CLASS': 'rest_framework_json_api.schemas.openapi.AutoSchema'})
257119
def test_schema_construction():

rest_framework_json_api/optional.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)