|
8 | 8 | from django.contrib.auth.models import User
|
9 | 9 | from django.db import models
|
10 | 10 | from django.http import HttpResponse
|
11 |
| -from django.test import TestCase |
| 11 | +from django.test import TestCase, override_settings |
12 | 12 | from django.utils import six
|
13 | 13 |
|
14 | 14 | from rest_framework import (
|
|
19 | 19 | TokenAuthentication
|
20 | 20 | )
|
21 | 21 | from rest_framework.authtoken.models import Token
|
| 22 | +from rest_framework.authtoken.views import obtain_auth_token |
22 | 23 | from rest_framework.response import Response
|
23 | 24 | from rest_framework.test import APIClient, APIRequestFactory
|
24 | 25 | from rest_framework.views import APIView
|
@@ -75,15 +76,14 @@ def put(self, request):
|
75 | 76 | authentication_classes=[CustomKeywordTokenAuthentication]
|
76 | 77 | )
|
77 | 78 | ),
|
78 |
| - url(r'^auth-token/$', 'rest_framework.authtoken.views.obtain_auth_token'), |
| 79 | + url(r'^auth-token/$', obtain_auth_token), |
79 | 80 | url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')),
|
80 | 81 | ]
|
81 | 82 |
|
82 | 83 |
|
| 84 | +@override_settings(ROOT_URLCONF='tests.test_authentication') |
83 | 85 | class BasicAuthTests(TestCase):
|
84 | 86 | """Basic authentication"""
|
85 |
| - urls = 'tests.test_authentication' |
86 |
| - |
87 | 87 | def setUp(self):
|
88 | 88 | self.csrf_client = APIClient(enforce_csrf_checks=True)
|
89 | 89 | self.username = 'john'
|
@@ -151,10 +151,9 @@ def test_post_json_failing_basic_auth(self):
|
151 | 151 | self.assertEqual(response['WWW-Authenticate'], 'Basic realm="api"')
|
152 | 152 |
|
153 | 153 |
|
| 154 | +@override_settings(ROOT_URLCONF='tests.test_authentication') |
154 | 155 | class SessionAuthTests(TestCase):
|
155 | 156 | """User session authentication"""
|
156 |
| - urls = 'tests.test_authentication' |
157 |
| - |
158 | 157 | def setUp(self):
|
159 | 158 | self.csrf_client = APIClient(enforce_csrf_checks=True)
|
160 | 159 | self.non_csrf_client = APIClient(enforce_csrf_checks=False)
|
@@ -223,7 +222,6 @@ def test_post_form_session_auth_failing(self):
|
223 | 222 |
|
224 | 223 | class BaseTokenAuthTests(object):
|
225 | 224 | """Token authentication"""
|
226 |
| - urls = 'tests.test_authentication' |
227 | 225 | model = None
|
228 | 226 | path = None
|
229 | 227 | header_prefix = 'Token '
|
@@ -311,6 +309,7 @@ def test_post_json_failing_token_auth(self):
|
311 | 309 | self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
312 | 310 |
|
313 | 311 |
|
| 312 | +@override_settings(ROOT_URLCONF='tests.test_authentication') |
314 | 313 | class TokenAuthTests(BaseTokenAuthTests, TestCase):
|
315 | 314 | model = Token
|
316 | 315 | path = '/token/'
|
@@ -367,11 +366,13 @@ def test_token_login_form(self):
|
367 | 366 | self.assertEqual(response.data['token'], self.key)
|
368 | 367 |
|
369 | 368 |
|
| 369 | +@override_settings(ROOT_URLCONF='tests.test_authentication') |
370 | 370 | class CustomTokenAuthTests(BaseTokenAuthTests, TestCase):
|
371 | 371 | model = CustomToken
|
372 | 372 | path = '/customtoken/'
|
373 | 373 |
|
374 | 374 |
|
| 375 | +@override_settings(ROOT_URLCONF='tests.test_authentication') |
375 | 376 | class CustomKeywordTokenAuthTests(BaseTokenAuthTests, TestCase):
|
376 | 377 | model = Token
|
377 | 378 | path = '/customkeywordtoken/'
|
|
0 commit comments