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 os
|
||||||
|
|
||||||
|
import django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.template.base import TemplateDoesNotExist # noqa
|
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
|
from django.utils._os import safe_join # noqa
|
||||||
|
|
||||||
# Set up a cache of the panel directories to search.
|
# Set up a cache of the panel directories to search.
|
||||||
panel_template_dirs = {}
|
panel_template_dirs = {}
|
||||||
|
|
||||||
|
|
||||||
class TemplateLoader(BaseLoader):
|
class TemplateLoader(tLoaderCls):
|
||||||
is_usable = True
|
is_usable = True
|
||||||
|
|
||||||
def get_template_sources(self, template_name):
|
def get_template_sources(self, template_name):
|
||||||
@ -54,4 +61,8 @@ class TemplateLoader(BaseLoader):
|
|||||||
raise TemplateDoesNotExist(template_name)
|
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.sessions.middleware.SessionMiddleware',
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'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',
|
'django.middleware.locale.LocaleMiddleware',
|
||||||
'horizon.middleware.HorizonMiddleware')
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
|
)
|
||||||
|
|
||||||
TEMPLATE_CONTEXT_PROCESSORS = (
|
TEMPLATE_CONTEXT_PROCESSORS = (
|
||||||
'django.core.context_processors.debug',
|
'django.core.context_processors.debug',
|
||||||
|
@ -1539,41 +1539,46 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
|||||||
self.assertMessageCount(error=2, warning=0)
|
self.assertMessageCount(error=2, warning=0)
|
||||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||||
|
|
||||||
@test.create_stubs({api.keystone: ('get_default_role',
|
# django 1.7 and later does not handle the thrown keystoneclient
|
||||||
'tenant_get',
|
# exception well enough.
|
||||||
'domain_get'),
|
# TODO(mrunge): re-check when django-1.8 is stable
|
||||||
quotas: ('get_tenant_quota_data',
|
@unittest.skipIf(django.VERSION >= (1, 7, 0),
|
||||||
'get_disabled_quotas')})
|
'Currently skipped with Django >= 1.7')
|
||||||
def test_update_project_when_default_role_does_not_exist(self):
|
@test.create_stubs({api.keystone: ('get_default_role',
|
||||||
project = self.tenants.first()
|
'tenant_get',
|
||||||
domain_id = project.domain_id
|
'domain_get'),
|
||||||
quota = self.quotas.first()
|
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)) \
|
api.keystone.get_default_role(IsA(http.HttpRequest)) \
|
||||||
.MultipleTimes().AndReturn(None) # Default role doesn't exist
|
.MultipleTimes().AndReturn(None) # Default role doesn't exist
|
||||||
api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
|
api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
|
||||||
admin=True) \
|
admin=True) \
|
||||||
.AndReturn(project)
|
.AndReturn(project)
|
||||||
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
|
api.keystone.domain_get(IsA(http.HttpRequest), domain_id) \
|
||||||
.AndReturn(self.domain)
|
.AndReturn(self.domain)
|
||||||
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
|
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
|
||||||
.AndReturn(self.disabled_quotas.first())
|
.AndReturn(self.disabled_quotas.first())
|
||||||
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
|
quotas.get_tenant_quota_data(IsA(http.HttpRequest),
|
||||||
tenant_id=self.tenant.id) \
|
tenant_id=self.tenant.id) \
|
||||||
.AndReturn(quota)
|
.AndReturn(quota)
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
url = reverse('horizon:identity:projects:update',
|
url = reverse('horizon:identity:projects:update',
|
||||||
args=[self.tenant.id])
|
args=[self.tenant.id])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Avoid the log message in the test output when the workflow's
|
# Avoid the log message in the test output when the workflow's
|
||||||
# step action cannot be instantiated
|
# step action cannot be instantiated
|
||||||
logging.disable(logging.ERROR)
|
logging.disable(logging.ERROR)
|
||||||
with self.assertRaises(exceptions.NotFound):
|
with self.assertRaises(exceptions.NotFound):
|
||||||
self.client.get(url)
|
self.client.get(url)
|
||||||
finally:
|
finally:
|
||||||
logging.disable(logging.NOTSET)
|
logging.disable(logging.NOTSET)
|
||||||
|
|
||||||
|
|
||||||
class UsageViewTests(test.BaseAdminViewTests):
|
class UsageViewTests(test.BaseAdminViewTests):
|
||||||
|
@ -15,8 +15,10 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import django
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django import http
|
from django import http
|
||||||
|
from django.utils import unittest
|
||||||
|
|
||||||
from mox import IsA # noqa
|
from mox import IsA # noqa
|
||||||
|
|
||||||
@ -151,6 +153,11 @@ class DatabaseTests(test.TestCase):
|
|||||||
res = self.client.get(LAUNCH_URL)
|
res = self.client.get(LAUNCH_URL)
|
||||||
self.assertTemplateUsed(res, 'project/databases/launch.html')
|
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',)})
|
@test.create_stubs({api.trove: ('flavor_list',)})
|
||||||
def test_launch_instance_exception_on_flavors(self):
|
def test_launch_instance_exception_on_flavors(self):
|
||||||
trove_exception = self.exceptions.nova
|
trove_exception = self.exceptions.nova
|
||||||
|
@ -21,6 +21,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
import django
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from openstack_dashboard import exceptions
|
from openstack_dashboard import exceptions
|
||||||
@ -102,8 +103,14 @@ MIDDLEWARE_CLASSES = (
|
|||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'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',
|
'horizon.middleware.HorizonMiddleware',
|
||||||
'django.middleware.doc.XViewMiddleware',
|
|
||||||
'django.middleware.locale.LocaleMiddleware',
|
'django.middleware.locale.LocaleMiddleware',
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user