From a23b11e3c0aa8786db47fa9ef7c2e904a2a759bf Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Thu, 27 Oct 2016 23:57:26 +0200 Subject: [PATCH 1/4] added support for django 1.10 in tox.ini --- tox.ini | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tox.ini b/tox.ini index 11ddb9f8e..6dcdaff2d 100644 --- a/tox.ini +++ b/tox.ini @@ -4,11 +4,11 @@ testpaths=oauth2_provider [tox] envlist = - py27-django{18,19}, + py27-django{18,19,110}, py32-django18, py33-django18, - py34-django{18,19}, - py35-django{18,19}, + py34-django{18,19,110}, + py35-django{18,19,110}, docs, flake8 @@ -17,6 +17,7 @@ commands=python runtests.py -q --cov=oauth2_provider --cov-report= --cov-append deps = django18: Django==1.8.15 django19: Django==1.9.10 + django110: Django==1.10.2 coverage==4.1 pytest-cov==2.3.0 -rrequirements/testing.txt @@ -31,6 +32,7 @@ deps = [testenv:docs] basepython=python changedir=docs +whitelist_externals=make deps = sphinx south From 54c51b04a84fdd409518e3bdb33e53936bd4f373 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Fri, 28 Oct 2016 00:04:52 +0200 Subject: [PATCH 2/4] urlpatterns are now plain lists --- README.rst | 4 ++-- docs/install.rst | 4 ++-- docs/rest-framework/getting_started.rst | 6 +++--- docs/tutorial/tutorial_01.rst | 5 ++--- docs/tutorial/tutorial_02.rst | 2 +- docs/tutorial/tutorial_03.rst | 5 ++--- oauth2_provider/tests/test_rest_framework.py | 7 +++---- oauth2_provider/tests/urls.py | 4 ++-- oauth2_provider/urls.py | 12 ++++++------ 9 files changed, 23 insertions(+), 26 deletions(-) diff --git a/README.rst b/README.rst index 973a72a2e..021e5f211 100644 --- a/README.rst +++ b/README.rst @@ -72,10 +72,10 @@ Notice that `oauth2_provider` namespace is mandatory. .. code-block:: python - urlpatterns = patterns( + urlpatterns = [ ... url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), - ) + ] Documentation -------------- diff --git a/docs/install.rst b/docs/install.rst index adaf95f34..60e9d8fe6 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -19,10 +19,10 @@ If you need an OAuth2 provider you'll want to add the following to your urls.py .. code-block:: python - urlpatterns = patterns( + urlpatterns = [ ... url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), - ) + ] Sync your database ------------------ diff --git a/docs/rest-framework/getting_started.rst b/docs/rest-framework/getting_started.rst index 58d9abb13..9fa8f873e 100644 --- a/docs/rest-framework/getting_started.rst +++ b/docs/rest-framework/getting_started.rst @@ -48,7 +48,7 @@ Here's our project's root `urls.py` module: .. code-block:: python - from django.conf.urls import url, patterns, include + from django.conf.urls import url, include from django.contrib.auth.models import User, Group from django.contrib import admin admin.autodiscover() @@ -91,11 +91,11 @@ Here's our project's root `urls.py` module: # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browseable API. - urlpatterns = patterns('', + urlpatterns = [ url(r'^', include(router.urls)), url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), url(r'^admin/', include(admin.site.urls)), - ) + ] Also add the following to your `settings.py` module: diff --git a/docs/tutorial/tutorial_01.rst b/docs/tutorial/tutorial_01.rst index f4f2444ed..fb11db779 100644 --- a/docs/tutorial/tutorial_01.rst +++ b/docs/tutorial/tutorial_01.rst @@ -33,12 +33,11 @@ Include the Django OAuth Toolkit urls in your `urls.py`, choosing the urlspace y .. code-block:: python - urlpatterns = patterns( - '', + urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), # ... - ) + ] Include the CORS middleware in your `settings.py`: diff --git a/docs/tutorial/tutorial_02.rst b/docs/tutorial/tutorial_02.rst index 7b82e5264..326fa83e9 100644 --- a/docs/tutorial/tutorial_02.rst +++ b/docs/tutorial/tutorial_02.rst @@ -34,7 +34,7 @@ URL this view will respond to: .. code-block:: python - from django.conf.urls import patterns, url + from django.conf.urls import url import oauth2_provider.views as oauth2_views from django.conf import settings from .views import ApiEndpoint diff --git a/docs/tutorial/tutorial_03.rst b/docs/tutorial/tutorial_03.rst index 210cc24cc..d49e286c8 100644 --- a/docs/tutorial/tutorial_03.rst +++ b/docs/tutorial/tutorial_03.rst @@ -65,11 +65,10 @@ To check everything works properly, mount the view above to some url: .. code-block:: python - urlpatterns = patterns( - '', + urlpatterns = [ url(r'^secret$', 'my.views.secret_page', name='secret'), '...', - ) + ] You should have an :term:`Application` registered at this point, if you don't, follow the steps in the previous tutorials to create one. Obtain an :term:`Access Token`, either following the OAuth2 diff --git a/oauth2_provider/tests/test_rest_framework.py b/oauth2_provider/tests/test_rest_framework.py index a64f58cd1..57e344309 100644 --- a/oauth2_provider/tests/test_rest_framework.py +++ b/oauth2_provider/tests/test_rest_framework.py @@ -1,7 +1,7 @@ import unittest from datetime import timedelta -from django.conf.urls import patterns, url, include +from django.conf.urls import url, include from django.contrib.auth import get_user_model from django.http import HttpResponse from django.test import TestCase @@ -50,15 +50,14 @@ class ResourceScopedView(OAuth2View): permission_classes = [permissions.IsAuthenticated, TokenHasResourceScope] required_scopes = ['resource1'] - urlpatterns = patterns( - '', + urlpatterns = [ url(r'^oauth2/', include('oauth2_provider.urls')), url(r'^oauth2-test/$', OAuth2View.as_view()), url(r'^oauth2-scoped-test/$', ScopedView.as_view()), url(r'^oauth2-read-write-test/$', ReadWriteScopedView.as_view()), url(r'^oauth2-resource-scoped-test/$', ResourceScopedView.as_view()), url(r'^oauth2-authenticated-or-scoped-test/$', AuthenticatedOrScopedView.as_view()), - ) + ] rest_framework_installed = True except ImportError: diff --git a/oauth2_provider/tests/urls.py b/oauth2_provider/tests/urls.py index aa925826a..7695ca39a 100644 --- a/oauth2_provider/tests/urls.py +++ b/oauth2_provider/tests/urls.py @@ -4,7 +4,7 @@ admin.autodiscover() -urlpatterns = ( +urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), -) +] diff --git a/oauth2_provider/urls.py b/oauth2_provider/urls.py index ebcb9e0b6..2e3130e25 100644 --- a/oauth2_provider/urls.py +++ b/oauth2_provider/urls.py @@ -3,23 +3,23 @@ from . import views -urlpatterns = ( +urlpatterns = [ url(r'^authorize/$', views.AuthorizationView.as_view(), name="authorize"), url(r'^token/$', views.TokenView.as_view(), name="token"), url(r'^revoke_token/$', views.RevokeTokenView.as_view(), name="revoke-token"), -) +] # Application management views -urlpatterns += ( +urlpatterns += [ url(r'^applications/$', views.ApplicationList.as_view(), name="list"), url(r'^applications/register/$', views.ApplicationRegistration.as_view(), name="register"), url(r'^applications/(?P\d+)/$', views.ApplicationDetail.as_view(), name="detail"), url(r'^applications/(?P\d+)/delete/$', views.ApplicationDelete.as_view(), name="delete"), url(r'^applications/(?P\d+)/update/$', views.ApplicationUpdate.as_view(), name="update"), -) +] -urlpatterns += ( +urlpatterns += [ url(r'^authorized_tokens/$', views.AuthorizedTokensListView.as_view(), name="authorized-token-list"), url(r'^authorized_tokens/(?P\d+)/delete/$', views.AuthorizedTokenDeleteView.as_view(), name="authorized-token-delete"), -) +] From db25ce7b491f886b486fb967001daabb146bbf77 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Thu, 17 Nov 2016 23:55:03 +0100 Subject: [PATCH 3/4] Fixed tests for Django 1.10 --- oauth2_provider/admin.py | 1 + oauth2_provider/middleware.py | 2 +- oauth2_provider/tests/settings.py | 28 +++++++++++++------- oauth2_provider/tests/test_models.py | 9 ++++++- oauth2_provider/tests/test_rest_framework.py | 4 +-- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/oauth2_provider/admin.py b/oauth2_provider/admin.py index d3c764adf..20bf1cb75 100644 --- a/oauth2_provider/admin.py +++ b/oauth2_provider/admin.py @@ -6,6 +6,7 @@ class RawIDAdmin(admin.ModelAdmin): raw_id_fields = ('user',) + Application = get_application_model() admin.site.register(Application, RawIDAdmin) diff --git a/oauth2_provider/middleware.py b/oauth2_provider/middleware.py index 0984443ca..3ea729a4b 100644 --- a/oauth2_provider/middleware.py +++ b/oauth2_provider/middleware.py @@ -3,7 +3,7 @@ # bastb Django 1.10 has updated Middleware. This code imports the Mixin required to get old-style # middleware working again -# More? +# More? # https://docs.djangoproject.com/en/1.10/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware try: from django.utils.deprecation import MiddlewareMixin diff --git a/oauth2_provider/tests/settings.py b/oauth2_provider/tests/settings.py index 1e38f8cc2..1bfc697db 100644 --- a/oauth2_provider/tests/settings.py +++ b/oauth2_provider/tests/settings.py @@ -1,6 +1,3 @@ -DEBUG = True -TEMPLATE_DEBUG = DEBUG - ADMINS = () MANAGERS = ADMINS @@ -40,10 +37,25 @@ # Make this unique, and don't share it with anybody. SECRET_KEY = "1234567890evonove" -TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', -) +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'debug': True, + 'context_processors': [ + 'django.contrib.auth.context_processors.auth', + 'django.template.context_processors.debug', + 'django.template.context_processors.i18n', + 'django.template.context_processors.media', + 'django.template.context_processors.static', + 'django.template.context_processors.tz', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', @@ -55,8 +67,6 @@ ROOT_URLCONF = 'oauth2_provider.tests.urls' -TEMPLATE_DIRS = () - INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/oauth2_provider/tests/test_models.py b/oauth2_provider/tests/test_models.py index 7bc191c2b..022beefa7 100644 --- a/oauth2_provider/tests/test_models.py +++ b/oauth2_provider/tests/test_models.py @@ -122,7 +122,14 @@ def test_related_objects(self): # Django internals caches the related objects. if django.VERSION < (1, 8): del UserModel._meta._related_objects_cache - related_object_names = [ro.name for ro in UserModel._meta.get_all_related_objects()] + if django.VERSION < (1, 10): + related_object_names = [ro.name for ro in UserModel._meta.get_all_related_objects()] + else: + related_object_names = [ + f.name for f in UserModel._meta.get_fields() + if (f.one_to_many or f.one_to_one) + and f.auto_created and not f.concrete + ] self.assertNotIn('oauth2_provider:application', related_object_names) self.assertIn('tests%stestapplication' % (':' if django.VERSION < (1, 8) else '_'), related_object_names) diff --git a/oauth2_provider/tests/test_rest_framework.py b/oauth2_provider/tests/test_rest_framework.py index 57e344309..4bf62e14e 100644 --- a/oauth2_provider/tests/test_rest_framework.py +++ b/oauth2_provider/tests/test_rest_framework.py @@ -5,6 +5,7 @@ from django.contrib.auth import get_user_model from django.http import HttpResponse from django.test import TestCase +from django.test.utils import override_settings from django.utils import timezone from .test_utils import TestCaseUtils @@ -71,9 +72,8 @@ class BaseTest(TestCaseUtils, TestCase): pass +@override_settings(ROOT_URLCONF=__name__) class TestOAuth2Authentication(BaseTest): - urls = 'oauth2_provider.tests.test_rest_framework' - def setUp(self): oauth2_settings._SCOPES = ['read', 'write', 'scope1', 'scope2', 'resource1'] From 4d18c5132f2e9e5fa02676a2c4665ae05e0399fb Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Fri, 18 Nov 2016 00:14:46 +0100 Subject: [PATCH 4/4] Updated changelog and authors --- AUTHORS | 1 + README.rst | 1 + docs/changelog.rst | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index f20b36ea9..7aa65f47c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -20,3 +20,4 @@ Paul Oswald Jens Timmerman Jim Graham pySilver +Silvano Cerza diff --git a/README.rst b/README.rst index 021e5f211..3455e593e 100644 --- a/README.rst +++ b/README.rst @@ -100,6 +100,7 @@ Changelog Development ~~~~~~~~~~~ +* #425: Added support for Django 1.10 * #396: added an IsAuthenticatedOrTokenHasScope Permission * #357: Support multiple-user clients by allowing User to be NULL for Applications * #389: Reuse refresh tokens if enabled. diff --git a/docs/changelog.rst b/docs/changelog.rst index 1ad4e67bf..6d8c55484 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,7 +4,8 @@ Changelog Development ~~~~~~~~~~~ -* #396: added an IsAuthenticatedOrTokenHasScope Permission +* #425: Added support for Django 1.10 +* #396: Added an IsAuthenticatedOrTokenHasScope Permission * #357: Support multiple-user clients by allowing User to be NULL for Applications * #389: Reuse refresh tokens if enabled.