Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django1.7 compatibility #93

Merged
merged 12 commits into from
Feb 3, 2023
4 changes: 3 additions & 1 deletion provider/oauth2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
import managers
import models
import urls
import views
import views

default_app_config = 'provider.oauth2.apps.Oauth2'
6 changes: 6 additions & 0 deletions provider/oauth2/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig

class Oauth2(AppConfig):
name = 'provider.oauth2'
label = 'oauth2'
verbose_name = "Provider Oauth2"
16 changes: 16 additions & 0 deletions provider/oauth2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def deserialize(cls, data):

return cls(**kwargs)

class Meta:
app_label = 'oauth2'
db_table = 'oauth2_client'


class Grant(models.Model):
"""
Expand Down Expand Up @@ -108,6 +112,10 @@ class Grant(models.Model):
def __unicode__(self):
return self.code

class Meta:
app_label = 'oauth2'
db_table = 'oauth2_grant'


class AccessToken(models.Model):
"""
Expand Down Expand Up @@ -165,6 +173,10 @@ def get_expire_delta(self, reference=None):
timedelta = expiration - reference
return timedelta.days*86400 + timedelta.seconds

class Meta:
app_label = 'oauth2'
db_table = 'oauth2_accesstoken'


class RefreshToken(models.Model):
"""
Expand All @@ -188,3 +200,7 @@ class RefreshToken(models.Model):

def __unicode__(self):
return self.token

class Meta:
app_label = 'oauth2'
db_table = 'oauth2_refreshtoken'
6 changes: 3 additions & 3 deletions provider/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def error_response(self, error, mimetype='application/json', status=400,
Return an error response to the client with default status code of
*400* stating the error as outlined in :rfc:`5.2`.
"""
return HttpResponse(json.dumps(error), mimetype=mimetype,
return HttpResponse(json.dumps(error), content_type=mimetype,
status=status, **kwargs)

def get(self, request):
Expand Down Expand Up @@ -463,7 +463,7 @@ def error_response(self, error, mimetype='application/json', status=400,
Return an error response to the client with default status code of
*400* stating the error as outlined in :rfc:`5.2`.
"""
return HttpResponse(json.dumps(error), mimetype=mimetype,
return HttpResponse(json.dumps(error), content_type=mimetype,
status=status, **kwargs)

def access_token_response(self, access_token):
Expand All @@ -488,7 +488,7 @@ def access_token_response(self, access_token):
pass

return HttpResponse(
json.dumps(response_data), mimetype='application/json'
json.dumps(response_data), content_type='application/json'
)

def authorization_code(self, request, data, client):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Django>=1.4
shortuuid>=0.3
shortuuid>=0.4
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'Framework :: Django',
],
install_requires=[
"shortuuid>=0.3"
"shortuuid>=0.4"
],
include_package_data=True,
zip_safe=False,
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DJ_VERSION=$(django-admin.py --version)
# exit if fail
[[ "$?" -ne "0" ]] && exit;

IS_16=$(echo $DJ_VERSION | grep "1.6")
IS_16=$(echo $DJ_VERSION | grep -E "1\.6|1\.7|1\.8|dev")

# if django version is not 1.6 (non-0 exit) we have to pass different
# app names to test runner
Expand Down
14 changes: 14 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Django settings for example project.
import os
from django import VERSION as DJANGO_VERSION

DEBUG = True
TEMPLATE_DEBUG = DEBUG
Expand Down Expand Up @@ -60,3 +61,16 @@
'provider.oauth2',
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

# Use DiscoverRunner on Django 1.7 and above
if DJANGO_VERSION[0] == 1 and DJANGO_VERSION[1] >= 7:
TEST_RUNNER = 'django.test.runner.DiscoverRunner'

7 changes: 1 addition & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
downloadcache = {toxworkdir}/cache/
envlist = py2.7-django.dev,py2.7-django1.6,py2.7-django1.5,py2.7-django1.4,py2.6-django.dev,py2.6-django1.6,py2.6-django1.5,py2.6-django1.4
envlist = py2.7-django.dev,py2.7-django1.6,py2.7-django1.5,py2.7-django1.4,py2.6-django1.6,py2.6-django1.5,py2.6-django1.4

[testenv]
setenv =
Expand Down Expand Up @@ -29,11 +29,6 @@ basepython = python2.7
deps = django>=1.4,<1.5
{[testenv]deps}

[testenv:py2.6-django.dev]
basepython = python2.6
deps = https://github.com/django/django/zipball/master
{[testenv]deps}

[testenv:py2.6-django1.6]
basepython = python2.6
deps = django>=1.6,<1.7
Expand Down