Skip to content

Commit

Permalink
more on code with flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
palazzem committed Apr 20, 2015
1 parent 576f34d commit fec119f
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 30 deletions.
1 change: 1 addition & 0 deletions oauth2_provider/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .models import Grant, AccessToken, RefreshToken, get_application_model


class RawIDAdmin(admin.ModelAdmin):
raw_id_fields = ('user',)

Expand Down
2 changes: 1 addition & 1 deletion oauth2_provider/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
from django.apps import apps
get_model = apps.get_model
except ImportError:
from django.db.models import get_model
from django.db.models import get_model
1 change: 0 additions & 1 deletion oauth2_provider/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def my_view(request):
# An access token is required to get here...
# ...
pass
"""
_scopes = scopes or []

Expand Down
1 change: 0 additions & 1 deletion oauth2_provider/ext/rest_framework/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,3 @@ def get_scopes(self, request, view):
read_write_scope = oauth2_settings.WRITE_SCOPE

return required_scopes + [read_write_scope]

4 changes: 2 additions & 2 deletions oauth2_provider/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def redirect_uri_allowed(self, uri):
parsed_uri = urlparse(uri)

if (parsed_allowed_uri.scheme == parsed_uri.scheme and
parsed_allowed_uri.netloc == parsed_uri.netloc and
parsed_allowed_uri.path == parsed_uri.path):
parsed_allowed_uri.netloc == parsed_uri.netloc and
parsed_allowed_uri.path == parsed_uri.path):

aqs_set = set(parse_qsl(parsed_allowed_uri.query))
uqs_set = set(parse_qsl(parsed_uri.query))
Expand Down
2 changes: 1 addition & 1 deletion oauth2_provider/oauth2_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _authenticate_request_body(self, request):
Remember that this method is NOT RECOMMENDED and SHOULD be limited to clients unable to
directly utilize the HTTP Basic authentication scheme. See rfc:`2.3.1` for more details.
"""
#TODO: check if oauthlib has already unquoted client_id and client_secret
# TODO: check if oauthlib has already unquoted client_id and client_secret
client_id = request.client_id
client_secret = request.client_secret

Expand Down
2 changes: 1 addition & 1 deletion oauth2_provider/tests/test_auth_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_get_user(self):
'oauth2_provider.backends.OAuth2Backend',
'django.contrib.auth.backends.ModelBackend',
),
MIDDLEWARE_CLASSES=MIDDLEWARE_CLASSES+('oauth2_provider.middleware.OAuth2TokenMiddleware',)
MIDDLEWARE_CLASSES=MIDDLEWARE_CLASSES + ('oauth2_provider.middleware.OAuth2TokenMiddleware',)
)
class TestOAuth2Middleware(BaseTest):

Expand Down
21 changes: 10 additions & 11 deletions oauth2_provider/tests/test_authorization_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from ..compat import urlparse, parse_qs, urlencode, get_user_model
from ..models import get_application_model, Grant, AccessToken
from ..settings import oauth2_settings
from ..oauth2_validators import OAuth2Validator
from ..views import ProtectedResourceView

from .test_utils import TestCaseUtils
Expand All @@ -35,7 +34,7 @@ def setUp(self):
self.dev_user = UserModel.objects.create_user("dev_user", "dev@user.com", "123456")

oauth2_settings.ALLOWED_REDIRECT_URI_SCHEMES = ['http', 'custom-scheme']

self.application = Application(
name="Test Application",
redirect_uris="http://localhost http://example.com http://example.it custom-scheme://example.com",
Expand Down Expand Up @@ -74,7 +73,6 @@ def test_skip_authorization_completely(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 302)


def test_pre_auth_invalid_client(self):
"""
Test error for an invalid client_id with response_type: code
Expand Down Expand Up @@ -147,11 +145,11 @@ def test_pre_auth_valid_client_custom_redirect_uri_scheme(self):

def test_pre_auth_approval_prompt(self):
"""
TODO
"""
tok = AccessToken.objects.create(user=self.test_user, token='1234567890',
application=self.application,
expires=timezone.now()+datetime.timedelta(days=1),
expires=timezone.now() + datetime.timedelta(days=1),
scope='read write')
self.client.login(username="test_user", password="123456")
query_string = urlencode({
Expand All @@ -173,13 +171,13 @@ def test_pre_auth_approval_prompt(self):

def test_pre_auth_approval_prompt_default(self):
"""
TODO
"""
self.assertEqual(oauth2_settings.REQUEST_APPROVAL_PROMPT, 'force')

AccessToken.objects.create(user=self.test_user, token='1234567890',
application=self.application,
expires=timezone.now()+datetime.timedelta(days=1),
expires=timezone.now() + datetime.timedelta(days=1),
scope='read write')
self.client.login(username="test_user", password="123456")
query_string = urlencode({
Expand All @@ -195,13 +193,13 @@ def test_pre_auth_approval_prompt_default(self):

def test_pre_auth_approval_prompt_default_override(self):
"""
TODO
"""
oauth2_settings.REQUEST_APPROVAL_PROMPT = 'auto'

AccessToken.objects.create(user=self.test_user, token='1234567890',
application=self.application,
expires=timezone.now()+datetime.timedelta(days=1),
expires=timezone.now() + datetime.timedelta(days=1),
scope='read write')
self.client.login(username="test_user", password="123456")
query_string = urlencode({
Expand Down Expand Up @@ -634,7 +632,8 @@ def test_refresh_repeating_requests_non_rotating_tokens(self):
'scope': content['scope'],
}

with mock.patch('oauthlib.oauth2.rfc6749.request_validator.RequestValidator.rotate_refresh_token', return_value=False):
with mock.patch('oauthlib.oauth2.rfc6749.request_validator.RequestValidator.rotate_refresh_token',
return_value=False):
response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers)
self.assertEqual(response.status_code, 200)
response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers)
Expand Down Expand Up @@ -742,7 +741,7 @@ def test_request_body_params(self):
'code': authorization_code,
'redirect_uri': 'http://example.it',
'client_id': self.application.client_id,
'client_secret': self.application.client_secret,
'client_secret': self.application.client_secret,
}

response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data)
Expand Down
7 changes: 4 additions & 3 deletions oauth2_provider/tests/test_client_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ def test_client_resource_password_based(self):
'username': 'test_user',
'password': '123456'
}
auth_headers = self.get_basic_auth_header(urllib.quote_plus(self.application.client_id), urllib.quote_plus(self.application.client_secret))
auth_headers = self.get_basic_auth_header(
urllib.quote_plus(self.application.client_id),
urllib.quote_plus(self.application.client_secret))

response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers)
self.assertEqual(response.status_code, 200)

Expand All @@ -185,5 +188,3 @@ def test_client_resource_password_based(self):
view = ResourceView.as_view()
response = view(request)
self.assertEqual(response, "This is a protected resource")


3 changes: 2 additions & 1 deletion oauth2_provider/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.core.exceptions import ValidationError
from django.utils import timezone

from ..models import AccessToken, get_application_model, Grant, AccessToken, RefreshToken
from ..models import get_application_model, Grant, AccessToken, RefreshToken
from ..compat import get_user_model


Expand Down Expand Up @@ -81,6 +81,7 @@ def test_str(self):
app.name = "test_app"
self.assertEqual("%s" % app, "test_app")


@skipIf(django.VERSION < (1, 5), "Behavior is broken on 1.4 and there is no solution")
@override_settings(OAUTH2_PROVIDER_APPLICATION_MODEL='tests.TestApplication')
class TestCustomApplicationModel(TestCase):
Expand Down
14 changes: 7 additions & 7 deletions oauth2_provider/tests/test_token_revocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_revoke_access_token(self):
"""
tok = AccessToken.objects.create(user=self.test_user, token='1234567890',
application=self.application,
expires=timezone.now()+datetime.timedelta(days=1),
expires=timezone.now() + datetime.timedelta(days=1),
scope='read write')
query_string = urlencode({
'client_id': self.application.client_id,
Expand All @@ -66,7 +66,7 @@ def test_revoke_access_token_with_hint(self):
"""
tok = AccessToken.objects.create(user=self.test_user, token='1234567890',
application=self.application,
expires=timezone.now()+datetime.timedelta(days=1),
expires=timezone.now() + datetime.timedelta(days=1),
scope='read write')
query_string = urlencode({
'client_id': self.application.client_id,
Expand All @@ -85,7 +85,7 @@ def test_revoke_access_token_with_invalid_hint(self):
"""
tok = AccessToken.objects.create(user=self.test_user, token='1234567890',
application=self.application,
expires=timezone.now()+datetime.timedelta(days=1),
expires=timezone.now() + datetime.timedelta(days=1),
scope='read write')
# invalid hint should have no effect
query_string = urlencode({
Expand All @@ -105,7 +105,7 @@ def test_revoke_refresh_token(self):
"""
tok = AccessToken.objects.create(user=self.test_user, token='1234567890',
application=self.application,
expires=timezone.now()+datetime.timedelta(days=1),
expires=timezone.now() + datetime.timedelta(days=1),
scope='read write')
rtok = RefreshToken.objects.create(user=self.test_user, token='999999999',
application=self.application, access_token=tok)
Expand All @@ -123,12 +123,13 @@ def test_revoke_token_with_wrong_hint(self):
"""
From the revocation rfc, `Section 4.1.2`_ :
If the server is unable to locate the token using the given hint, it MUST extend its search across all of its supported token typeso
If the server is unable to locate the token using the given hint,
it MUST extend its search across all of its supported token types
.. _`Section 4.1.2`: http://tools.ietf.org/html/draft-ietf-oauth-revocation-11#section-4.1.2
"""
tok = AccessToken.objects.create(user=self.test_user, token='1234567890',
application=self.application,
expires=timezone.now()+datetime.timedelta(days=1),
expires=timezone.now() + datetime.timedelta(days=1),
scope='read write')

query_string = urlencode({
Expand All @@ -141,4 +142,3 @@ def test_revoke_token_with_wrong_hint(self):
response = self.client.post(url)
self.assertEqual(response.status_code, 200)
self.assertFalse(AccessToken.objects.filter(id=tok.id).exists())

1 change: 0 additions & 1 deletion oauth2_provider/tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ def test_validate_bad_uris(self):
self.assertRaises(ValidationError, validate_uris, bad_uri)
bad_uri = 'sdklfsjlfjljdflksjlkfjsdkl'
self.assertRaises(ValidationError, validate_uris, bad_uri)

1 change: 1 addition & 0 deletions oauth2_provider/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from .settings import oauth2_settings


class URIValidator(RegexValidator):
regex = re.compile(
r'^(?:[a-z][a-z0-9\.\-\+]*)://' # scheme...
Expand Down

0 comments on commit fec119f

Please sign in to comment.