mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-04-25 11:33:43 +03:00
Merge pull request #5567 from rpkilby/importable
Add rest_framework.compat import test
This commit is contained in:
commit
71a512b2d9
|
@ -11,7 +11,6 @@ import inspect
|
||||||
import django
|
import django
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth import views
|
|
||||||
from django.core.exceptions import ImproperlyConfigured, ValidationError
|
from django.core.exceptions import ImproperlyConfigured, ValidationError
|
||||||
from django.core.validators import \
|
from django.core.validators import \
|
||||||
MaxLengthValidator as DjangoMaxLengthValidator
|
MaxLengthValidator as DjangoMaxLengthValidator
|
||||||
|
@ -334,11 +333,3 @@ def authenticate(request=None, **credentials):
|
||||||
else:
|
else:
|
||||||
return authenticate(request=request, **credentials)
|
return authenticate(request=request, **credentials)
|
||||||
|
|
||||||
if django.VERSION < (1, 11):
|
|
||||||
login = views.login
|
|
||||||
login_kwargs = {'template_name': 'rest_framework/login.html'}
|
|
||||||
logout = views.logout
|
|
||||||
else:
|
|
||||||
login = views.LoginView.as_view(template_name='rest_framework/login.html')
|
|
||||||
login_kwargs = {}
|
|
||||||
logout = views.LogoutView.as_view()
|
|
||||||
|
|
|
@ -14,9 +14,19 @@ and you should make sure your authentication settings include `SessionAuthentica
|
||||||
"""
|
"""
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import django
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
from django.contrib.auth import views
|
||||||
|
|
||||||
|
if django.VERSION < (1, 11):
|
||||||
|
login = views.login
|
||||||
|
login_kwargs = {'template_name': 'rest_framework/login.html'}
|
||||||
|
logout = views.logout
|
||||||
|
else:
|
||||||
|
login = views.LoginView.as_view(template_name='rest_framework/login.html')
|
||||||
|
login_kwargs = {}
|
||||||
|
logout = views.LogoutView.as_view()
|
||||||
|
|
||||||
from rest_framework.compat import login, login_kwargs, logout
|
|
||||||
|
|
||||||
app_name = 'rest_framework'
|
app_name = 'rest_framework'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
|
|
@ -41,6 +41,7 @@ def pytest_configure():
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'rest_framework.authtoken',
|
'rest_framework.authtoken',
|
||||||
|
'tests.importable',
|
||||||
'tests',
|
'tests',
|
||||||
),
|
),
|
||||||
PASSWORD_HASHERS=(
|
PASSWORD_HASHERS=(
|
||||||
|
|
2
tests/importable/__init__.py
Normal file
2
tests/importable/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
from rest_framework import compat # noqa
|
13
tests/importable/test_installed.py
Normal file
13
tests/importable/test_installed.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from tests import importable
|
||||||
|
|
||||||
|
|
||||||
|
def test_installed():
|
||||||
|
# ensure that apps can freely import rest_framework.compat
|
||||||
|
assert 'tests.importable' in settings.INSTALLED_APPS
|
||||||
|
|
||||||
|
|
||||||
|
def test_imported():
|
||||||
|
# ensure that the __init__ hasn't been mucked with
|
||||||
|
assert hasattr(importable, 'compat')
|
Loading…
Reference in New Issue
Block a user