From bc905aa96b68037a276592d44285bced038045a8 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Wed, 11 Jun 2014 16:01:23 +1000 Subject: [PATCH] Switch from unittest2 to oslotest(testtools) This brings us inline with other projects and allows us to use oslotest.BaseTestCase which gets us stdout and logging on test failure. Change-Id: Ic47e456d9076d6f2803a400eda9d6a89d0b30441 --- mistral/db/sqlalchemy/api.py | 2 ++ .../api/v1/controllers/test_executions.py | 8 ++++---- mistral/tests/base.py | 20 +++++++++++++++++-- .../tests/unit/actions/test_action_factory.py | 7 ++++--- .../unit/actions/test_std_email_action.py | 6 +++--- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/mistral/db/sqlalchemy/api.py b/mistral/db/sqlalchemy/api.py index f61d3fbd5..2af3d30ab 100644 --- a/mistral/db/sqlalchemy/api.py +++ b/mistral/db/sqlalchemy/api.py @@ -71,9 +71,11 @@ def setup_db(): def drop_db(): + global _facade try: engine = get_engine() m.Trigger.metadata.drop_all(engine) + _facade = None except Exception as e: LOG.exception("Database shutdown exception: %s", e) return False diff --git a/mistral/tests/api/v1/controllers/test_executions.py b/mistral/tests/api/v1/controllers/test_executions.py index 4071c3970..4fc9f2eac 100644 --- a/mistral/tests/api/v1/controllers/test_executions.py +++ b/mistral/tests/api/v1/controllers/test_executions.py @@ -130,10 +130,10 @@ class TestExecutionsController(base.FunctionalTest): @mock.patch.object(engine.EngineClient, 'start_workflow_execution', mock.MagicMock(side_effect=ex.MistralException)) def test_post_throws_exception(self): - with self.assertRaises(AppError) as context: - self.app.post_json('/v1/workbooks/my_workbook/executions', - EXECS[0]) - self.assertIn('Bad response: 400', context.exception.message) + context = self.assertRaises(AppError, self.app.post_json, + '/v1/workbooks/my_workbook/executions', + EXECS[0]) + self.assertIn('Bad response: 400', context.message) @mock.patch.object(db_api, 'execution_delete', mock.MagicMock(return_value=None)) diff --git a/mistral/tests/base.py b/mistral/tests/base.py index 6f1a2f12a..b73b7f9b4 100644 --- a/mistral/tests/base.py +++ b/mistral/tests/base.py @@ -15,12 +15,14 @@ # limitations under the License. import os +import sys import tempfile -import unittest2 +import testtools.matchers as ttm from oslo import messaging from oslo.config import cfg from oslo.messaging import transport +from oslotest import base import pkg_resources as pkg from stevedore import driver @@ -58,7 +60,7 @@ def get_fake_transport(): return transport.Transport(mgr.driver) -class BaseTest(unittest2.TestCase): +class BaseTest(base.BaseTestCase): def setUp(self): super(BaseTest, self).setUp() @@ -69,6 +71,20 @@ class BaseTest(unittest2.TestCase): # TODO: add whatever is needed for all Mistral tests in here + def assertListEqual(self, l1, l2): + if tuple(sys.version_info)[0:2] < (2, 7): + # for python 2.6 compatibility + self.assertEqual(l1, l2) + else: + super(BaseTest, self).assertListEqual(l1, l2) + + def assertDictEqual(self, cmp1, cmp2): + if tuple(sys.version_info)[0:2] < (2, 7): + # for python 2.6 compatibility + self.assertThat(cmp1, ttm.Equals(cmp2)) + else: + super(BaseTest, self).assertDictEqual(cmp1, cmp2) + def _assert_single_item(self, items, **props): return self._assert_multiple_items(items, 1, **props)[0] diff --git a/mistral/tests/unit/actions/test_action_factory.py b/mistral/tests/unit/actions/test_action_factory.py index 27ec40be7..0b9ae314f 100644 --- a/mistral/tests/unit/actions/test_action_factory.py +++ b/mistral/tests/unit/actions/test_action_factory.py @@ -16,7 +16,7 @@ import json import copy -import unittest2 +from mistral import exceptions from mistral.openstack.common import log as logging from mistral.actions import action_factory as a_f from mistral.actions import std_actions as std @@ -112,9 +112,10 @@ class ActionFactoryTest(base.BaseTest): self.assertEqual(std.SendEmailAction, a_f.get_action_class("std.email")) - @unittest2.expectedFailure def test_get_action_class_failure(self): - self.assertEqual(std.EchoAction, a_f.get_action_class("echo")) + exc = self.assertRaises(exceptions.ActionException, + a_f.get_action_class, 'echo') + self.assertIn('Invalid action name', exc.message) def test_create_http_action(self): action = a_f.create_action(DB_TASK) diff --git a/mistral/tests/unit/actions/test_std_email_action.py b/mistral/tests/unit/actions/test_std_email_action.py index 421b2be46..be197425f 100644 --- a/mistral/tests/unit/actions/test_std_email_action.py +++ b/mistral/tests/unit/actions/test_std_email_action.py @@ -15,7 +15,7 @@ # limitations under the License. -import unittest2 +import testtools from mock import call from mock import patch @@ -63,12 +63,12 @@ class SendEmailActionTest(base.BaseTest): } self.to_addrs = ', '.join(self.params['to']) - @unittest2.skipIf(not LOCAL_SMTPD, "Setup local smtpd to run it") + @testtools.skipIf(not LOCAL_SMTPD, "Setup local smtpd to run it") def test_send_email_real(self): action = std.SendEmailAction(self.params, self.settings) action.run() - @unittest2.skipIf(not REMOTE_SMTP, "Configure Remote SMTP to run it") + @testtools.skipIf(not REMOTE_SMTP, "Configure Remote SMTP to run it") def test_with_password_real(self): self.params['to'] = ["dz@stackstorm.com"] self.settings = {