@@ -133,3 +133,43 @@ def test_oauth2_toolkit_scopes_backend(no_warnings):
133
133
assert 'implicit' in oauth2 ['flows' ]
134
134
flow = oauth2 ['flows' ]['implicit' ]
135
135
assert 'test_backend_scope' in flow ['scopes' ]
136
+
137
+
138
+ @mock .patch (
139
+ 'drf_spectacular.settings.spectacular_settings.OAUTH2_SCOPES' ,
140
+ {"read" : "Read scope" , "burn" : "Burn scope" },
141
+ )
142
+ @mock .patch (
143
+ 'drf_spectacular.settings.spectacular_settings.OAUTH2_FLOWS' ,
144
+ ['implicit' ]
145
+ )
146
+ @mock .patch (
147
+ 'drf_spectacular.settings.spectacular_settings.OAUTH2_REFRESH_URL' ,
148
+ 'http://127.0.0.1:8000/o/refresh'
149
+ )
150
+ @mock .patch (
151
+ 'drf_spectacular.settings.spectacular_settings.OAUTH2_AUTHORIZATION_URL' ,
152
+ 'http://127.0.0.1:8000/o/authorize'
153
+ )
154
+ @mock .patch (
155
+ 'oauth2_provider.settings.oauth2_settings.SCOPES' ,
156
+ {"read" : "Reading scope" , "write" : "Writing scope" , "extra_scope" : "Extra Scope" },
157
+ )
158
+ @mock .patch (
159
+ 'oauth2_provider.settings.oauth2_settings.DEFAULT_SCOPES' ,
160
+ ["read" , "write" ]
161
+ )
162
+ @pytest .mark .contrib ('oauth2_provider' )
163
+ def test_oauth2_toolkit_custom_scopes (no_warnings ):
164
+ router = routers .SimpleRouter ()
165
+ router .register ('TokenHasReadWriteScope' , TokenHasReadWriteScopeViewset , basename = "x1" )
166
+
167
+ urlpatterns = [
168
+ * router .urls ,
169
+ path ('o/' , include ('oauth2_provider.urls' , namespace = 'oauth2_provider' )),
170
+ ]
171
+ schema = generate_schema (None , patterns = urlpatterns )
172
+
173
+ assert schema ['components' ]['securitySchemes' ]['oauth2' ]['flows' ]['implicit' ]['scopes' ] == {
174
+ 'burn' : 'Burn scope' , 'read' : 'Read scope'
175
+ }
0 commit comments