Merge "Suppress expected exception messages in unit test"

This commit is contained in:
Jenkins 2014-08-25 12:08:49 +00:00 committed by Gerrit Code Review
commit 59e410eb24
1 changed files with 20 additions and 15 deletions

View File

@ -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
self.client.get(LAUNCH_URL) loggers = []
for cls in toSuppress:
logger = logging.getLogger(cls)
loggers.append((logger, logger.getEffectiveLevel()))
logger.setLevel(logging.CRITICAL)
from horizon import exceptions try:
self.assertRaises(exceptions.Http302, handle_uncaught_redirect) with self.assertRaises(exceptions.Http302):
####################################################################### self.client.get(LAUNCH_URL)
# FIXME (woodm1979): This SHOULD be the test mechanism. finally:
# res = self.client.get(LAUNCH_URL) # Restore the previous log levels
# self.assertMessageCount(res, errors=1) for (log, level) in loggers:
# self.assertRedirectsNoFollow(res, INDEX_URL) log.setLevel(level)
@test.create_stubs({ @test.create_stubs({
api.trove: ('flavor_list', 'backup_list', 'instance_create', api.trove: ('flavor_list', 'backup_list', 'instance_create',