Refactor base test classes

- use config fixture
- init test config only for unit tests

Change-Id: Ie460b550031f49c53375270ded240131cb5f124d
This commit is contained in:
Pavlo Shchelokovskyy 2016-03-03 12:11:16 +02:00 committed by Dmitry Tantsur
parent b804efeb02
commit 51f5690bea
2 changed files with 15 additions and 21 deletions

View File

@ -11,12 +11,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import unittest
import fixtures
import futurist import futurist
import mock import mock
from oslo_concurrency import lockutils from oslo_concurrency import lockutils
from oslo_config import cfg from oslo_config import cfg
from oslo_config import fixture as config_fixture
from oslo_log import log from oslo_log import log
from oslo_utils import uuidutils from oslo_utils import uuidutils
@ -31,30 +32,14 @@ from ironic_inspector import utils
CONF = cfg.CONF CONF = cfg.CONF
def init_test_conf(): class BaseTest(fixtures.TestWithFixtures):
try:
# Functional tests
CONF.reload_config_files()
# Unit tests
except Exception:
CONF.reset()
for group in ('firewall', 'processing', 'ironic', 'discoverd'):
CONF.register_group(cfg.OptGroup(group))
try:
# Functional tests
log.register_options(CONF)
except Exception:
# Unit tests
pass
CONF.set_default('connection', "sqlite:///", group='database')
CONF.set_default('slave_connection', False, group='database')
CONF.set_default('max_retries', 10, group='database')
IS_FUNCTIONAL = False
class BaseTest(unittest.TestCase):
def setUp(self): def setUp(self):
super(BaseTest, self).setUp() super(BaseTest, self).setUp()
init_test_conf() if not self.IS_FUNCTIONAL:
self.init_test_conf()
self.session = db.get_session() self.session = db.get_session()
engine = db.get_engine() engine = db.get_engine()
db.Base.metadata.create_all(engine) db.Base.metadata.create_all(engine)
@ -69,6 +54,14 @@ class BaseTest(unittest.TestCase):
self.addCleanup(lambda p=patch: p.stop()) self.addCleanup(lambda p=patch: p.stop())
utils._EXECUTOR = futurist.SynchronousExecutor(green=True) utils._EXECUTOR = futurist.SynchronousExecutor(green=True)
def init_test_conf(self):
CONF.reset()
log.register_options(CONF)
self.cfg = self.useFixture(config_fixture.Config(CONF))
self.cfg.set_default('connection', "sqlite:///", group='database')
self.cfg.set_default('slave_connection', False, group='database')
self.cfg.set_default('max_retries', 10, group='database')
def assertPatchEqual(self, expected, actual): def assertPatchEqual(self, expected, actual):
expected = sorted(expected, key=lambda p: p['path']) expected = sorted(expected, key=lambda p: p['path'])
actual = sorted(actual, key=lambda p: p['path']) actual = sorted(actual, key=lambda p: p['path'])

View File

@ -56,6 +56,7 @@ DEFAULT_SLEEP = 2
class Base(base.NodeTest): class Base(base.NodeTest):
ROOT_URL = 'http://127.0.0.1:5050' ROOT_URL = 'http://127.0.0.1:5050'
IS_FUNCTIONAL = True
def setUp(self): def setUp(self):
super(Base, self).setUp() super(Base, self).setUp()