Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Commit 4e99990

Browse files
authored
Merge pull request #256 from mblayman/django-1.10
Add support for Django 1.10 and Django REST Framework 3.4
2 parents 29e839d + 9f73965 commit 4e99990

File tree

8 files changed

+88
-70
lines changed

8 files changed

+88
-70
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,33 @@ env:
1010
- TOX_ENV=py27-django1.8-drf3.1
1111
- TOX_ENV=py27-django1.8-drf3.2
1212
- TOX_ENV=py27-django1.8-drf3.3
13+
- TOX_ENV=py27-django1.8-drf3.4
1314

1415
- TOX_ENV=py27-django1.9-drf3.1
1516
- TOX_ENV=py27-django1.9-drf3.2
1617
- TOX_ENV=py27-django1.9-drf3.3
18+
- TOX_ENV=py27-django1.9-drf3.4
19+
20+
- TOX_ENV=py27-django1.10-drf3.4
1721

1822
- TOX_ENV=py33-django1.8-drf3.0
1923
- TOX_ENV=py33-django1.8-drf3.1
2024
- TOX_ENV=py33-django1.8-drf3.2
2125
- TOX_ENV=py33-django1.8-drf3.3
26+
- TOX_ENV=py33-django1.8-drf3.4
2227

2328
- TOX_ENV=py34-django1.8-drf3.0
2429
- TOX_ENV=py34-django1.8-drf3.1
2530
- TOX_ENV=py34-django1.8-drf3.2
2631
- TOX_ENV=py34-django1.8-drf3.3
32+
- TOX_ENV=py34-django1.8-drf3.4
2733

2834
- TOX_ENV=py34-django1.9-drf3.1
2935
- TOX_ENV=py34-django1.9-drf3.2
3036
- TOX_ENV=py34-django1.9-drf3.3
37+
- TOX_ENV=py34-django1.9-drf3.4
38+
39+
- TOX_ENV=py34-django1.10-drf3.4
3140

3241
matrix:
3342
fast_finish: true

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Requirements
2323
------------
2424

2525
- Python (2.7, 3.3, 3.4)
26-
- Django (1.8, 1.9)
27-
- Django REST Framework (3.0, 3.1, 3.2, 3.3)
26+
- Django (1.8, 1.9, 1.10)
27+
- Django REST Framework (3.0, 3.1, 3.2, 3.3, 3.4)
2828

2929
Installation
3030
------------

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ If you want to know more about JWT, check out the following resources:
2828
## Requirements
2929

3030
- Python (2.7, 3.3, 3.4)
31-
- Django (1.8, 1.9)
32-
- Django REST Framework (3.0, 3.1, 3.2, 3.3)
31+
- Django (1.8, 1.9, 1.10)
32+
- Django REST Framework (3.0, 3.1, 3.2, 3.3, 3.4)
3333

3434
## Security
3535

tests/test_authentication.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
import unittest
22

3-
from django.http import HttpResponse
43
from django.test import TestCase
5-
from django.conf.urls import patterns
6-
7-
from rest_framework import permissions, status
8-
try:
9-
from rest_framework_oauth.authentication import OAuth2Authentication
10-
except ImportError:
11-
try:
12-
from rest_framework.authentication import OAuth2Authentication
13-
except ImportError:
14-
OAuth2Authentication = None
4+
from rest_framework import status
155
try:
166
try:
177
from rest_framework_oauth.compat import oauth2_provider
@@ -30,12 +20,10 @@
3020
oauth2_provider = None
3121

3222
from rest_framework.test import APIRequestFactory, APIClient
33-
from rest_framework.views import APIView
3423

3524
from rest_framework_jwt import utils
3625
from rest_framework_jwt.compat import get_user_model
3726
from rest_framework_jwt.settings import api_settings, DEFAULTS
38-
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
3927

4028
User = get_user_model()
4129

@@ -44,34 +32,8 @@
4432
factory = APIRequestFactory()
4533

4634

47-
class MockView(APIView):
48-
permission_classes = (permissions.IsAuthenticated,)
49-
50-
def get(self, request):
51-
return HttpResponse({'a': 1, 'b': 2, 'c': 3})
52-
53-
def post(self, request):
54-
return HttpResponse({'a': 1, 'b': 2, 'c': 3})
55-
56-
57-
urlpatterns = patterns(
58-
'',
59-
(r'^jwt/$', MockView.as_view(
60-
authentication_classes=[JSONWebTokenAuthentication])),
61-
62-
(r'^jwt-oauth2/$', MockView.as_view(
63-
authentication_classes=[
64-
JSONWebTokenAuthentication, OAuth2Authentication])),
65-
66-
(r'^oauth2-jwt/$', MockView.as_view(
67-
authentication_classes=[
68-
OAuth2Authentication, JSONWebTokenAuthentication])),
69-
)
70-
71-
7235
class JSONWebTokenAuthenticationTests(TestCase):
7336
"""JSON Web Token Authentication"""
74-
urls = 'tests.test_authentication'
7537

7638
def setUp(self):
7739
self.csrf_client = APIClient(enforce_csrf_checks=True)

tests/test_serializers.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import unittest
22
from distutils.version import StrictVersion
33

4-
import rest_framework
4+
import django
55
from django.test import TestCase
6+
from django.test.utils import override_settings
7+
import rest_framework
68

79
from rest_framework_jwt.compat import get_user_model
810
from rest_framework_jwt.serializers import JSONWebTokenSerializer
@@ -68,6 +70,9 @@ def test_invalid_credentials(self):
6870
self.assertFalse(is_valid)
6971
self.assertEqual(serializer.errors, expected_error)
7072

73+
@unittest.skipIf(
74+
django.VERSION[1] >= 10,
75+
reason='The ModelBackend does not permit login when is_active is False.')
7176
def test_disabled_user(self):
7277
self.user.is_active = False
7378
self.user.save()
@@ -82,6 +87,25 @@ def test_disabled_user(self):
8287
self.assertFalse(is_valid)
8388
self.assertEqual(serializer.errors, expected_error)
8489

90+
@unittest.skipUnless(
91+
django.VERSION[1] >= 10,
92+
reason='The AllowAllUsersModelBackend permits login when is_active is False.')
93+
@override_settings(AUTHENTICATION_BACKENDS=[
94+
'django.contrib.auth.backends.AllowAllUsersModelBackend'])
95+
def test_disabled_user_all_users_backend(self):
96+
self.user.is_active = False
97+
self.user.save()
98+
99+
serializer = JSONWebTokenSerializer(data=self.data)
100+
is_valid = serializer.is_valid()
101+
102+
expected_error = {
103+
'non_field_errors': ['User account is disabled.']
104+
}
105+
106+
self.assertFalse(is_valid)
107+
self.assertEqual(serializer.errors, expected_error)
108+
85109
def test_required_fields(self):
86110
serializer = JSONWebTokenSerializer(data={})
87111
is_valid = serializer.is_valid()

tests/test_views.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,28 @@
33
from datetime import datetime, timedelta
44
import time
55

6+
from cryptography.hazmat.backends import default_backend
7+
from cryptography.hazmat.primitives.asymmetric import rsa
68
from django import get_version
79
from django.test import TestCase
810
from django.test.utils import override_settings
9-
from django.conf.urls import patterns
1011
from rest_framework import status
1112
from rest_framework.test import APIClient
1213

13-
from rest_framework_jwt import utils
14+
from rest_framework_jwt import utils, views
1415
from rest_framework_jwt.compat import get_user_model
1516
from rest_framework_jwt.settings import api_settings, DEFAULTS
1617

17-
from cryptography.hazmat.backends import default_backend
18-
from cryptography.hazmat.primitives.asymmetric import rsa
19-
2018
from . import utils as test_utils
2119

2220
User = get_user_model()
2321

2422
NO_CUSTOM_USER_MODEL = 'Custom User Model only supported after Django 1.5'
2523

26-
urlpatterns = patterns(
27-
'',
28-
(r'^auth-token/$', 'rest_framework_jwt.views.obtain_jwt_token'),
29-
(r'^auth-token-refresh/$', 'rest_framework_jwt.views.refresh_jwt_token'),
30-
(r'^auth-token-verify/$', 'rest_framework_jwt.views.verify_jwt_token'),
31-
32-
)
33-
3424
orig_datetime = datetime
3525

3626

3727
class BaseTestCase(TestCase):
38-
urls = 'tests.test_views'
3928

4029
def setUp(self):
4130
self.email = '[email protected]'
@@ -53,7 +42,8 @@ def setUp(self):
5342
class TestCustomResponsePayload(BaseTestCase):
5443

5544
def setUp(self):
56-
api_settings.JWT_RESPONSE_PAYLOAD_HANDLER = test_utils\
45+
self.original_handler = views.jwt_response_payload_handler
46+
views.jwt_response_payload_handler = test_utils\
5747
.jwt_response_payload_handler
5848
return super(TestCustomResponsePayload, self).setUp()
5949

@@ -72,8 +62,7 @@ def test_jwt_login_custom_response_json(self):
7262
self.assertEqual(response.data['user'], self.username)
7363

7464
def tearDown(self):
75-
api_settings.JWT_RESPONSE_PAYLOAD_HANDLER =\
76-
DEFAULTS['JWT_RESPONSE_PAYLOAD_HANDLER']
65+
views.jwt_response_payload_handler = self.original_handler
7766

7867

7968
class ObtainJSONWebTokenTests(BaseTestCase):
@@ -166,7 +155,6 @@ def test_jwt_login_using_zero(self):
166155
@override_settings(AUTH_USER_MODEL='tests.CustomUser')
167156
class CustomUserObtainJSONWebTokenTests(TestCase):
168157
"""JSON Web Token Authentication"""
169-
urls = 'tests.test_views'
170158

171159
def setUp(self):
172160
from .models import CustomUser
@@ -211,7 +199,6 @@ def test_jwt_login_json_bad_creds(self):
211199
@override_settings(AUTH_USER_MODEL='tests.CustomUserUUID')
212200
class CustomUserUUIDObtainJSONWebTokenTests(TestCase):
213201
"""JSON Web Token Authentication"""
214-
urls = 'tests.test_views'
215202

216203
def setUp(self):
217204
from .models import CustomUserUUID

tests/urls.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
1-
"""
2-
Blank URLConf just to keep the test suite happy
3-
"""
4-
from django.conf.urls import patterns
1+
from django.conf.urls import url
2+
from django.http import HttpResponse
3+
from rest_framework import permissions
4+
from rest_framework.views import APIView
5+
try:
6+
from rest_framework_oauth.authentication import OAuth2Authentication
7+
except ImportError:
8+
try:
9+
from rest_framework.authentication import OAuth2Authentication
10+
except ImportError:
11+
OAuth2Authentication = None
512

6-
urlpatterns = patterns('')
13+
from rest_framework_jwt import views
14+
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
15+
16+
17+
class MockView(APIView):
18+
permission_classes = (permissions.IsAuthenticated,)
19+
20+
def get(self, request):
21+
return HttpResponse({'a': 1, 'b': 2, 'c': 3})
22+
23+
def post(self, request):
24+
return HttpResponse({'a': 1, 'b': 2, 'c': 3})
25+
26+
27+
urlpatterns = [
28+
url(r'^auth-token/$', views.obtain_jwt_token),
29+
url(r'^auth-token-refresh/$', views.refresh_jwt_token),
30+
url(r'^auth-token-verify/$', views.verify_jwt_token),
31+
32+
url(r'^jwt/$', MockView.as_view(
33+
authentication_classes=[JSONWebTokenAuthentication])),
34+
url(r'^jwt-oauth2/$', MockView.as_view(
35+
authentication_classes=[
36+
JSONWebTokenAuthentication, OAuth2Authentication])),
37+
url(r'^oauth2-jwt/$', MockView.as_view(
38+
authentication_classes=[
39+
OAuth2Authentication, JSONWebTokenAuthentication])),
40+
]

tox.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
[tox]
22
envlist =
33
py27-{flake8,docs},
4-
{py27,py33,py34}-django{1.8,1.9}-drf{3.0,3.1,3.2,3.3}
4+
{py27,py33,py34}-django{1.8,1.9,1.10}-drf{3.0,3.1,3.2,3.3,3.4}
55

66
[testenv]
7-
commands = ./runtests.py --fast {posargs}
7+
commands = ./runtests.py --fast {posargs} --verbose
88
setenv =
99
PYTHONDONTWRITEBYTECODE=1
1010
deps =
1111
django1.8: Django==1.8.7
1212
django1.9: Django==1.9.0
13+
django1.10: Django==1.10
1314
drf2.4: djangorestframework==2.4.5
1415
drf3.0: djangorestframework==3.0.5
1516
drf3.1: djangorestframework==3.1.3
1617
drf3.2: djangorestframework==3.2.2
1718
drf3.3: djangorestframework==3.3.2
19+
drf3.4: djangorestframework==3.4.6
1820
py27-django{1.8,1.9}-drf{3.1,3.2,3.3}: djangorestframework-oauth==1.0.1
1921
-rrequirements/testing.txt
2022

0 commit comments

Comments
 (0)