From 601e1ad44c18b9665c2ec6886438299de72d3761 Mon Sep 17 00:00:00 2001 From: Rob Cresswell Date: Tue, 18 Jul 2017 12:06:58 +0100 Subject: [PATCH] Fix Django 1.11 Compatibility Implements: blueprint dj111 Change-Id: Idfaef58b2a069006f6d792e43041dd136097c413 Co-Authored-By: Adrian Turjak --- openstack_auth/tests/settings.py | 2 ++ openstack_auth/tests/tests.py | 6 ++++-- openstack_auth/utils.py | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/openstack_auth/tests/settings.py b/openstack_auth/tests/settings.py index 9590d51c..1e750a27 100644 --- a/openstack_auth/tests/settings.py +++ b/openstack_auth/tests/settings.py @@ -13,6 +13,8 @@ import os +ALLOWED_HOSTS = ['*'] + DATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3'}} INSTALLED_APPS = [ diff --git a/openstack_auth/tests/tests.py b/openstack_auth/tests/tests.py index 80e5a88e..0678b59b 100644 --- a/openstack_auth/tests/tests.py +++ b/openstack_auth/tests/tests.py @@ -1099,7 +1099,8 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin, url = reverse('login') response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertContains(response, 'name="domain" type="text"') + self.assertContains(response, 'id="id_domain"') + self.assertContains(response, 'name="domain"') def test_login_form_multidomain_dropdown(self): override = self.settings(OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT=True, @@ -1113,7 +1114,8 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin, url = reverse('login') response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertContains(response, 'select id="id_domain" name="domain"') + self.assertContains(response, 'id="id_domain"') + self.assertContains(response, 'name="domain"') self.assertContains(response, 'option value="Default"') settings.OPENSTACK_KEYSTONE_DOMAIN_DROPDOWN = False diff --git a/openstack_auth/utils.py b/openstack_auth/utils.py index 3d49b7a8..d38d5133 100644 --- a/openstack_auth/utils.py +++ b/openstack_auth/utils.py @@ -17,7 +17,6 @@ import re from django.conf import settings from django.contrib import auth -from django.contrib.auth import middleware from django.contrib.auth import models from django.utils import timezone from keystoneauth1.identity import v2 as v2_auth @@ -62,6 +61,10 @@ def get_user(request): def patch_middleware_get_user(): + # NOTE(adriant): We can't import middleware until our customer user model + # is actually registered, otherwise a call to get_user_model within the + # middleware module will fail. + from django.contrib.auth import middleware middleware.get_user = middleware_get_user auth.get_user = get_user