Skip to content

Commit db25ce7

Browse files
committed
Fixed tests for Django 1.10
1 parent 54c51b0 commit db25ce7

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

oauth2_provider/admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class RawIDAdmin(admin.ModelAdmin):
77
raw_id_fields = ('user',)
88

9+
910
Application = get_application_model()
1011

1112
admin.site.register(Application, RawIDAdmin)

oauth2_provider/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# bastb Django 1.10 has updated Middleware. This code imports the Mixin required to get old-style
55
# middleware working again
6-
# More?
6+
# More?
77
# https://docs.djangoproject.com/en/1.10/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware
88
try:
99
from django.utils.deprecation import MiddlewareMixin

oauth2_provider/tests/settings.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
DEBUG = True
2-
TEMPLATE_DEBUG = DEBUG
3-
41
ADMINS = ()
52

63
MANAGERS = ADMINS
@@ -40,10 +37,25 @@
4037
# Make this unique, and don't share it with anybody.
4138
SECRET_KEY = "1234567890evonove"
4239

43-
TEMPLATE_LOADERS = (
44-
'django.template.loaders.filesystem.Loader',
45-
'django.template.loaders.app_directories.Loader',
46-
)
40+
TEMPLATES = [
41+
{
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',
55+
],
56+
},
57+
},
58+
]
4759

4860
MIDDLEWARE_CLASSES = (
4961
'django.middleware.common.CommonMiddleware',
@@ -55,8 +67,6 @@
5567

5668
ROOT_URLCONF = 'oauth2_provider.tests.urls'
5769

58-
TEMPLATE_DIRS = ()
59-
6070
INSTALLED_APPS = (
6171
'django.contrib.auth',
6272
'django.contrib.contenttypes',

oauth2_provider/tests/test_models.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,14 @@ def test_related_objects(self):
122122
# Django internals caches the related objects.
123123
if django.VERSION < (1, 8):
124124
del UserModel._meta._related_objects_cache
125-
related_object_names = [ro.name for ro in UserModel._meta.get_all_related_objects()]
125+
if django.VERSION < (1, 10):
126+
related_object_names = [ro.name for ro in UserModel._meta.get_all_related_objects()]
127+
else:
128+
related_object_names = [
129+
f.name for f in UserModel._meta.get_fields()
130+
if (f.one_to_many or f.one_to_one)
131+
and f.auto_created and not f.concrete
132+
]
126133
self.assertNotIn('oauth2_provider:application', related_object_names)
127134
self.assertIn('tests%stestapplication' % (':' if django.VERSION < (1, 8) else '_'),
128135
related_object_names)

oauth2_provider/tests/test_rest_framework.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.contrib.auth import get_user_model
66
from django.http import HttpResponse
77
from django.test import TestCase
8+
from django.test.utils import override_settings
89
from django.utils import timezone
910

1011
from .test_utils import TestCaseUtils
@@ -71,9 +72,8 @@ class BaseTest(TestCaseUtils, TestCase):
7172
pass
7273

7374

75+
@override_settings(ROOT_URLCONF=__name__)
7476
class TestOAuth2Authentication(BaseTest):
75-
urls = 'oauth2_provider.tests.test_rest_framework'
76-
7777
def setUp(self):
7878
oauth2_settings._SCOPES = ['read', 'write', 'scope1', 'scope2', 'resource1']
7979

0 commit comments

Comments
 (0)