Consolidates TestCase and BaseTestCase
Most unit tests are derived from TestCase class of base.py. A few unit tests are derived from BaseTestCase class of utils.py. This patch consolidates these two classes into one and have all the tests derived from a single base class which is TestCase class. Hence, the ironic/tests/util.py is removed from this patch. Change-Id: Iecc3352ef7e49524b202e6551a233692a2f6acea
This commit is contained in:
parent
d6739867ab
commit
7716be1db4
|
@ -55,7 +55,7 @@ from ironic.openstack.common import lockutils
|
|||
from ironic.openstack.common import log as logging
|
||||
|
||||
import ironic.db.sqlalchemy.migrate_repo
|
||||
from ironic.tests import utils as test_utils
|
||||
from ironic.tests import base
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -121,7 +121,7 @@ def get_db_connection_info(conn_pieces):
|
|||
return (user, password, database, host)
|
||||
|
||||
|
||||
class BaseMigrationTestCase(test_utils.BaseTestCase):
|
||||
class BaseMigrationTestCase(base.TestCase):
|
||||
"""Base class fort testing of migration utils."""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -314,7 +314,7 @@ class WalkVersionsMixin(object):
|
|||
raise
|
||||
|
||||
|
||||
class TestWalkVersions(test_utils.BaseTestCase, WalkVersionsMixin):
|
||||
class TestWalkVersions(base.TestCase, WalkVersionsMixin):
|
||||
def setUp(self):
|
||||
super(TestWalkVersions, self).setUp()
|
||||
self.migration_api = mock.MagicMock()
|
||||
|
|
|
@ -27,9 +27,9 @@ from ironic.common.glance_service import base_image_service
|
|||
from ironic.common.glance_service import service_utils
|
||||
from ironic.common import image_service as service
|
||||
from ironic.openstack.common import context
|
||||
from ironic.tests import base
|
||||
from ironic.tests import matchers
|
||||
from ironic.tests import stubs
|
||||
from ironic.tests import utils
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
|
@ -80,7 +80,7 @@ class TestGlanceSerializer(testtools.TestCase):
|
|||
metadata)
|
||||
|
||||
|
||||
class TestGlanceImageService(utils.BaseTestCase):
|
||||
class TestGlanceImageService(base.TestCase):
|
||||
NOW_GLANCE_OLD_FORMAT = "2010-10-11T10:30:22"
|
||||
NOW_GLANCE_FORMAT = "2010-10-11T10:30:22.000000"
|
||||
|
||||
|
@ -615,7 +615,7 @@ def _create_failing_glance_client(info):
|
|||
return MyGlanceStubClient()
|
||||
|
||||
|
||||
class TestGlanceUrl(utils.BaseTestCase):
|
||||
class TestGlanceUrl(base.TestCase):
|
||||
|
||||
def test_generate_glance_http_url(self):
|
||||
self.config(glance_host="127.0.0.1", group='glance')
|
||||
|
@ -633,7 +633,7 @@ class TestGlanceUrl(utils.BaseTestCase):
|
|||
self.assertEqual(generated_url, https_url)
|
||||
|
||||
|
||||
class TestServiceUtils(utils.BaseTestCase):
|
||||
class TestServiceUtils(base.TestCase):
|
||||
|
||||
def test_parse_image_ref_no_ssl(self):
|
||||
image_href = 'http://127.0.0.1:9292/image_path/image_uuid'
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2010-2011 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Common utilities used in testing"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import fixtures
|
||||
from oslo.config import cfg
|
||||
import testtools
|
||||
|
||||
from ironic.openstack.common.fixture import moxstubout
|
||||
|
||||
|
||||
class BaseTestCase(testtools.TestCase):
|
||||
|
||||
def setUp(self, conf=cfg.CONF):
|
||||
super(BaseTestCase, self).setUp()
|
||||
moxfixture = self.useFixture(moxstubout.MoxStubout())
|
||||
self.mox = moxfixture.mox
|
||||
self.stubs = moxfixture.stubs
|
||||
self.conf = conf
|
||||
self.useFixture(fixtures.FakeLogger('openstack.common'))
|
||||
self.useFixture(fixtures.Timeout(30, True))
|
||||
self.config(fatal_exception_format_errors=True)
|
||||
self.useFixture(fixtures.NestedTempfile())
|
||||
self.tempdirs = []
|
||||
|
||||
self.addCleanup(self.conf.reset)
|
||||
self.addCleanup(self.conf.reset)
|
||||
self.addCleanup(self.stubs.UnsetAll)
|
||||
self.addCleanup(self.stubs.SmartUnsetAll)
|
||||
|
||||
def create_tempfiles(self, files, ext='.conf'):
|
||||
tempfiles = []
|
||||
for (basename, contents) in files:
|
||||
if not os.path.isabs(basename):
|
||||
(fd, path) = tempfile.mkstemp(prefix=basename, suffix=ext)
|
||||
else:
|
||||
path = basename + ext
|
||||
fd = os.open(path, os.O_CREAT | os.O_WRONLY)
|
||||
tempfiles.append(path)
|
||||
try:
|
||||
os.write(fd, contents)
|
||||
finally:
|
||||
os.close(fd)
|
||||
return tempfiles
|
||||
|
||||
def config(self, **kw):
|
||||
"""Override some configuration values.
|
||||
|
||||
The keyword arguments are the names of configuration options to
|
||||
override and their values.
|
||||
|
||||
If a group argument is supplied, the overrides are applied to
|
||||
the specified configuration option group.
|
||||
|
||||
All overrides are automatically cleaned up at the end of the
|
||||
current test.
|
||||
"""
|
||||
group = kw.pop('group', None)
|
||||
for k, v in kw.iteritems():
|
||||
self.conf.set_override(k, v, group)
|
Loading…
Reference in New Issue