Use oslo_db.sqlalchemy.test_fixtures

Make use of the newer fixtures in oslo_db.sqlalchemy.test_fixtures
which is what was intended to supersede fixtures
in oslo_db.sqlalchemy.test_base.

Change-Id: Icb88c13336fffb499083197ed864b8e4e45dc241
Closes-Bug: #1797102
This commit is contained in:
Takashi NATSUME 2018-10-10 17:28:05 +09:00
parent f554c61333
commit 7748c754b9
4 changed files with 45 additions and 31 deletions

View File

@ -32,7 +32,8 @@ import os
from migrate.versioning import repository from migrate.versioning import repository
import mock import mock
from oslo_db.sqlalchemy import test_base from oslo_db.sqlalchemy import enginefacade
from oslo_db.sqlalchemy import test_fixtures
from oslo_db.sqlalchemy import test_migrations from oslo_db.sqlalchemy import test_migrations
from oslo_db.sqlalchemy import utils as db_utils from oslo_db.sqlalchemy import utils as db_utils
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
@ -51,6 +52,10 @@ from nova.tests import fixtures as nova_fixtures
class NovaAPIModelsSync(test_migrations.ModelsMigrationsSync): class NovaAPIModelsSync(test_migrations.ModelsMigrationsSync):
"""Test that the models match the database after migrations are run.""" """Test that the models match the database after migrations are run."""
def setUp(self):
super(NovaAPIModelsSync, self).setUp()
self.engine = enginefacade.writer.get_engine()
def db_sync(self, engine): def db_sync(self, engine):
with mock.patch.object(sa_migration, 'get_engine', with mock.patch.object(sa_migration, 'get_engine',
return_value=engine): return_value=engine):
@ -122,20 +127,20 @@ class NovaAPIModelsSync(test_migrations.ModelsMigrationsSync):
class TestNovaAPIMigrationsSQLite(NovaAPIModelsSync, class TestNovaAPIMigrationsSQLite(NovaAPIModelsSync,
test_base.DbTestCase, test_fixtures.OpportunisticDBTestMixin,
test.NoDBTestCase): test.NoDBTestCase):
pass pass
class TestNovaAPIMigrationsMySQL(NovaAPIModelsSync, class TestNovaAPIMigrationsMySQL(NovaAPIModelsSync,
test_base.MySQLOpportunisticTestCase, test_fixtures.OpportunisticDBTestMixin,
test.NoDBTestCase): test.NoDBTestCase):
pass FIXTURE = test_fixtures.MySQLOpportunisticFixture
class TestNovaAPIMigrationsPostgreSQL(NovaAPIModelsSync, class TestNovaAPIMigrationsPostgreSQL(NovaAPIModelsSync,
test_base.PostgreSQLOpportunisticTestCase, test.NoDBTestCase): test_fixtures.OpportunisticDBTestMixin, test.NoDBTestCase):
pass FIXTURE = test_fixtures.PostgresqlOpportunisticFixture
class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin): class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin):
@ -146,6 +151,7 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin):
# test output. # test output.
self.useFixture(nova_fixtures.StandardLogging()) self.useFixture(nova_fixtures.StandardLogging())
super(NovaAPIMigrationsWalk, self).setUp() super(NovaAPIMigrationsWalk, self).setUp()
self.engine = enginefacade.writer.get_engine()
@property @property
def INIT_VERSION(self): def INIT_VERSION(self):
@ -722,17 +728,17 @@ class NovaAPIMigrationsWalk(test_migrations.WalkVersionsMixin):
class TestNovaAPIMigrationsWalkSQLite(NovaAPIMigrationsWalk, class TestNovaAPIMigrationsWalkSQLite(NovaAPIMigrationsWalk,
test_base.DbTestCase, test_fixtures.OpportunisticDBTestMixin,
test.NoDBTestCase): test.NoDBTestCase):
pass pass
class TestNovaAPIMigrationsWalkMySQL(NovaAPIMigrationsWalk, class TestNovaAPIMigrationsWalkMySQL(NovaAPIMigrationsWalk,
test_base.MySQLOpportunisticTestCase, test_fixtures.OpportunisticDBTestMixin,
test.NoDBTestCase): test.NoDBTestCase):
pass FIXTURE = test_fixtures.MySQLOpportunisticFixture
class TestNovaAPIMigrationsWalkPostgreSQL(NovaAPIMigrationsWalk, class TestNovaAPIMigrationsWalkPostgreSQL(NovaAPIMigrationsWalk,
test_base.PostgreSQLOpportunisticTestCase, test.NoDBTestCase): test_fixtures.OpportunisticDBTestMixin, test.NoDBTestCase):
pass FIXTURE = test_fixtures.PostgresqlOpportunisticFixture

View File

@ -27,7 +27,7 @@ import netaddr
from oslo_db import api as oslo_db_api from oslo_db import api as oslo_db_api
from oslo_db import exception as db_exc from oslo_db import exception as db_exc
from oslo_db.sqlalchemy import enginefacade from oslo_db.sqlalchemy import enginefacade
from oslo_db.sqlalchemy import test_base from oslo_db.sqlalchemy import test_fixtures
from oslo_db.sqlalchemy import update_match from oslo_db.sqlalchemy import update_match
from oslo_db.sqlalchemy import utils as sqlalchemyutils from oslo_db.sqlalchemy import utils as sqlalchemyutils
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
@ -8832,7 +8832,9 @@ class RetryOnDeadlockTestCase(test.TestCase):
self.assertTrue(call_api()) self.assertTrue(call_api())
class TestSqlalchemyTypesRepr(test_base.DbTestCase): class TestSqlalchemyTypesRepr(
test_fixtures.OpportunisticDBTestMixin, test.NoDBTestCase):
def setUp(self): def setUp(self):
# NOTE(sdague): the oslo_db base test case completely # NOTE(sdague): the oslo_db base test case completely
# invalidates our logging setup, we actually have to do that # invalidates our logging setup, we actually have to do that
@ -8841,6 +8843,7 @@ class TestSqlalchemyTypesRepr(test_base.DbTestCase):
self.useFixture(nova_fixtures.StandardLogging()) self.useFixture(nova_fixtures.StandardLogging())
super(TestSqlalchemyTypesRepr, self).setUp() super(TestSqlalchemyTypesRepr, self).setUp()
self.engine = enginefacade.writer.get_engine()
meta = MetaData(bind=self.engine) meta = MetaData(bind=self.engine)
self.table = Table( self.table = Table(
'cidr_tbl', 'cidr_tbl',
@ -8867,14 +8870,12 @@ class TestSqlalchemyTypesRepr(test_base.DbTestCase):
self.assertEqual(addrs[idx][1], row.addr) self.assertEqual(addrs[idx][1], row.addr)
class TestMySQLSqlalchemyTypesRepr(TestSqlalchemyTypesRepr, class TestMySQLSqlalchemyTypesRepr(TestSqlalchemyTypesRepr):
test_base.MySQLOpportunisticTestCase): FIXTURE = test_fixtures.MySQLOpportunisticFixture
pass
class TestPostgreSQLSqlalchemyTypesRepr(TestSqlalchemyTypesRepr, class TestPostgreSQLSqlalchemyTypesRepr(TestSqlalchemyTypesRepr):
test_base.PostgreSQLOpportunisticTestCase): FIXTURE = test_fixtures.PostgresqlOpportunisticFixture
pass
class TestDBInstanceTags(test.TestCase): class TestDBInstanceTags(test.TestCase):

View File

@ -14,7 +14,9 @@
# under the License. # under the License.
from oslo_db.sqlalchemy.compat import utils as compat_utils from oslo_db.sqlalchemy.compat import utils as compat_utils
from oslo_db.sqlalchemy import enginefacade
from oslo_db.sqlalchemy import test_base from oslo_db.sqlalchemy import test_base
from oslo_db.sqlalchemy import test_fixtures
from oslo_db.sqlalchemy import utils as oslodbutils from oslo_db.sqlalchemy import utils as oslodbutils
from oslo_utils import uuidutils from oslo_utils import uuidutils
from sqlalchemy import Integer, String from sqlalchemy import Integer, String
@ -26,6 +28,7 @@ from sqlalchemy.types import UserDefinedType
from nova.db.sqlalchemy import api as db from nova.db.sqlalchemy import api as db
from nova.db.sqlalchemy import utils from nova.db.sqlalchemy import utils
from nova import exception from nova import exception
from nova import test
from nova.tests import fixtures as nova_fixtures from nova.tests import fixtures as nova_fixtures
SA_VERSION = compat_utils.SQLA_VERSION SA_VERSION = compat_utils.SQLA_VERSION
@ -44,7 +47,8 @@ class CustomType(UserDefinedType):
# a fixture. # a fixture.
class TestMigrationUtilsSQLite(test_base.DbTestCase): class TestMigrationUtilsSQLite(
test_fixtures.OpportunisticDBTestMixin, test.NoDBTestCase):
"""Class for testing utils that are used in db migrations.""" """Class for testing utils that are used in db migrations."""
def setUp(self): def setUp(self):
@ -54,6 +58,7 @@ class TestMigrationUtilsSQLite(test_base.DbTestCase):
# test output. # test output.
self.useFixture(nova_fixtures.StandardLogging()) self.useFixture(nova_fixtures.StandardLogging())
super(TestMigrationUtilsSQLite, self).setUp() super(TestMigrationUtilsSQLite, self).setUp()
self.engine = enginefacade.writer.get_engine()
self.meta = MetaData(bind=self.engine) self.meta = MetaData(bind=self.engine)
def test_delete_from_select(self): def test_delete_from_select(self):
@ -221,11 +226,9 @@ class TestMigrationUtilsSQLite(test_base.DbTestCase):
self.engine, table_name=table_name) self.engine, table_name=table_name)
class TestMigrationUtilsPostgreSQL(TestMigrationUtilsSQLite, class TestMigrationUtilsPostgreSQL(TestMigrationUtilsSQLite):
test_base.PostgreSQLOpportunisticTestCase): FIXTURE = test_fixtures.PostgresqlOpportunisticFixture
pass
class TestMigrationUtilsMySQL(TestMigrationUtilsSQLite, class TestMigrationUtilsMySQL(TestMigrationUtilsSQLite):
test_base.MySQLOpportunisticTestCase): FIXTURE = test_fixtures.MySQLOpportunisticFixture
pass

View File

@ -38,7 +38,8 @@ import os
from migrate import UniqueConstraint from migrate import UniqueConstraint
from migrate.versioning import repository from migrate.versioning import repository
import mock import mock
from oslo_db.sqlalchemy import test_base from oslo_db.sqlalchemy import enginefacade
from oslo_db.sqlalchemy import test_fixtures
from oslo_db.sqlalchemy import test_migrations from oslo_db.sqlalchemy import test_migrations
from oslo_db.sqlalchemy import utils as oslodbutils from oslo_db.sqlalchemy import utils as oslodbutils
import sqlalchemy import sqlalchemy
@ -101,6 +102,7 @@ class NovaMigrationsCheckers(test_migrations.ModelsMigrationsSync,
self.useFixture(nova_fixtures.Timeout( self.useFixture(nova_fixtures.Timeout(
os.environ.get('OS_TEST_TIMEOUT', 0), os.environ.get('OS_TEST_TIMEOUT', 0),
self.TIMEOUT_SCALING_FACTOR)) self.TIMEOUT_SCALING_FACTOR))
self.engine = enginefacade.writer.get_engine()
def assertColumnExists(self, engine, table_name, column): def assertColumnExists(self, engine, table_name, column):
self.assertTrue(oslodbutils.column_exists(engine, table_name, column), self.assertTrue(oslodbutils.column_exists(engine, table_name, column),
@ -1016,14 +1018,16 @@ class NovaMigrationsCheckers(test_migrations.ModelsMigrationsSync,
class TestNovaMigrationsSQLite(NovaMigrationsCheckers, class TestNovaMigrationsSQLite(NovaMigrationsCheckers,
test_base.DbTestCase, test_fixtures.OpportunisticDBTestMixin,
test.NoDBTestCase): test.NoDBTestCase):
pass pass
class TestNovaMigrationsMySQL(NovaMigrationsCheckers, class TestNovaMigrationsMySQL(NovaMigrationsCheckers,
test_base.MySQLOpportunisticTestCase, test_fixtures.OpportunisticDBTestMixin,
test.NoDBTestCase): test.NoDBTestCase):
FIXTURE = test_fixtures.MySQLOpportunisticFixture
def test_innodb_tables(self): def test_innodb_tables(self):
with mock.patch.object(sa_migration, 'get_engine', with mock.patch.object(sa_migration, 'get_engine',
return_value=self.migrate_engine): return_value=self.migrate_engine):
@ -1048,9 +1052,9 @@ class TestNovaMigrationsMySQL(NovaMigrationsCheckers,
class TestNovaMigrationsPostgreSQL(NovaMigrationsCheckers, class TestNovaMigrationsPostgreSQL(NovaMigrationsCheckers,
test_base.PostgreSQLOpportunisticTestCase, test_fixtures.OpportunisticDBTestMixin,
test.NoDBTestCase): test.NoDBTestCase):
pass FIXTURE = test_fixtures.PostgresqlOpportunisticFixture
class ProjectTestCase(test.NoDBTestCase): class ProjectTestCase(test.NoDBTestCase):