From ca341ef70576967c6ebe243a079bbd31d1631a9e Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Mon, 6 Nov 2017 09:56:57 -0500 Subject: [PATCH 1/2] Add compat import test --- tests/conftest.py | 1 + tests/importable/__init__.py | 2 ++ tests/importable/test_installed.py | 13 +++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 tests/importable/__init__.py create mode 100644 tests/importable/test_installed.py diff --git a/tests/conftest.py b/tests/conftest.py index 0e5c55ffea..9906935d7c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -41,6 +41,7 @@ def pytest_configure(): 'django.contrib.staticfiles', 'rest_framework', 'rest_framework.authtoken', + 'tests.importable', 'tests', ), PASSWORD_HASHERS=( diff --git a/tests/importable/__init__.py b/tests/importable/__init__.py new file mode 100644 index 0000000000..19aaf6f90a --- /dev/null +++ b/tests/importable/__init__.py @@ -0,0 +1,2 @@ + +from rest_framework import compat # noqa diff --git a/tests/importable/test_installed.py b/tests/importable/test_installed.py new file mode 100644 index 0000000000..5998c9cbc7 --- /dev/null +++ b/tests/importable/test_installed.py @@ -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') From d6a8e020219a5c1a543b2b1c68de58ac03386b1d Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Mon, 6 Nov 2017 15:06:47 +0100 Subject: [PATCH 2/2] Move django.contrib.auth import out of compat. Fixed some regressions where compat was imported during app loading and led to importing django.contrib.auth.models which ended in a `AppRegistryNotReady` exception. --- rest_framework/compat.py | 9 --------- rest_framework/urls.py | 12 +++++++++++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index ce821402e2..456c8b20d1 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -11,7 +11,6 @@ import django from django.apps import apps from django.conf import settings -from django.contrib.auth import views from django.core.exceptions import ImproperlyConfigured, ValidationError from django.core.validators import \ MaxLengthValidator as DjangoMaxLengthValidator @@ -334,11 +333,3 @@ def authenticate(request=None, **credentials): else: 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() diff --git a/rest_framework/urls.py b/rest_framework/urls.py index 60107d4d24..10cc5def0c 100644 --- a/rest_framework/urls.py +++ b/rest_framework/urls.py @@ -14,9 +14,19 @@ """ from __future__ import unicode_literals +import django 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' urlpatterns = [ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy