summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Cresswell <robert.cresswell@outlook.com>2015-12-10 13:33:50 +0000
committerRob Cresswell <robert.cresswell@outlook.com>2016-01-15 13:12:24 +0000
commitd8a9ad9fb268216409c2d05ff47aa366cbc5432c (patch)
treeb603321d19ccd1127b6755d71598ff593a6985b4
parent47ce93c09f207ac233b9b8ca875c23f49b160133 (diff)
downloaddjango_openstack_auth-d8a9ad9fb268216409c2d05ff47aa366cbc5432c.tar.gz
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
-rw-r--r--openstack_auth/forms.py10
-rw-r--r--openstack_auth/tests/run_tests.py8
-rw-r--r--openstack_auth/tests/tests.py21
-rw-r--r--openstack_auth/views.py13
-rw-r--r--tox.ini6
5 files changed, 25 insertions, 33 deletions
diff --git a/openstack_auth/forms.py b/openstack_auth/forms.py
index 61241ac..6e4bf8b 100644
--- a/openstack_auth/forms.py
+++ b/openstack_auth/forms.py
@@ -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():
diff --git a/openstack_auth/tests/run_tests.py b/openstack_auth/tests/run_tests.py
index b317967..bc1e8c9 100644
--- a/openstack_auth/tests/run_tests.py
+++ b/openstack_auth/tests/run_tests.py
@@ -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()
diff --git a/openstack_auth/tests/tests.py b/openstack_auth/tests/tests.py
index 3eeff59..847c8b6 100644
--- a/openstack_auth/tests/tests.py
+++ b/openstack_auth/tests/tests.py
@@ -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)
diff --git a/openstack_auth/views.py b/openstack_auth/views.py
index 9e060a0..eb70940 100644
--- a/openstack_auth/views.py
+++ b/openstack_auth/views.py
@@ -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
diff --git a/tox.ini b/tox.ini
index 2573302..96292cb 100644
--- a/tox.ini
+++ b/tox.ini
@@ -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