Skip to content

Commit a093565

Browse files
committed
fix flake8 failing tests
1 parent ff67402 commit a093565

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

‎oauth2_provider/oauth2_backends.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
fromurllib.parseimporturlparse, urlunparse
33

44
fromoauthlibimportoauth2
5-
fromoauthlib.commonimportquote, urlencode, urlencoded, RequestasOauthlibRequest
5+
fromoauthlib.commonimportRequestasOauthlibRequest
6+
fromoauthlib.commonimportquote, urlencode, urlencoded
7+
68
from .exceptionsimportFatalClientError, OAuthToolkitError
79
from .settingsimportoauth2_settings
810

@@ -14,6 +16,7 @@ class OAuthLibCore(object):
1416
Meant for things like extracting request data and converting
1517
everything to formats more palatable for oauthlib's Server.
1618
"""
19+
1720
def__init__(self, server=None):
1821
"""
1922
:params server: An instance of oauthlib.oauth2.Server class
@@ -127,9 +130,11 @@ def create_authorization_response(self, request, scopes, credentials, allow):
127130
returnuri, headers, body, status
128131

129132
exceptoauth2.FatalClientErroraserror:
130-
raiseFatalClientError(error=error, redirect_uri=credentials["redirect_uri"])
133+
raiseFatalClientError(
134+
error=error, redirect_uri=credentials["redirect_uri"])
131135
exceptoauth2.OAuth2Erroraserror:
132-
raiseOAuthToolkitError(error=error, redirect_uri=credentials["redirect_uri"])
136+
raiseOAuthToolkitError(
137+
error=error, redirect_uri=credentials["redirect_uri"])
133138

134139
defcreate_token_response(self, request):
135140
"""
@@ -170,12 +175,13 @@ def verify_request(self, request, scopes):
170175
"""
171176
uri, http_method, body, headers=self._extract_params(request)
172177

173-
valid, r=self.server.verify_request(uri, http_method, body, headers, scopes=scopes)
178+
valid, r=self.server.verify_request(
179+
uri, http_method, body, headers, scopes=scopes)
174180
returnvalid, r
175181

176182
defauthenticate_client(self, request):
177183
"""Wrapper to call `authenticate_client` on `server_class` instance.
178-
184+
179185
:param request: The current django.http.HttpRequest object
180186
"""
181187
uri, http_method, body, headers=self._extract_params(request)
@@ -187,6 +193,7 @@ class JSONOAuthLibCore(OAuthLibCore):
187193
"""
188194
Extends the default OAuthLibCore to parse correctly application/json requests
189195
"""
196+
190197
defextract_body(self, request):
191198
"""
192199
Extracts the JSON body from the Django request object

‎oauth2_provider/views/generic.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
from ..settingsimportoauth2_settings
44
from .mixinsimport (
5-
OAuthLibMixin,
6-
ProtectedResourceMixin, ReadWriteScopedResourceMixin, ScopedResourceMixin,
7-
ClientProtectedResourceMixin
5+
ClientProtectedResourceMixin, OAuthLibMixin, ProtectedResourceMixin,
6+
ReadWriteScopedResourceMixin, ScopedResourceMixin
87
)
98

9+
1010
classInitializationMixin(OAuthLibMixin):
1111

1212
"""Initializer for OauthLibMixin
@@ -16,6 +16,7 @@ class InitializationMixin(OAuthLibMixin):
1616
validator_class=oauth2_settings.OAUTH2_VALIDATOR_CLASS
1717
oauthlib_backend_class=oauth2_settings.OAUTH2_BACKEND_CLASS
1818

19+
1920
classProtectedResourceView(ProtectedResourceMixin, InitializationMixin, View):
2021
"""
2122
Generic view protecting resources by providing OAuth2 authentication out of the box
@@ -38,6 +39,7 @@ class ReadWriteScopedResourceView(ReadWriteScopedResourceMixin, ProtectedResourc
3839
"""
3940
pass
4041

42+
4143
classClientProtectedResourceView(ClientProtectedResourceMixin, InitializationMixin, View):
4244

4345
"""View for protecting a resource with client-credentials method.
@@ -46,6 +48,7 @@ class ClientProtectedResourceView(ClientProtectedResourceMixin, InitializationMi
4648

4749
pass
4850

51+
4952
classClientProtectedScopedResourceView(ScopedResourceMixin, ClientProtectedResourceView):
5053

5154
"""Impose scope restrictions if client protection fallsback to access token.

‎oauth2_provider/views/mixins.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def error_response(self, error, **kwargs):
177177
defauthenticate_client(self, request):
178178
"""Returns a boolean representing if client is authenticated with client credentials
179179
method. Returns `True` if authenticated.
180-
180+
181181
:param request: The current django.http.HttpRequest object
182182
"""
183183
core=self.get_oauthlib_core()
@@ -209,6 +209,7 @@ class ProtectedResourceMixin(OAuthLibMixin):
209209
Helper mixin that implements OAuth2 protection on request dispatch,
210210
specially useful for Django Generic Views
211211
"""
212+
212213
defdispatch(self, request, *args, **kwargs):
213214
# let preflight OPTIONS requests pass
214215
ifrequest.method.upper() =="OPTIONS":
@@ -232,12 +233,14 @@ class ReadWriteScopedResourceMixin(ScopedResourceMixin, OAuthLibMixin):
232233

233234
def__new__(cls, *args, **kwargs):
234235
provided_scopes=get_scopes_backend().get_all_scopes()
235-
read_write_scopes= [oauth2_settings.READ_SCOPE, oauth2_settings.WRITE_SCOPE]
236+
read_write_scopes= [oauth2_settings.READ_SCOPE,
237+
oauth2_settings.WRITE_SCOPE]
236238

237239
ifnotset(read_write_scopes).issubset(set(provided_scopes)):
238240
raiseImproperlyConfigured(
239241
"ReadWriteScopedResourceMixin requires following scopes{}"
240-
' to be in OAUTH2_PROVIDER["SCOPES"] list in settings'.format(read_write_scopes)
242+
' to be in OAUTH2_PROVIDER["SCOPES"] list in settings'.format(
243+
read_write_scopes)
241244
)
242245

243246
returnsuper().__new__(cls, *args, **kwargs)
@@ -256,11 +259,12 @@ def get_scopes(self, *args, **kwargs):
256259
# this returns a copy so that self.required_scopes is not modified
257260
returnscopes+ [self.read_write_scope]
258261

262+
259263
classClientProtectedResourceMixin(OAuthLibMixin):
260264

261265
"""Mixin for protecting resources with client authentication as mentioned in rfc:`3.2.1`
262-
This involves authenticating with any of: HTTP Basic Auth, Client Credentials and Access token in that order.
263-
Breaks off after first validation.
266+
This involves authenticating with any of: HTTP Basic Auth, Client Credentials and
267+
Access token in that order. Breaks off after first validation.
264268
"""
265269

266270
defdispatch(self, request, *args, **kwargs):

‎tests/test_introspection_view.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from .utilsimportget_basic_auth_header
1313

14+
1415
Application=get_application_model()
1516
AccessToken=get_access_token_model()
1617
UserModel=get_user_model()
@@ -20,9 +21,12 @@ class TestTokenIntrospectionViews(TestCase):
2021
"""
2122
Tests for Authorized Token Introspection Views
2223
"""
24+
2325
defsetUp(self):
24-
self.resource_server_user=UserModel.objects.create_user("resource_server", "[email protected]")
25-
self.test_user=UserModel.objects.create_user("bar_user", "[email protected]")
26+
self.resource_server_user=UserModel.objects.create_user(
27+
"resource_server", "[email protected]")
28+
self.test_user=UserModel.objects.create_user(
29+
"bar_user", "[email protected]")
2630

2731
self.application=Application.objects.create(
2832
name="Test Application",
@@ -261,7 +265,8 @@ def test_view_post_notexisting_token(self):
261265
deftest_view_post_valid_client_creds_basic_auth(self):
262266
"""Test HTTP basic auth working
263267
"""
264-
auth_headers=get_basic_auth_header(self.application.client_id, self.application.client_secret)
268+
auth_headers=get_basic_auth_header(
269+
self.application.client_id, self.application.client_secret)
265270
response=self.client.post(
266271
reverse("oauth2_provider:introspect"),
267272
{"token": self.valid_token.token},
@@ -280,7 +285,8 @@ def test_view_post_valid_client_creds_basic_auth(self):
280285
deftest_view_post_invalid_client_creds_basic_auth(self):
281286
"""Must fail for invalid client credentials
282287
"""
283-
auth_headers=get_basic_auth_header(self.application.client_id, self.application.client_secret+"_so_wrong")
288+
auth_headers=get_basic_auth_header(
289+
self.application.client_id, self.application.client_secret+"_so_wrong")
284290
response=self.client.post(
285291
reverse("oauth2_provider:introspect"),
286292
{"token": self.valid_token.token},

0 commit comments

Comments
(0)