Add Django-1.7 support
And add initial Django-1.8 fixes - skip unittests until exceptions are fixed - Django-1.8 changed the way TemplateLoaders are initialized. - django.middleware.doc.XViewMiddleware is removed. - SessionAuthenticationMiddleware was added and will be mandatory for Django-2.0 Closes-Bug: #1425892 Partially Implements: blueprint django18 Change-Id: Idfd3f494db7b11a66e2262c9520be88b098fbb7b
This commit is contained in:
parent
ef1b395b1c
commit
e77dfcab4c
@ -16,16 +16,23 @@ Wrapper for loading templates from "templates" directories in panel modules.
|
||||
|
||||
import os
|
||||
|
||||
import django
|
||||
from django.conf import settings
|
||||
from django.template.base import TemplateDoesNotExist # noqa
|
||||
from django.template.loader import BaseLoader # noqa
|
||||
|
||||
if django.get_version() >= '1.8':
|
||||
from django.template.engine import Engine
|
||||
from django.template.loaders.base import Loader as tLoaderCls
|
||||
else:
|
||||
from django.template.loader import BaseLoader as tLoaderCls # noqa
|
||||
|
||||
from django.utils._os import safe_join # noqa
|
||||
|
||||
# Set up a cache of the panel directories to search.
|
||||
panel_template_dirs = {}
|
||||
|
||||
|
||||
class TemplateLoader(BaseLoader):
|
||||
class TemplateLoader(tLoaderCls):
|
||||
is_usable = True
|
||||
|
||||
def get_template_sources(self, template_name):
|
||||
@ -54,4 +61,8 @@ class TemplateLoader(BaseLoader):
|
||||
raise TemplateDoesNotExist(template_name)
|
||||
|
||||
|
||||
_loader = TemplateLoader()
|
||||
if django.get_version() >= '1.8':
|
||||
e = Engine()
|
||||
_loader = TemplateLoader(e)
|
||||
else:
|
||||
_loader = TemplateLoader()
|
||||
|
@ -73,9 +73,17 @@ MIDDLEWARE_CLASSES = (
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.doc.XViewMiddleware',
|
||||
)
|
||||
if django.VERSION >= (1, 8, 0):
|
||||
MIDDLEWARE_CLASSES += (
|
||||
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',)
|
||||
else:
|
||||
MIDDLEWARE_CLASSES += ('django.middleware.doc.XViewMiddleware',)
|
||||
MIDDLEWARE_CLASSES += (
|
||||
'horizon.middleware.HorizonMiddleware',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
'horizon.middleware.HorizonMiddleware')
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
)
|
||||
|
||||
TEMPLATE_CONTEXT_PROCESSORS = (
|
||||
'django.core.context_processors.debug',
|
||||
|
@ -1539,41 +1539,46 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
self.assertMessageCount(error=2, warning=0)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({api.keystone: ('get_default_role',
|
||||
'tenant_get',
|
||||
'domain_get'),
|
||||
quotas: ('get_tenant_quota_data',
|
||||
'get_disabled_quotas')})
|
||||
def test_update_project_when_default_role_does_not_exist(self):
|
||||
project = self.tenants.first()
|
||||
domain_id = project.domain_id
|
||||
quota = self.quotas.first()
|
||||
# django 1.7 and later does not handle the thrown keystoneclient
|
||||
# exception well enough.
|
||||
# TODO(mrunge): re-check when django-1.8 is stable
|
||||
@unittest.skipIf(django.VERSION >= (1, 7, 0),
|
||||
'Currently skipped with Django >= 1.7')
|
||||
@test.create_stubs({api.keystone: ('get_default_role',
|
||||
'tenant_get',
|
||||
'domain_get'),
|
||||
quotas: ('get_tenant_quota_data',
|
||||
'get_disabled_quotas')})
|
||||
def test_update_project_when_default_role_does_not_exist(self):
|
||||
project = self.tenants.first()
|
||||
domain_id = project.domain_id
|
||||
quota = self.quotas.first()
|
||||
|
||||
api.keystone.get_default_role(IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(None) # Default role doesn't exist
|
||||
api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
|
||||
admin=True) \
|
||||
.AndReturn(project)
|
||||
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
|
||||
.AndReturn(self.domain)
|
||||
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
|
||||
.AndReturn(self.disabled_quotas.first())
|
||||
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
|
||||
tenant_id=self.tenant.id) \
|
||||
.AndReturn(quota)
|
||||
self.mox.ReplayAll()
|
||||
api.keystone.get_default_role(IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(None) # Default role doesn't exist
|
||||
api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
|
||||
admin=True) \
|
||||
.AndReturn(project)
|
||||
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
|
||||
.AndReturn(self.domain)
|
||||
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
|
||||
.AndReturn(self.disabled_quotas.first())
|
||||
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
|
||||
tenant_id=self.tenant.id) \
|
||||
.AndReturn(quota)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
url = reverse('horizon:identity:projects:update',
|
||||
args=[self.tenant.id])
|
||||
url = reverse('horizon:identity:projects:update',
|
||||
args=[self.tenant.id])
|
||||
|
||||
try:
|
||||
# Avoid the log message in the test output when the workflow's
|
||||
# step action cannot be instantiated
|
||||
logging.disable(logging.ERROR)
|
||||
with self.assertRaises(exceptions.NotFound):
|
||||
self.client.get(url)
|
||||
finally:
|
||||
logging.disable(logging.NOTSET)
|
||||
try:
|
||||
# Avoid the log message in the test output when the workflow's
|
||||
# step action cannot be instantiated
|
||||
logging.disable(logging.ERROR)
|
||||
with self.assertRaises(exceptions.NotFound):
|
||||
self.client.get(url)
|
||||
finally:
|
||||
logging.disable(logging.NOTSET)
|
||||
|
||||
|
||||
class UsageViewTests(test.BaseAdminViewTests):
|
||||
|
@ -15,8 +15,10 @@
|
||||
|
||||
import logging
|
||||
|
||||
import django
|
||||
from django.core.urlresolvers import reverse
|
||||
from django import http
|
||||
from django.utils import unittest
|
||||
|
||||
from mox import IsA # noqa
|
||||
|
||||
@ -151,6 +153,11 @@ class DatabaseTests(test.TestCase):
|
||||
res = self.client.get(LAUNCH_URL)
|
||||
self.assertTemplateUsed(res, 'project/databases/launch.html')
|
||||
|
||||
# django 1.7 and later does not handle the thrown Http302
|
||||
# exception well enough.
|
||||
# TODO(mrunge): re-check when django-1.8 is stable
|
||||
@unittest.skipIf(django.VERSION >= (1, 7, 0),
|
||||
'Currently skipped with Django >= 1.7')
|
||||
@test.create_stubs({api.trove: ('flavor_list',)})
|
||||
def test_launch_instance_exception_on_flavors(self):
|
||||
trove_exception = self.exceptions.nova
|
||||
|
@ -21,6 +21,7 @@ import os
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
import django
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from openstack_dashboard import exceptions
|
||||
@ -102,8 +103,14 @@ MIDDLEWARE_CLASSES = (
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
)
|
||||
if django.VERSION >= (1, 8, 0):
|
||||
MIDDLEWARE_CLASSES += (
|
||||
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',)
|
||||
else:
|
||||
MIDDLEWARE_CLASSES += ('django.middleware.doc.XViewMiddleware',)
|
||||
MIDDLEWARE_CLASSES += (
|
||||
'horizon.middleware.HorizonMiddleware',
|
||||
'django.middleware.doc.XViewMiddleware',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user