Fix the py27dj19 tests

- Wrap the expected_url variable in a django 1.9 condition so that it
  returns as expected.
- Use request.GET/request.POST instead of request.REQUEST
- Remove some conditional code required for old Django versions

This is the first step in getting Horizon to fully support Django 1.9.
It does *not* yet aim to offer full support, which is why the
requirements have not been bumped.

Change-Id: I7f8f3cde92cafdb5c9134baf75fc736cbf35ff6a
Partially-Implements: blueprint drop-dj17
Depends-On: Ia6cbbc281732e9c466edeaa76739122e006a997e
This commit is contained in:
Rob Cresswell 2015-12-10 13:33:50 +00:00
parent 47ce93c09f
commit d8a9ad9fb2
5 changed files with 25 additions and 33 deletions

View File

@ -14,7 +14,6 @@
import collections
import logging
import django
from django.conf import settings
from django.contrib.auth import authenticate # noqa
from django.contrib.auth import forms as django_auth_forms
@ -94,13 +93,8 @@ class Login(django_auth_forms.AuthenticationForm):
msg = ("Websso is enabled but horizon is not configured to work " +
"with keystone version 3 or above.")
LOG.warning(msg)
# Starting from 1.7 Django uses OrderedDict for fields and keyOrder
# no longer works for it
if django.VERSION >= (1, 7):
self.fields = collections.OrderedDict(
(key, self.fields[key]) for key in fields_ordering)
else:
self.fields.keyOrder = fields_ordering
self.fields = collections.OrderedDict(
(key, self.fields[key]) for key in fields_ordering)
@staticmethod
def get_region_choices():

View File

@ -13,18 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import django
from django.test.runner import DiscoverRunner as test_runner
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'openstack_auth.tests.settings'
import django
if django.VERSION < (1, 8, 0):
from django.test.simple import DjangoTestSuiteRunner as test_runner
else:
from django.test.runner import DiscoverRunner as test_runner
if hasattr(django, 'setup'):
django.setup()

View File

@ -13,6 +13,7 @@
import uuid
import django
from django.conf import settings
from django.contrib import auth
from django.core.urlresolvers import reverse
@ -362,7 +363,10 @@ class OpenStackAuthTestsV2(OpenStackAuthTestsMixin, test.TestCase):
response = self.client.get(url, form_data)
if next:
expected_url = 'http://testserver%s' % next
if django.VERSION >= (1, 9):
expected_url = next
else:
expected_url = 'http://testserver%s' % next
self.assertEqual(response['location'], expected_url)
else:
self.assertRedirects(response, settings.LOGIN_REDIRECT_URL)
@ -408,7 +412,10 @@ class OpenStackAuthTestsV2(OpenStackAuthTestsMixin, test.TestCase):
response = self.client.get(url, form_data)
if next:
expected_url = 'http://testserver%s' % next
if django.VERSION >= (1, 9):
expected_url = next
else:
expected_url = 'http://testserver%s' % next
self.assertEqual(response['location'], expected_url)
else:
self.assertRedirects(response, settings.LOGIN_REDIRECT_URL)
@ -719,7 +726,10 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin, test.TestCase):
response = self.client.get(url, form_data)
if next:
expected_url = 'http://testserver%s' % next
if django.VERSION >= (1, 9):
expected_url = next
else:
expected_url = 'http://testserver%s' % next
self.assertEqual(response['location'], expected_url)
else:
self.assertRedirects(response, settings.LOGIN_REDIRECT_URL)
@ -764,7 +774,10 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin, test.TestCase):
response = self.client.get(url, form_data)
if next:
expected_url = 'http://testserver%s' % next
if django.VERSION >= (1, 9):
expected_url = next
else:
expected_url = 'http://testserver%s' % next
self.assertEqual(response['location'], expected_url)
else:
self.assertRedirects(response, settings.LOGIN_REDIRECT_URL)

View File

@ -12,7 +12,6 @@
# limitations under the License.
import logging
import django
from django.conf import settings
from django.contrib import auth
from django.contrib.auth.decorators import login_required # noqa
@ -83,13 +82,7 @@ def login(request, template_name=None, extra_context=None, **kwargs):
initial.update({'region': requested_region})
if request.method == "POST":
# NOTE(saschpe): Since https://code.djangoproject.com/ticket/15198,
# the 'request' object is passed directly to AuthenticationForm in
# django.contrib.auth.views#login:
if django.VERSION >= (1, 6):
form = functional.curry(forms.Login)
else:
form = functional.curry(forms.Login, request)
form = functional.curry(forms.Login)
else:
form = functional.curry(forms.Login, initial=initial)
@ -233,7 +226,7 @@ def switch(request, tenant_id, redirect_field_name=auth.REDIRECT_FIELD_NAME):
# Ensure the user-originating redirection url is safe.
# Taken from django.contrib.auth.views.login()
redirect_to = request.REQUEST.get(redirect_field_name, '')
redirect_to = request.GET.get(redirect_field_name, '')
if not is_safe_url(url=redirect_to, host=request.get_host()):
redirect_to = settings.LOGIN_REDIRECT_URL
@ -270,7 +263,7 @@ def switch_region(request, region_name,
LOG.debug('Switching services region to %s for user "%s".'
% (region_name, request.user.username))
redirect_to = request.REQUEST.get(redirect_field_name, '')
redirect_to = request.GET.get(redirect_field_name, '')
if not is_safe_url(url=redirect_to, host=request.get_host()):
redirect_to = settings.LOGIN_REDIRECT_URL

View File

@ -1,7 +1,7 @@
[tox]
minversion = 1.6
skipsdist = True
envlist = py27,py27dj17,py27dj18,pep8,py33,py34
envlist = py27,py27dj18,pep8,py33,py34
[testenv]
usedevelop = True
@ -24,10 +24,6 @@ commands =
python -m coverage html --include='openstack_auth/*' --omit='openstack_auth/tests/*' -d 'reports'
python -m coverage xml --include='openstack_auth/*' --omit='openstack_auth/tests/*'
[testenv:py27dj17]
commands = pip install django>=1.7,<1.8
python openstack_auth/tests/run_tests.py {posargs}
# Django 1.8 is LTS
[testenv:py27dj18]
commands = pip install django>=1.8,<1.9