Merge "tests: Use base class for all functional tests"

This commit is contained in:
Zuul 2023-06-15 11:49:16 +00:00 committed by Gerrit Code Review
commit 6fe6b3713c
2 changed files with 22 additions and 12 deletions

View File

@ -30,6 +30,8 @@ class TestCase(testtools.TestCase):
and establishes the placement database.
"""
USES_DB = True
def setUp(self):
super(TestCase, self).setUp()
@ -37,8 +39,14 @@ class TestCase(testtools.TestCase):
self.conf_fixture = self.useFixture(
config_fixture.Config(cfg.ConfigOpts()))
conf.register_opts(self.conf_fixture.conf)
self.placement_db = self.useFixture(fixtures.Database(
self.conf_fixture, set_config=True))
if self.USES_DB:
self.placement_db = self.useFixture(fixtures.Database(
self.conf_fixture, set_config=True))
else:
self.conf_fixture.config(
connection='sqlite://',
group='placement_database',
)
self.conf_fixture.conf([], default_config_files=[])
self.useFixture(policy_fixture.PolicyFixture(self.conf_fixture))
@ -51,3 +59,7 @@ class TestCase(testtools.TestCase):
self.context = context.RequestContext()
self.context.config = self.conf_fixture.conf
class NoDBTestCase(TestCase):
USES_DB = False

View File

@ -23,7 +23,6 @@ subdirectory. The test will then use that DB and username/password combo to run
the tests.
"""
from unittest import mock
from alembic import script
@ -32,13 +31,12 @@ from oslo_db.sqlalchemy import test_migrations
from oslo_db.sqlalchemy import utils as db_utils
from oslo_log import log as logging
from oslo_utils.fixture import uuidsentinel as uuids
from oslotest import base as test_base
from sqlalchemy import inspect
import testtools
from placement.db.sqlalchemy import migration
from placement.db.sqlalchemy import models
from placement import db_api
from placement.tests.functional import base
LOG = logging.getLogger(__name__)
@ -88,7 +86,7 @@ class WalkVersionsMixin(object):
raise
class TestWalkVersions(testtools.TestCase, WalkVersionsMixin):
class TestWalkVersions(base.NoDBTestCase, WalkVersionsMixin):
def setUp(self):
super(TestWalkVersions, self).setUp()
self.migration_api = mock.MagicMock()
@ -301,21 +299,21 @@ class PostgresqlOpportunisticFixture(
class TestMigrationsSQLite(MigrationCheckersMixin,
WalkVersionsMixin,
test_fixtures.OpportunisticDBTestMixin,
test_base.BaseTestCase):
base.NoDBTestCase):
FIXTURE = SQLiteOpportunisticFixture
class TestMigrationsMySQL(MigrationCheckersMixin,
WalkVersionsMixin,
test_fixtures.OpportunisticDBTestMixin,
test_base.BaseTestCase):
base.NoDBTestCase):
FIXTURE = MySQLOpportunisticFixture
class TestMigrationsPostgresql(MigrationCheckersMixin,
WalkVersionsMixin,
test_fixtures.OpportunisticDBTestMixin,
test_base.BaseTestCase):
base.NoDBTestCase):
FIXTURE = PostgresqlOpportunisticFixture
@ -332,17 +330,17 @@ class _TestModelsMigrations(test_migrations.ModelsMigrationsSync):
class ModelsMigrationsSyncSqlite(_TestModelsMigrations,
test_fixtures.OpportunisticDBTestMixin,
test_base.BaseTestCase):
base.NoDBTestCase):
FIXTURE = SQLiteOpportunisticFixture
class ModelsMigrationsSyncMysql(_TestModelsMigrations,
test_fixtures.OpportunisticDBTestMixin,
test_base.BaseTestCase):
base.NoDBTestCase):
FIXTURE = MySQLOpportunisticFixture
class ModelsMigrationsSyncPostgresql(_TestModelsMigrations,
test_fixtures.OpportunisticDBTestMixin,
test_base.BaseTestCase):
base.NoDBTestCase):
FIXTURE = PostgresqlOpportunisticFixture