Skip to content

Commit 71a512b

Browse files
authored
Merge pull request #5567 from rpkilby/importable
Add rest_framework.compat import test
2 parents 7d0fa02 + d6a8e02 commit 71a512b

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

rest_framework/compat.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import django
1212
from django.apps import apps
1313
from django.conf import settings
14-
from django.contrib.auth import views
1514
from django.core.exceptions import ImproperlyConfigured, ValidationError
1615
from django.core.validators import \
1716
MaxLengthValidator as DjangoMaxLengthValidator
@@ -334,11 +333,3 @@ def authenticate(request=None, **credentials):
334333
else:
335334
return authenticate(request=request, **credentials)
336335

337-
if django.VERSION < (1, 11):
338-
login = views.login
339-
login_kwargs = {'template_name': 'rest_framework/login.html'}
340-
logout = views.logout
341-
else:
342-
login = views.LoginView.as_view(template_name='rest_framework/login.html')
343-
login_kwargs = {}
344-
logout = views.LogoutView.as_view()

rest_framework/urls.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,19 @@
1414
"""
1515
from __future__ import unicode_literals
1616

17+
import django
1718
from django.conf.urls import url
19+
from django.contrib.auth import views
20+
21+
if django.VERSION < (1, 11):
22+
login = views.login
23+
login_kwargs = {'template_name': 'rest_framework/login.html'}
24+
logout = views.logout
25+
else:
26+
login = views.LoginView.as_view(template_name='rest_framework/login.html')
27+
login_kwargs = {}
28+
logout = views.LogoutView.as_view()
1829

19-
from rest_framework.compat import login, login_kwargs, logout
2030

2131
app_name = 'rest_framework'
2232
urlpatterns = [

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def pytest_configure():
4141
'django.contrib.staticfiles',
4242
'rest_framework',
4343
'rest_framework.authtoken',
44+
'tests.importable',
4445
'tests',
4546
),
4647
PASSWORD_HASHERS=(

tests/importable/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
from rest_framework import compat # noqa

tests/importable/test_installed.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
from django.conf import settings
3+
from tests import importable
4+
5+
6+
def test_installed():
7+
# ensure that apps can freely import rest_framework.compat
8+
assert 'tests.importable' in settings.INSTALLED_APPS
9+
10+
11+
def test_imported():
12+
# ensure that the __init__ hasn't been mucked with
13+
assert hasattr(importable, 'compat')

0 commit comments

Comments
 (0)