Skip to content

Commit c4a3456

Browse files
committed
test: add test for rest_framework_simplejwt.token_blacklist support
1 parent be34d0b commit c4a3456

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

tests/contrib/test_rest_auth.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from django.urls import include, path
77
from rest_framework import viewsets
88

9-
from tests import assert_schema, generate_schema
9+
from tests import assert_schema, generate_schema, get_request_schema
1010
from tests.models import SimpleModel, SimpleSerializer
1111

1212
transforms = [
@@ -70,3 +70,37 @@ class XViewset(viewsets.ModelViewSet):
7070
'jwtCookieAuth': {'type': 'apiKey', 'in': 'cookie', 'name': 'jwt-session'},
7171
'jwtHeaderAuth': {'type': 'http', 'scheme': 'bearer', 'bearerFormat': 'JWT'}
7272
}
73+
74+
75+
@pytest.mark.contrib('dj_rest_auth', 'rest_framework_simplejwt')
76+
# @mock.patch('dj_rest_auth.app_settings.api_settings.USE_JWT', True)
77+
@mock.patch('rest_framework_simplejwt.settings.api_settings.BLACKLIST_AFTER_ROTATION', True)
78+
def test_rest_auth_token_blacklist(no_warnings, settings):
79+
# flush module import cache to re-evaluate conditional import
80+
import dj_rest_auth.urls
81+
reload(dj_rest_auth.urls)
82+
83+
settings.INSTALLED_APPS += (
84+
'rest_framework_simplejwt',
85+
'rest_framework_simplejwt.token_blacklist',
86+
)
87+
settings.SIMPLE_JWT = {
88+
'BLACKLIST_AFTER_ROTATION': True
89+
}
90+
91+
urlpatterns = [
92+
path('rest-auth/', include('dj_rest_auth.urls')),
93+
]
94+
schema = generate_schema(None, patterns=urlpatterns)
95+
assert get_request_schema(schema['paths']['/rest-auth/logout/']['post'])['$ref'] == '#/components/schemas/Logout'
96+
assert schema['components']['schemas']['Logout'] == {
97+
'type': 'object',
98+
'properties': {
99+
'refresh': {
100+
'type': 'string',
101+
},
102+
},
103+
'required': [
104+
'refresh',
105+
],
106+
}

0 commit comments

Comments
 (0)