From 029121616f36f8fb8e5abae33f0635cae6d2ff9c Mon Sep 17 00:00:00 2001 From: "Gary W. Smith" Date: Mon, 18 Aug 2014 21:30:16 -0700 Subject: [PATCH] Suppress expected exception messages in unit test Closes-Bug: 1358120 Change-Id: Id3683d49d45c0077b93fd2241ebe11b1225c4ab2 --- .../dashboards/project/databases/tests.py | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/openstack_dashboard/dashboards/project/databases/tests.py b/openstack_dashboard/dashboards/project/databases/tests.py index 8be1307e0d..2a090dd86d 100644 --- a/openstack_dashboard/dashboards/project/databases/tests.py +++ b/openstack_dashboard/dashboards/project/databases/tests.py @@ -13,11 +13,14 @@ # License for the specific language governing permissions and limitations # under the License. +import logging + from django.core.urlresolvers import reverse from django import http from mox import IsA # noqa +from horizon import exceptions from openstack_dashboard import api from openstack_dashboard.test import helpers as test @@ -136,27 +139,29 @@ class DatabaseTests(test.TestCase): @test.create_stubs({api.trove: ('flavor_list',)}) 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) self.mox.ReplayAll() - ####################################################################### - # FIXME (woodm1979): I can't make the normal mechanisms work: - # assertMessageCount or assertRedirectsNoFollow - # exceptions.handle is correctly raising a redirect which is causing - # the test to fail. + toSuppress = ["openstack_dashboard.dashboards.project.databases." + "workflows.create_instance", + "horizon.workflows.base"] - def handle_uncaught_redirect(): - self.client.get(LAUNCH_URL) + # 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) - from horizon import exceptions - self.assertRaises(exceptions.Http302, handle_uncaught_redirect) - ####################################################################### + try: + with self.assertRaises(exceptions.Http302): + self.client.get(LAUNCH_URL) - # FIXME (woodm1979): This SHOULD be the test mechanism. - # res = self.client.get(LAUNCH_URL) - # self.assertMessageCount(res, errors=1) - # self.assertRedirectsNoFollow(res, INDEX_URL) + finally: + # Restore the previous log levels + for (log, level) in loggers: + log.setLevel(level) @test.create_stubs({ api.trove: ('flavor_list', 'backup_list', 'instance_create',