|
8 | 8 | from django.conf import settings
|
9 | 9 | from django.conf.urls import include, url
|
10 | 10 | from django.contrib.auth.models import User
|
11 |
| -from django.db import models |
12 | 11 | from django.http import HttpResponse
|
13 | 12 | from django.test import TestCase, override_settings
|
14 | 13 | from django.utils import six
|
|
26 | 25 | from rest_framework.test import APIClient, APIRequestFactory
|
27 | 26 | from rest_framework.views import APIView
|
28 | 27 |
|
29 |
| -factory = APIRequestFactory() |
30 |
| - |
| 28 | +from .models import CustomToken |
31 | 29 |
|
32 |
| -class CustomToken(models.Model): |
33 |
| - key = models.CharField(max_length=40, primary_key=True) |
34 |
| - user = models.OneToOneField(User, on_delete=models.CASCADE) |
| 30 | +factory = APIRequestFactory() |
35 | 31 |
|
36 | 32 |
|
37 | 33 | class CustomTokenAuthentication(TokenAuthentication):
|
@@ -87,7 +83,7 @@ def put(self, request):
|
87 | 83 | ]
|
88 | 84 |
|
89 | 85 |
|
90 |
| -@override_settings(ROOT_URLCONF='tests.test_authentication') |
| 86 | +@override_settings(ROOT_URLCONF=__name__) |
91 | 87 | class BasicAuthTests(TestCase):
|
92 | 88 | """Basic authentication"""
|
93 | 89 | def setUp(self):
|
@@ -169,7 +165,7 @@ def test_fail_post_if_credentials_contain_spaces(self):
|
169 | 165 | assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
170 | 166 |
|
171 | 167 |
|
172 |
| -@override_settings(ROOT_URLCONF='tests.test_authentication') |
| 168 | +@override_settings(ROOT_URLCONF=__name__) |
173 | 169 | class SessionAuthTests(TestCase):
|
174 | 170 | """User session authentication"""
|
175 | 171 | def setUp(self):
|
@@ -370,7 +366,7 @@ def test_post_json_failing_token_auth(self):
|
370 | 366 | assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
371 | 367 |
|
372 | 368 |
|
373 |
| -@override_settings(ROOT_URLCONF='tests.test_authentication') |
| 369 | +@override_settings(ROOT_URLCONF=__name__) |
374 | 370 | class TokenAuthTests(BaseTokenAuthTests, TestCase):
|
375 | 371 | model = Token
|
376 | 372 | path = '/token/'
|
@@ -429,13 +425,13 @@ def test_token_login_form(self):
|
429 | 425 | assert response.data['token'] == self.key
|
430 | 426 |
|
431 | 427 |
|
432 |
| -@override_settings(ROOT_URLCONF='tests.test_authentication') |
| 428 | +@override_settings(ROOT_URLCONF=__name__) |
433 | 429 | class CustomTokenAuthTests(BaseTokenAuthTests, TestCase):
|
434 | 430 | model = CustomToken
|
435 | 431 | path = '/customtoken/'
|
436 | 432 |
|
437 | 433 |
|
438 |
| -@override_settings(ROOT_URLCONF='tests.test_authentication') |
| 434 | +@override_settings(ROOT_URLCONF=__name__) |
439 | 435 | class CustomKeywordTokenAuthTests(BaseTokenAuthTests, TestCase):
|
440 | 436 | model = Token
|
441 | 437 | path = '/customkeywordtoken/'
|
@@ -549,7 +545,7 @@ class MockUser(object):
|
549 | 545 | authentication.authenticate = old_authenticate
|
550 | 546 |
|
551 | 547 |
|
552 |
| -@override_settings(ROOT_URLCONF='tests.test_authentication', |
| 548 | +@override_settings(ROOT_URLCONF=__name__, |
553 | 549 | AUTHENTICATION_BACKENDS=('django.contrib.auth.backends.RemoteUserBackend',))
|
554 | 550 | class RemoteUserAuthenticationUnitTests(TestCase):
|
555 | 551 | def setUp(self):
|
|
0 commit comments