Skip to content

Commit b64fecd

Browse files
committed
tests: Clean up code style and run flake8 over tests/ directory too
1 parent 9ee08d4 commit b64fecd

21 files changed

+1004
-975
lines changed

docs/rfc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""
22
Custom Sphinx documentation module to link to parts of the OAuth2 RFC.
33
"""
4-
from docutils import nodes, utils
4+
from docutils import nodes
5+
56

67
base_url = "http://tools.ietf.org/html/rfc6749"
78

@@ -33,5 +34,4 @@ def setup(app):
3334
3435
:param app: Sphinx application context.
3536
"""
36-
app.add_role('rfc', rfclink)
37-
return
37+
app.add_role("rfc", rfclink)

tests/models.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from django.db import models
22

33
from oauth2_provider.models import (
4-
AbstractApplication,
5-
AbstractAccessToken,
6-
AbstractGrant,
7-
AbstractRefreshToken,
4+
AbstractAccessToken, AbstractApplication,
5+
AbstractGrant, AbstractRefreshToken
86
)
97

108

tests/settings.py

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,126 +3,126 @@
33
MANAGERS = ADMINS
44

55
DATABASES = {
6-
'default': {
7-
'ENGINE': 'django.db.backends.sqlite3',
8-
'NAME': 'example.sqlite',
6+
"default": {
7+
"ENGINE": "django.db.backends.sqlite3",
8+
"NAME": "example.sqlite",
99
}
1010
}
1111

1212
ALLOWED_HOSTS = []
1313

1414
TIME_ZONE = "UTC"
1515

16-
LANGUAGE_CODE = 'en-us'
16+
LANGUAGE_CODE = "en-us"
1717

1818
SITE_ID = 1
1919

2020
USE_I18N = True
2121
USE_L10N = True
2222
USE_TZ = True
2323

24-
MEDIA_ROOT = ''
25-
MEDIA_URL = ''
24+
MEDIA_ROOT = ""
25+
MEDIA_URL = ""
2626

27-
STATIC_ROOT = ''
28-
STATIC_URL = '/static/'
27+
STATIC_ROOT = ""
28+
STATIC_URL = "/static/"
2929

3030
STATICFILES_DIRS = ()
3131

3232
STATICFILES_FINDERS = (
33-
'django.contrib.staticfiles.finders.FileSystemFinder',
34-
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
33+
"django.contrib.staticfiles.finders.FileSystemFinder",
34+
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
3535
)
3636

37-
# Make this unique, and don't share it with anybody.
37+
# Make this unique, and don"t share it with anybody.
3838
SECRET_KEY = "1234567890evonove"
3939

4040
TEMPLATES = [
4141
{
42-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
43-
'DIRS': [],
44-
'APP_DIRS': True,
45-
'OPTIONS': {
46-
'debug': True,
47-
'context_processors': [
48-
'django.contrib.auth.context_processors.auth',
49-
'django.template.context_processors.debug',
50-
'django.template.context_processors.i18n',
51-
'django.template.context_processors.media',
52-
'django.template.context_processors.static',
53-
'django.template.context_processors.tz',
54-
'django.contrib.messages.context_processors.messages',
42+
"BACKEND": "django.template.backends.django.DjangoTemplates",
43+
"DIRS": [],
44+
"APP_DIRS": True,
45+
"OPTIONS": {
46+
"debug": True,
47+
"context_processors": [
48+
"django.contrib.auth.context_processors.auth",
49+
"django.template.context_processors.debug",
50+
"django.template.context_processors.i18n",
51+
"django.template.context_processors.media",
52+
"django.template.context_processors.static",
53+
"django.template.context_processors.tz",
54+
"django.contrib.messages.context_processors.messages",
5555
],
5656
},
5757
},
5858
]
5959

6060
MIDDLEWARE = (
61-
'django.middleware.common.CommonMiddleware',
62-
'django.contrib.sessions.middleware.SessionMiddleware',
63-
'django.middleware.csrf.CsrfViewMiddleware',
64-
'django.contrib.auth.middleware.AuthenticationMiddleware',
65-
'django.contrib.messages.middleware.MessageMiddleware',
61+
"django.middleware.common.CommonMiddleware",
62+
"django.contrib.sessions.middleware.SessionMiddleware",
63+
"django.middleware.csrf.CsrfViewMiddleware",
64+
"django.contrib.auth.middleware.AuthenticationMiddleware",
65+
"django.contrib.messages.middleware.MessageMiddleware",
6666
)
6767
# Django < 1.10 compatibility
6868
MIDDLEWARE_CLASSES = MIDDLEWARE
6969

70-
ROOT_URLCONF = 'tests.urls'
70+
ROOT_URLCONF = "tests.urls"
7171

7272
INSTALLED_APPS = (
73-
'django.contrib.auth',
74-
'django.contrib.contenttypes',
75-
'django.contrib.sessions',
76-
'django.contrib.sites',
77-
'django.contrib.staticfiles',
78-
'django.contrib.admin',
79-
80-
'oauth2_provider',
81-
'tests',
73+
"django.contrib.auth",
74+
"django.contrib.contenttypes",
75+
"django.contrib.sessions",
76+
"django.contrib.sites",
77+
"django.contrib.staticfiles",
78+
"django.contrib.admin",
79+
80+
"oauth2_provider",
81+
"tests",
8282
)
8383

8484
LOGGING = {
85-
'version': 1,
86-
'disable_existing_loggers': False,
87-
'formatters': {
88-
'verbose': {
89-
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
85+
"version": 1,
86+
"disable_existing_loggers": False,
87+
"formatters": {
88+
"verbose": {
89+
"format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s"
9090
},
91-
'simple': {
92-
'format': '%(levelname)s %(message)s'
91+
"simple": {
92+
"format": "%(levelname)s %(message)s"
9393
},
9494
},
95-
'filters': {
96-
'require_debug_false': {
97-
'()': 'django.utils.log.RequireDebugFalse'
95+
"filters": {
96+
"require_debug_false": {
97+
"()": "django.utils.log.RequireDebugFalse"
9898
}
9999
},
100-
'handlers': {
101-
'mail_admins': {
102-
'level': 'ERROR',
103-
'filters': ['require_debug_false'],
104-
'class': 'django.utils.log.AdminEmailHandler'
100+
"handlers": {
101+
"mail_admins": {
102+
"level": "ERROR",
103+
"filters": ["require_debug_false"],
104+
"class": "django.utils.log.AdminEmailHandler"
105105
},
106-
'console': {
107-
'level': 'DEBUG',
108-
'class': 'logging.StreamHandler',
109-
'formatter': 'simple'
106+
"console": {
107+
"level": "DEBUG",
108+
"class": "logging.StreamHandler",
109+
"formatter": "simple"
110110
},
111-
'null': {
112-
'level': 'DEBUG',
113-
'class': 'logging.NullHandler',
111+
"null": {
112+
"level": "DEBUG",
113+
"class": "logging.NullHandler",
114114
},
115115
},
116-
'loggers': {
117-
'django.request': {
118-
'handlers': ['mail_admins'],
119-
'level': 'ERROR',
120-
'propagate': True,
116+
"loggers": {
117+
"django.request": {
118+
"handlers": ["mail_admins"],
119+
"level": "ERROR",
120+
"propagate": True,
121121
},
122-
'oauth2_provider': {
123-
'handlers': ['null'],
124-
'level': 'DEBUG',
125-
'propagate': True,
122+
"oauth2_provider": {
123+
"handlers": ["null"],
124+
"level": "DEBUG",
125+
"propagate": True,
126126
},
127127
}
128128
}

tests/test_application_views.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class TestApplicationRegistrationView(BaseTest):
2929

3030
def test_get_form_class(self):
3131
"""
32-
Tests that the form class returned by the 'get_form_class' method is
32+
Tests that the form class returned by the "get_form_class" method is
3333
bound to custom application model defined in the
34-
'OAUTH2_PROVIDER_APPLICATION_MODEL' setting.
34+
"OAUTH2_PROVIDER_APPLICATION_MODEL" setting.
3535
"""
3636
# Patch oauth2 settings to use a custom Application model
3737
oauth2_settings.APPLICATION_MODEL = "tests.SampleApplication"
@@ -40,21 +40,21 @@ def test_get_form_class(self):
4040
application_form_class = ApplicationRegistration().get_form_class()
4141
self.assertEqual(SampleApplication, application_form_class._meta.model)
4242
# Revert oauth2 settings
43-
oauth2_settings.APPLICATION_MODEL = 'oauth2_provider.Application'
43+
oauth2_settings.APPLICATION_MODEL = "oauth2_provider.Application"
4444

4545
def test_application_registration_user(self):
4646
self.client.login(username="foo_user", password="123456")
4747

4848
form_data = {
49-
'name': 'Foo app',
50-
'client_id': 'client_id',
51-
'client_secret': 'client_secret',
52-
'client_type': Application.CLIENT_CONFIDENTIAL,
53-
'redirect_uris': 'http://example.com',
54-
'authorization_grant_type': Application.GRANT_AUTHORIZATION_CODE
49+
"name": "Foo app",
50+
"client_id": "client_id",
51+
"client_secret": "client_secret",
52+
"client_type": Application.CLIENT_CONFIDENTIAL,
53+
"redirect_uris": "http://example.com",
54+
"authorization_grant_type": Application.GRANT_AUTHORIZATION_CODE,
5555
}
5656

57-
response = self.client.post(reverse('oauth2_provider:register'), form_data)
57+
response = self.client.post(reverse("oauth2_provider:register"), form_data)
5858
self.assertEqual(response.status_code, 302)
5959

6060
app = get_application_model().objects.get(name="Foo app")
@@ -73,12 +73,12 @@ def _create_application(self, name, user):
7373

7474
def setUp(self):
7575
super(TestApplicationViews, self).setUp()
76-
self.app_foo_1 = self._create_application('app foo_user 1', self.foo_user)
77-
self.app_foo_2 = self._create_application('app foo_user 2', self.foo_user)
78-
self.app_foo_3 = self._create_application('app foo_user 3', self.foo_user)
76+
self.app_foo_1 = self._create_application("app foo_user 1", self.foo_user)
77+
self.app_foo_2 = self._create_application("app foo_user 2", self.foo_user)
78+
self.app_foo_3 = self._create_application("app foo_user 3", self.foo_user)
7979

80-
self.app_bar_1 = self._create_application('app bar_user 1', self.bar_user)
81-
self.app_bar_2 = self._create_application('app bar_user 2', self.bar_user)
80+
self.app_bar_1 = self._create_application("app bar_user 1", self.bar_user)
81+
self.app_bar_2 = self._create_application("app bar_user 2", self.bar_user)
8282

8383
def tearDown(self):
8484
super(TestApplicationViews, self).tearDown()
@@ -87,18 +87,18 @@ def tearDown(self):
8787
def test_application_list(self):
8888
self.client.login(username="foo_user", password="123456")
8989

90-
response = self.client.get(reverse('oauth2_provider:list'))
90+
response = self.client.get(reverse("oauth2_provider:list"))
9191
self.assertEqual(response.status_code, 200)
92-
self.assertEqual(len(response.context['object_list']), 3)
92+
self.assertEqual(len(response.context["object_list"]), 3)
9393

9494
def test_application_detail_owner(self):
9595
self.client.login(username="foo_user", password="123456")
9696

97-
response = self.client.get(reverse('oauth2_provider:detail', args=(self.app_foo_1.pk,)))
97+
response = self.client.get(reverse("oauth2_provider:detail", args=(self.app_foo_1.pk,)))
9898
self.assertEqual(response.status_code, 200)
9999

100100
def test_application_detail_not_owner(self):
101101
self.client.login(username="foo_user", password="123456")
102102

103-
response = self.client.get(reverse('oauth2_provider:detail', args=(self.app_bar_1.pk,)))
103+
response = self.client.get(reverse("oauth2_provider:detail", args=(self.app_bar_1.pk,)))
104104
self.assertEqual(response.status_code, 404)

0 commit comments

Comments
 (0)