From 82f07cc69b3c9c57e3ac772491434ddbecbf3e49 Mon Sep 17 00:00:00 2001 From: Sergey Kraynev Date: Tue, 31 Mar 2015 09:16:04 -0400 Subject: [PATCH] Use HeatTestCase as parent instead of testtools Let's use base class for test, which allows to write scenarious tests in child clases. Change-Id: I8276513d6ce5a83ce1b46ff3107cc0e3223d9b4d --- heat/tests/db/test_sqlalchemy_types.py | 4 ++-- heat/tests/test_attributes.py | 3 +-- heat/tests/test_constraints.py | 6 +++--- heat/tests/test_dependencies.py | 5 ++--- heat/tests/test_identifier.py | 9 ++++----- heat/tests/test_parameters.py | 7 +++---- heat/tests/test_plugin_loader.py | 4 ++-- heat/tests/test_properties.py | 10 +++++----- heat/tests/test_rpc_client.py | 11 +++-------- heat/tests/test_short_id.py | 5 ++--- heat/tests/test_sqlalchemy_types.py | 6 +++--- 11 files changed, 30 insertions(+), 40 deletions(-) diff --git a/heat/tests/db/test_sqlalchemy_types.py b/heat/tests/db/test_sqlalchemy_types.py index f85317d78c..6802050a4e 100644 --- a/heat/tests/db/test_sqlalchemy_types.py +++ b/heat/tests/db/test_sqlalchemy_types.py @@ -14,12 +14,12 @@ from sqlalchemy.dialects.mysql import base as mysql_base from sqlalchemy.dialects.sqlite import base as sqlite_base from sqlalchemy import types -import testtools from heat.db.sqlalchemy import types as db_types +from heat.tests import common -class ListTest(testtools.TestCase): +class ListTest(common.HeatTestCase): def setUp(self): super(ListTest, self).setUp() diff --git a/heat/tests/test_attributes.py b/heat/tests/test_attributes.py index da673fc3f8..fb99db9f02 100644 --- a/heat/tests/test_attributes.py +++ b/heat/tests/test_attributes.py @@ -12,7 +12,6 @@ # under the License. import mock -import testtools from heat.engine import attributes from heat.engine import resources @@ -20,7 +19,7 @@ from heat.engine import support from heat.tests import common -class AttributeSchemaTest(testtools.TestCase): +class AttributeSchemaTest(common.HeatTestCase): def test_schema_all(self): d = {'description': 'A attribute'} s = attributes.Schema('A attribute') diff --git a/heat/tests/test_constraints.py b/heat/tests/test_constraints.py index 11e2954d83..2a4023b887 100644 --- a/heat/tests/test_constraints.py +++ b/heat/tests/test_constraints.py @@ -13,14 +13,14 @@ import six -import testtools from heat.common import exception from heat.engine import constraints from heat.engine import environment +from heat.tests import common -class SchemaTest(testtools.TestCase): +class SchemaTest(common.HeatTestCase): def test_range_schema(self): d = {'range': {'min': 5, 'max': 10}, 'description': 'a range'} r = constraints.Range(5, 10, description='a range') @@ -432,7 +432,7 @@ class SchemaTest(testtools.TestCase): self.assertEqual(['a', 'b'], res) -class CustomConstraintTest(testtools.TestCase): +class CustomConstraintTest(common.HeatTestCase): def setUp(self): super(CustomConstraintTest, self).setUp() diff --git a/heat/tests/test_dependencies.py b/heat/tests/test_dependencies.py index 6dcf30ccda..e5b57e971b 100644 --- a/heat/tests/test_dependencies.py +++ b/heat/tests/test_dependencies.py @@ -12,12 +12,11 @@ # under the License. -import testtools - from heat.engine import dependencies +from heat.tests import common -class dependenciesTest(testtools.TestCase): +class dependenciesTest(common.HeatTestCase): def _dep_test(self, func, checkorder, deps): nodes = set.union(*[set(e) for e in deps]) diff --git a/heat/tests/test_identifier.py b/heat/tests/test_identifier.py index ac20d01dde..5f01bcd09c 100644 --- a/heat/tests/test_identifier.py +++ b/heat/tests/test_identifier.py @@ -12,12 +12,11 @@ # under the License. -import testtools - from heat.common import identifier +from heat.tests import common -class IdentifierTest(testtools.TestCase): +class IdentifierTest(common.HeatTestCase): url_prefix = 'http://1.2.3.4/foo/' def test_attrs(self): @@ -361,7 +360,7 @@ class IdentifierTest(testtools.TestCase): self.assertEqual(['p1', 'p2', 'p3'], hi._path_components()) -class ResourceIdentifierTest(testtools.TestCase): +class ResourceIdentifierTest(common.HeatTestCase): def test_resource_init_no_path(self): si = identifier.HeatIdentifier('t', 's', 'i') ri = identifier.ResourceIdentifier(resource_name='r', **si) @@ -392,7 +391,7 @@ class ResourceIdentifierTest(testtools.TestCase): 't', 's', 'i', 'p', 'r/r') -class EventIdentifierTest(testtools.TestCase): +class EventIdentifierTest(common.HeatTestCase): def test_event_init_integer_id(self): self._test_event_init('42') diff --git a/heat/tests/test_parameters.py b/heat/tests/test_parameters.py index 5d9d2f2c96..6851c72c6c 100644 --- a/heat/tests/test_parameters.py +++ b/heat/tests/test_parameters.py @@ -13,7 +13,6 @@ from oslo_serialization import jsonutils as json import six -import testtools from heat.common import exception from heat.common import identifier @@ -156,7 +155,7 @@ class ParameterTestCommon(common.HeatTestCase): self.assertEqual(self.zero, p.value()) -class ParameterTestSpecific(testtools.TestCase): +class ParameterTestSpecific(common.HeatTestCase): def test_new_bad_type(self): self.assertRaises(exception.InvalidSchemaError, new_parameter, 'p', {'Type': 'List'}, validate_value=False) @@ -434,7 +433,7 @@ params_schema = json.loads('''{ }''') -class ParametersTest(testtools.TestCase): +class ParametersTest(common.HeatTestCase): def new_parameters(self, stack_name, tmpl, user_params=None, stack_id=None, validate_value=True, param_defaults=None): @@ -566,7 +565,7 @@ class ParametersTest(testtools.TestCase): self.assertEqual(111, params['a']) -class ParameterSchemaTest(testtools.TestCase): +class ParameterSchemaTest(common.HeatTestCase): def test_validate_schema_wrong_key(self): error = self.assertRaises(exception.InvalidSchemaError, diff --git a/heat/tests/test_plugin_loader.py b/heat/tests/test_plugin_loader.py index 4a874d336b..e8cbe9b628 100644 --- a/heat/tests/test_plugin_loader.py +++ b/heat/tests/test_plugin_loader.py @@ -16,13 +16,13 @@ import pkgutil import sys import mock -import testtools from heat.common import plugin_loader import heat.engine +from heat.tests import common -class PluginLoaderTest(testtools.TestCase): +class PluginLoaderTest(common.HeatTestCase): def test_module_name(self): self.assertEqual('foo.bar.blarg.wibble', plugin_loader._module_name('foo.bar', 'blarg.wibble')) diff --git a/heat/tests/test_properties.py b/heat/tests/test_properties.py index 4d816086bd..41caa0447f 100644 --- a/heat/tests/test_properties.py +++ b/heat/tests/test_properties.py @@ -13,7 +13,6 @@ from oslo_serialization import jsonutils import six -import testtools from heat.common import exception from heat.engine.cfn import functions as cfn_funcs @@ -23,9 +22,10 @@ from heat.engine import parameters from heat.engine import properties from heat.engine import resources from heat.engine import support +from heat.tests import common -class PropertySchemaTest(testtools.TestCase): +class PropertySchemaTest(common.HeatTestCase): def test_schema_all(self): d = { 'type': 'string', @@ -582,7 +582,7 @@ class PropertySchemaTest(testtools.TestCase): self.assertTrue(schema.allow_conversion) -class PropertyTest(testtools.TestCase): +class PropertyTest(common.HeatTestCase): def test_required_default(self): p = properties.Property({'Type': 'String'}) self.assertFalse(p.required()) @@ -932,7 +932,7 @@ class PropertyTest(testtools.TestCase): "an integer", six.text_type(ex)) -class PropertiesTest(testtools.TestCase): +class PropertiesTest(common.HeatTestCase): def setUp(self): super(PropertiesTest, self).setUp() schema = { @@ -1509,7 +1509,7 @@ class PropertiesTest(testtools.TestCase): self.assertTrue(props_a != props_b) -class PropertiesValidationTest(testtools.TestCase): +class PropertiesValidationTest(common.HeatTestCase): def test_required(self): schema = {'foo': {'Type': 'String', 'Required': True}} props = properties.Properties(schema, {'foo': 'bar'}) diff --git a/heat/tests/test_rpc_client.py b/heat/tests/test_rpc_client.py index ef2fe35bcf..a07b30dcf8 100644 --- a/heat/tests/test_rpc_client.py +++ b/heat/tests/test_rpc_client.py @@ -22,28 +22,23 @@ import copy import mock from oslo_messaging._drivers import common as rpc_common import stubout -import testtools from heat.common import exception from heat.common import identifier -from heat.common import messaging from heat.rpc import client as rpc_client +from heat.tests import common from heat.tests import utils -class EngineRpcAPITestCase(testtools.TestCase): +class EngineRpcAPITestCase(common.HeatTestCase): def setUp(self): - messaging.setup("fake://", optional=True) - self.addCleanup(messaging.cleanup) - self.context = utils.dummy_context() - + super(EngineRpcAPITestCase, self).setUp() self.stubs = stubout.StubOutForTesting() self.identity = dict(identifier.HeatIdentifier('engine_test_tenant', '6', 'wordpress')) self.rpcapi = rpc_client.EngineClient() - super(EngineRpcAPITestCase, self).setUp() def _to_remote_error(self, error): """Converts the given exception to the one with the _Remote suffix. diff --git a/heat/tests/test_short_id.py b/heat/tests/test_short_id.py index 0cb74704a4..d49f19b9d9 100644 --- a/heat/tests/test_short_id.py +++ b/heat/tests/test_short_id.py @@ -13,12 +13,11 @@ import uuid -import testtools - from heat.common import short_id +from heat.tests import common -class ShortIdTest(testtools.TestCase): +class ShortIdTest(common.HeatTestCase): def test_byte_string_8(self): self.assertEqual('\xab', short_id._to_byte_string(0xab, 8)) diff --git a/heat/tests/test_sqlalchemy_types.py b/heat/tests/test_sqlalchemy_types.py index 758ef70d76..97921346ce 100644 --- a/heat/tests/test_sqlalchemy_types.py +++ b/heat/tests/test_sqlalchemy_types.py @@ -14,12 +14,12 @@ from sqlalchemy.dialects.mysql import base as mysql_base from sqlalchemy.dialects.sqlite import base as sqlite_base from sqlalchemy import types -import testtools from heat.db.sqlalchemy import types as db_types +from heat.tests import common -class LongTextTest(testtools.TestCase): +class LongTextTest(common.HeatTestCase): def setUp(self): super(LongTextTest, self).setUp() @@ -34,7 +34,7 @@ class LongTextTest(testtools.TestCase): self.assertEqual(types.Text, type(impl)) -class JsonTest(testtools.TestCase): +class JsonTest(common.HeatTestCase): def setUp(self): super(JsonTest, self).setUp()