Skip to content

Commit

Permalink
Move all urls into tests/urls.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
mblayman committed Aug 28, 2016
1 parent fd2bfbb commit 6a8fc52
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 57 deletions.
39 changes: 1 addition & 38 deletions tests/test_authentication.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import unittest

from django.http import HttpResponse
from django.test import TestCase
from django.conf.urls import url

from rest_framework import permissions, status
try:
from rest_framework_oauth.authentication import OAuth2Authentication
except ImportError:
try:
from rest_framework.authentication import OAuth2Authentication
except ImportError:
OAuth2Authentication = None
from rest_framework import status
try:
try:
from rest_framework_oauth.compat import oauth2_provider
Expand All @@ -30,12 +20,10 @@
oauth2_provider = None

from rest_framework.test import APIRequestFactory, APIClient
from rest_framework.views import APIView

from rest_framework_jwt import utils
from rest_framework_jwt.compat import get_user_model
from rest_framework_jwt.settings import api_settings, DEFAULTS
from rest_framework_jwt.authentication import JSONWebTokenAuthentication

User = get_user_model()

Expand All @@ -44,33 +32,8 @@
factory = APIRequestFactory()


class MockView(APIView):
permission_classes = (permissions.IsAuthenticated,)

def get(self, request):
return HttpResponse({'a': 1, 'b': 2, 'c': 3})

def post(self, request):
return HttpResponse({'a': 1, 'b': 2, 'c': 3})


urlpatterns = [
url(r'^jwt/$', MockView.as_view(
authentication_classes=[JSONWebTokenAuthentication])),

url(r'^jwt-oauth2/$', MockView.as_view(
authentication_classes=[
JSONWebTokenAuthentication, OAuth2Authentication])),

url(r'^oauth2-jwt/$', MockView.as_view(
authentication_classes=[
OAuth2Authentication, JSONWebTokenAuthentication])),
]


class JSONWebTokenAuthenticationTests(TestCase):
"""JSON Web Token Authentication"""
urls = 'tests.test_authentication'

def setUp(self):
self.csrf_client = APIClient(enforce_csrf_checks=True)
Expand Down
18 changes: 3 additions & 15 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,28 @@
from datetime import datetime, timedelta
import time

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
from django import get_version
from django.test import TestCase
from django.test.utils import override_settings
from django.conf.urls import url
from rest_framework import status
from rest_framework.test import APIClient

from rest_framework_jwt import utils, views
from rest_framework_jwt import utils
from rest_framework_jwt.compat import get_user_model
from rest_framework_jwt.settings import api_settings, DEFAULTS

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa

from . import utils as test_utils

User = get_user_model()

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

urlpatterns = [
url(r'^auth-token/$', views.obtain_jwt_token),
url(r'^auth-token-refresh/$', views.refresh_jwt_token),
url(r'^auth-token-verify/$', views.verify_jwt_token),
]

orig_datetime = datetime


class BaseTestCase(TestCase):
urls = 'tests.test_views'

def setUp(self):
self.email = 'jpueblo@example.com'
Expand Down Expand Up @@ -67,7 +58,6 @@ def test_jwt_login_custom_response_json(self):

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(decoded_payload['username'], self.username)
self.assertEqual(response.data['user'], self.username)

def tearDown(self):
api_settings.JWT_RESPONSE_PAYLOAD_HANDLER =\
Expand Down Expand Up @@ -164,7 +154,6 @@ def test_jwt_login_using_zero(self):
@override_settings(AUTH_USER_MODEL='tests.CustomUser')
class CustomUserObtainJSONWebTokenTests(TestCase):
"""JSON Web Token Authentication"""
urls = 'tests.test_views'

def setUp(self):
from .models import CustomUser
Expand Down Expand Up @@ -209,7 +198,6 @@ def test_jwt_login_json_bad_creds(self):
@override_settings(AUTH_USER_MODEL='tests.CustomUserUUID')
class CustomUserUUIDObtainJSONWebTokenTests(TestCase):
"""JSON Web Token Authentication"""
urls = 'tests.test_views'

def setUp(self):
from .models import CustomUserUUID
Expand Down
44 changes: 40 additions & 4 deletions tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
"""
Blank URLConf just to keep the test suite happy
"""
urlpatterns = []
from django.conf.urls import url
from django.http import HttpResponse
from rest_framework import permissions
from rest_framework.views import APIView
try:
from rest_framework_oauth.authentication import OAuth2Authentication
except ImportError:
try:
from rest_framework.authentication import OAuth2Authentication
except ImportError:
OAuth2Authentication = None

from rest_framework_jwt import views
from rest_framework_jwt.authentication import JSONWebTokenAuthentication


class MockView(APIView):
permission_classes = (permissions.IsAuthenticated,)

def get(self, request):
return HttpResponse({'a': 1, 'b': 2, 'c': 3})

def post(self, request):
return HttpResponse({'a': 1, 'b': 2, 'c': 3})


urlpatterns = [
url(r'^auth-token/$', views.obtain_jwt_token),
url(r'^auth-token-refresh/$', views.refresh_jwt_token),
url(r'^auth-token-verify/$', views.verify_jwt_token),

url(r'^jwt/$', MockView.as_view(
authentication_classes=[JSONWebTokenAuthentication])),
url(r'^jwt-oauth2/$', MockView.as_view(
authentication_classes=[
JSONWebTokenAuthentication, OAuth2Authentication])),
url(r'^oauth2-jwt/$', MockView.as_view(
authentication_classes=[
OAuth2Authentication, JSONWebTokenAuthentication])),
]

0 comments on commit 6a8fc52

Please sign in to comment.