Skip to content

Commit

Permalink
Adding support to Django 1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
amorim committed Mar 2, 2018
1 parent 336a0c7 commit ce36f1b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 17 deletions.
10 changes: 7 additions & 3 deletions oidc_auth/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from urlparse import urlparse, parse_qs
from django.conf import settings
from django.contrib.auth import get_user_model
from django.utils.importlib import import_module
from importlib import import_module
from django.test import Client
from nose import tools
import mock

from .utils import OIDCTestCase
from oidc_auth.models import OpenIDProvider, Nonce
from oidc_auth.models import OpenIDProvider, Nonce, OpenIDUser
from oidc_auth.settings import oidc_settings

UserModel = get_user_model()
Expand All @@ -26,6 +26,7 @@ def test_get_login(self):
response = self.client.get('/oidc/login/')

tools.assert_equal(response.status_code, 200)
print('Templates:', response.templates)
tools.assert_true(any(t.name == 'oidc/login.html' for t in response.templates))

@mock.patch('requests.get')
Expand Down Expand Up @@ -95,7 +96,8 @@ def test_post_token_endpoint(self, post_mock):
'refresh_token': '12345',
'expires_in': 3600,
'token_type': 'Bearer',
'id_token': '12345'
'id_token': '12345',
'sub': 'foobar'
}
post_mock.return_value = response

Expand All @@ -110,6 +112,7 @@ def test_post_token_endpoint(self, post_mock):
jwks_uri='http://a.b/jwks')

user = UserModel.objects.create(username='foobar')
OpenIDUser.objects.create(sub='foobar', issuer=provider, user=user)

session = self.client.session
session['oidc_state'] = state
Expand Down Expand Up @@ -168,6 +171,7 @@ def test_post_token_endpoint_with_invalid_ssl(self, post_mock):
session.save()

user = UserModel.objects.create(username='foobar')
OpenIDUser.objects.create(sub='foobar', issuer=provider, user=user)

with mock.patch.object(OpenIDProvider, 'verify_id_token') as mock_verify_id_token:
mock_verify_id_token.return_value = { 'sub': 'foobar' }
Expand Down
11 changes: 6 additions & 5 deletions oidc_auth/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.conf.urls import patterns, url
from django.conf.urls import url

import views

urlpatterns = patterns('oidc_auth.views',
url(r'^login/$', 'login_begin', name='oidc-login'),
url(r'^complete/$', 'login_complete', name='oidc-complete'),
)
urlpatterns = [
url(r'^login/$', views.login_begin, name='oidc-login'),
url(r'^complete/$', views.login_complete, name='oidc-complete'),
]
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Production requirements
Django>1.5
Django>1.9
pyjwkest==0.6.2
requests==2.2.1
South==1.0.2

# Test requirements
django-nose==1.4
django-nose==1.4.5
mock==1.0.1
tox
21 changes: 21 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import django
import logging

import os

django_version = django.get_version()
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

DEBUG = True
TEMPLATE_DEBUG = DEBUG
Expand Down Expand Up @@ -70,6 +74,23 @@
# Don't forget to use absolute paths, not relative paths.
)

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]


INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down
6 changes: 4 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = {py27}-django{15,16,17,18}
envlist = {py27}-django{15,16,17,18,19,111}

[testenv]
basepython =
Expand All @@ -8,11 +8,13 @@ deps =
pyjwkest==0.6.2
requests==2.2.1
South==1.0.2
django-nose==1.4
django-nose==1.4.5
mock==1.0.1
django15: Django>=1.5,<1.6
django16: Django>=1.6,<1.7
django17: Django>=1.7,<1.8
django18: Django>=1.8,<1.9
django19: Django>=1.9
django111: Django>=1.11
commands=
python manage.py test
15 changes: 10 additions & 5 deletions urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from django.conf.urls import patterns, url, include
from django.conf.urls import url, include
from django.contrib import admin

import oidc_auth
import views
from oidc_auth import urls

admin.autodiscover()


urlpatterns = patterns('views',
url(r'^$', 'index'),
url(r'^oidc/', include('oidc_auth.urls')),
urlpatterns = [
url(r'^$', views.index),
url(r'^oidc/', include(oidc_auth.urls)),
url(r'^admin/', include(admin.site.urls)),
)
]

0 comments on commit ce36f1b

Please sign in to comment.