mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-28 20:44:03 +03:00
Add migration for CustomToken test model.
Move authentication tests to sub-app to enable this.
This commit is contained in:
parent
cb4cbb61f2
commit
481ae69df3
0
tests/authentication/__init__.py
Normal file
0
tests/authentication/__init__.py
Normal file
24
tests/authentication/migrations/0001_initial.py
Normal file
24
tests/authentication/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CustomToken',
|
||||
fields=[
|
||||
('key', models.CharField(max_length=40, primary_key=True, serialize=False)),
|
||||
('user', models.OneToOneField(on_delete=models.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
0
tests/authentication/migrations/__init__.py
Normal file
0
tests/authentication/migrations/__init__.py
Normal file
10
tests/authentication/models.py
Normal file
10
tests/authentication/models.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
# coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
|
||||
|
||||
class CustomToken(models.Model):
|
||||
key = models.CharField(max_length=40, primary_key=True)
|
||||
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
|
@ -8,7 +8,6 @@ import pytest
|
|||
from django.conf import settings
|
||||
from django.conf.urls import include, url
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.http import HttpResponse
|
||||
from django.test import TestCase, override_settings
|
||||
from django.utils import six
|
||||
|
@ -26,14 +25,11 @@ from rest_framework.response import Response
|
|||
from rest_framework.test import APIClient, APIRequestFactory
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from .models import CustomToken
|
||||
|
||||
factory = APIRequestFactory()
|
||||
|
||||
|
||||
class CustomToken(models.Model):
|
||||
key = models.CharField(max_length=40, primary_key=True)
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
|
||||
|
||||
class CustomTokenAuthentication(TokenAuthentication):
|
||||
model = CustomToken
|
||||
|
||||
|
@ -87,7 +83,7 @@ urlpatterns = [
|
|||
]
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='tests.test_authentication')
|
||||
@override_settings(ROOT_URLCONF=__name__)
|
||||
class BasicAuthTests(TestCase):
|
||||
"""Basic authentication"""
|
||||
def setUp(self):
|
||||
|
@ -169,7 +165,7 @@ class BasicAuthTests(TestCase):
|
|||
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='tests.test_authentication')
|
||||
@override_settings(ROOT_URLCONF=__name__)
|
||||
class SessionAuthTests(TestCase):
|
||||
"""User session authentication"""
|
||||
def setUp(self):
|
||||
|
@ -370,7 +366,7 @@ class BaseTokenAuthTests(object):
|
|||
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='tests.test_authentication')
|
||||
@override_settings(ROOT_URLCONF=__name__)
|
||||
class TokenAuthTests(BaseTokenAuthTests, TestCase):
|
||||
model = Token
|
||||
path = '/token/'
|
||||
|
@ -429,13 +425,13 @@ class TokenAuthTests(BaseTokenAuthTests, TestCase):
|
|||
assert response.data['token'] == self.key
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='tests.test_authentication')
|
||||
@override_settings(ROOT_URLCONF=__name__)
|
||||
class CustomTokenAuthTests(BaseTokenAuthTests, TestCase):
|
||||
model = CustomToken
|
||||
path = '/customtoken/'
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='tests.test_authentication')
|
||||
@override_settings(ROOT_URLCONF=__name__)
|
||||
class CustomKeywordTokenAuthTests(BaseTokenAuthTests, TestCase):
|
||||
model = Token
|
||||
path = '/customkeywordtoken/'
|
||||
|
@ -549,7 +545,7 @@ class BasicAuthenticationUnitTests(TestCase):
|
|||
authentication.authenticate = old_authenticate
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='tests.test_authentication',
|
||||
@override_settings(ROOT_URLCONF=__name__,
|
||||
AUTHENTICATION_BACKENDS=('django.contrib.auth.backends.RemoteUserBackend',))
|
||||
class RemoteUserAuthenticationUnitTests(TestCase):
|
||||
def setUp(self):
|
|
@ -56,6 +56,7 @@ def pytest_configure(config):
|
|||
'django.contrib.staticfiles',
|
||||
'rest_framework',
|
||||
'rest_framework.authtoken',
|
||||
'tests.authentication',
|
||||
'tests.importable',
|
||||
'tests',
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue
Block a user