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

Commit 6a8fc52

Browse files
committed
Move all urls into tests/urls.py.
1 parent fd2bfbb commit 6a8fc52

File tree

3 files changed

+44
-57
lines changed

3 files changed

+44
-57
lines changed

tests/test_authentication.py

Lines changed: 1 addition & 38 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 url
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,33 +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 = [
58-
url(r'^jwt/$', MockView.as_view(
59-
authentication_classes=[JSONWebTokenAuthentication])),
60-
61-
url(r'^jwt-oauth2/$', MockView.as_view(
62-
authentication_classes=[
63-
JSONWebTokenAuthentication, OAuth2Authentication])),
64-
65-
url(r'^oauth2-jwt/$', MockView.as_view(
66-
authentication_classes=[
67-
OAuth2Authentication, JSONWebTokenAuthentication])),
68-
]
69-
70-
7135
class JSONWebTokenAuthenticationTests(TestCase):
7236
"""JSON Web Token Authentication"""
73-
urls = 'tests.test_authentication'
7437

7538
def setUp(self):
7639
self.csrf_client = APIClient(enforce_csrf_checks=True)

tests/test_views.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +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 url
1011
from rest_framework import status
1112
from rest_framework.test import APIClient
1213

13-
from rest_framework_jwt import utils, views
14+
from rest_framework_jwt import utils
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 = [
27-
url(r'^auth-token/$', views.obtain_jwt_token),
28-
url(r'^auth-token-refresh/$', views.refresh_jwt_token),
29-
url(r'^auth-token-verify/$', views.verify_jwt_token),
30-
]
31-
3224
orig_datetime = datetime
3325

3426

3527
class BaseTestCase(TestCase):
36-
urls = 'tests.test_views'
3728

3829
def setUp(self):
3930
self.email = '[email protected]'
@@ -67,7 +58,6 @@ def test_jwt_login_custom_response_json(self):
6758

6859
self.assertEqual(response.status_code, status.HTTP_200_OK)
6960
self.assertEqual(decoded_payload['username'], self.username)
70-
self.assertEqual(response.data['user'], self.username)
7161

7262
def tearDown(self):
7363
api_settings.JWT_RESPONSE_PAYLOAD_HANDLER =\
@@ -164,7 +154,6 @@ def test_jwt_login_using_zero(self):
164154
@override_settings(AUTH_USER_MODEL='tests.CustomUser')
165155
class CustomUserObtainJSONWebTokenTests(TestCase):
166156
"""JSON Web Token Authentication"""
167-
urls = 'tests.test_views'
168157

169158
def setUp(self):
170159
from .models import CustomUser
@@ -209,7 +198,6 @@ def test_jwt_login_json_bad_creds(self):
209198
@override_settings(AUTH_USER_MODEL='tests.CustomUserUUID')
210199
class CustomUserUUIDObtainJSONWebTokenTests(TestCase):
211200
"""JSON Web Token Authentication"""
212-
urls = 'tests.test_views'
213201

214202
def setUp(self):
215203
from .models import CustomUserUUID

tests/urls.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
1-
"""
2-
Blank URLConf just to keep the test suite happy
3-
"""
4-
urlpatterns = []
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
12+
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+
]

0 commit comments

Comments
 (0)