Suppress expected exception messages in unit test
Closes-Bug: 1358120 Change-Id: Id3683d49d45c0077b93fd2241ebe11b1225c4ab2
This commit is contained in:
parent
ca99ddcd5a
commit
029121616f
@ -13,11 +13,14 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django import http
|
from django import http
|
||||||
|
|
||||||
from mox import IsA # noqa
|
from mox import IsA # noqa
|
||||||
|
|
||||||
|
from horizon import exceptions
|
||||||
from openstack_dashboard import api
|
from openstack_dashboard import api
|
||||||
from openstack_dashboard.test import helpers as test
|
from openstack_dashboard.test import helpers as test
|
||||||
|
|
||||||
@ -136,27 +139,29 @@ class DatabaseTests(test.TestCase):
|
|||||||
|
|
||||||
@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.trove
|
trove_exception = self.exceptions.nova
|
||||||
api.trove.flavor_list(IsA(http.HttpRequest)).AndRaise(trove_exception)
|
api.trove.flavor_list(IsA(http.HttpRequest)).AndRaise(trove_exception)
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
#######################################################################
|
toSuppress = ["openstack_dashboard.dashboards.project.databases."
|
||||||
# FIXME (woodm1979): I can't make the normal mechanisms work:
|
"workflows.create_instance",
|
||||||
# assertMessageCount or assertRedirectsNoFollow
|
"horizon.workflows.base"]
|
||||||
# exceptions.handle is correctly raising a redirect which is causing
|
|
||||||
# the test to fail.
|
|
||||||
|
|
||||||
def handle_uncaught_redirect():
|
# Suppress expected log messages in the test output
|
||||||
|
loggers = []
|
||||||
|
for cls in toSuppress:
|
||||||
|
logger = logging.getLogger(cls)
|
||||||
|
loggers.append((logger, logger.getEffectiveLevel()))
|
||||||
|
logger.setLevel(logging.CRITICAL)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with self.assertRaises(exceptions.Http302):
|
||||||
self.client.get(LAUNCH_URL)
|
self.client.get(LAUNCH_URL)
|
||||||
|
|
||||||
from horizon import exceptions
|
finally:
|
||||||
self.assertRaises(exceptions.Http302, handle_uncaught_redirect)
|
# Restore the previous log levels
|
||||||
#######################################################################
|
for (log, level) in loggers:
|
||||||
|
log.setLevel(level)
|
||||||
# FIXME (woodm1979): This SHOULD be the test mechanism.
|
|
||||||
# res = self.client.get(LAUNCH_URL)
|
|
||||||
# self.assertMessageCount(res, errors=1)
|
|
||||||
# self.assertRedirectsNoFollow(res, INDEX_URL)
|
|
||||||
|
|
||||||
@test.create_stubs({
|
@test.create_stubs({
|
||||||
api.trove: ('flavor_list', 'backup_list', 'instance_create',
|
api.trove: ('flavor_list', 'backup_list', 'instance_create',
|
||||||
|
Loading…
Reference in New Issue
Block a user