tests: Use common base class

The final step in cleaning up our many base classes. This will allow us
to do things consistently across the test suite in future changes.

Change-Id: I0bf663fdfd3c8be93e5658493e221d0a7db78832
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2021-07-16 12:55:49 +01:00
parent 538e0a23ab
commit a6007a98b1
16 changed files with 148 additions and 129 deletions

View File

@ -18,7 +18,7 @@ import debtcollector
from oslo_db.sqlalchemy import enginefacade
from oslo_db.sqlalchemy.test_base import backend_specific # noqa
from oslo_db.sqlalchemy import test_fixtures as db_fixtures
from oslotest import base as test_base
from oslo_db.tests import base as test_base
@enginefacade.transaction_context_provider
@ -62,7 +62,8 @@ class PostgreSQLOpportunisticTestCase(DbTestCase):
# make use of oslo_db.sqlalchemy.test_fixtures directly.
class _DbTestCase(
db_fixtures.OpportunisticDBTestMixin, test_base.BaseTestCase):
db_fixtures.OpportunisticDBTestMixin, test_base.BaseTestCase,
):
def setUp(self):
super(_DbTestCase, self).setUp()

View File

@ -21,7 +21,6 @@ import warnings
from oslo_config import cfg
from oslo_context import context as oslo_context
from oslotest import base as oslo_test_base
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import MetaData
@ -36,10 +35,10 @@ from oslo_db import options
from oslo_db.sqlalchemy import enginefacade
from oslo_db.sqlalchemy import engines as oslo_engines
from oslo_db.sqlalchemy import orm
from oslo_db.tests.sqlalchemy import base as test_base
from oslo_db.tests import base as test_base
from oslo_db.tests.sqlalchemy import base as db_test_base
from oslo_db import warning
enginefacade.transaction_context_provider(oslo_context.RequestContext)
@ -92,7 +91,7 @@ class AssertDataSource(collections.namedtuple(
assert False, "Unknown constant: %s" % const
class MockFacadeTest(oslo_test_base.BaseTestCase):
class MockFacadeTest(test_base.BaseTestCase):
"""test by applying mocks to internal call-points.
This applies mocks to
@ -1186,7 +1185,7 @@ class MockFacadeTest(oslo_test_base.BaseTestCase):
session.execute("test")
class PatchFactoryTest(oslo_test_base.BaseTestCase):
class PatchFactoryTest(test_base.BaseTestCase):
def test_patch_manager(self):
normal_mgr = enginefacade.transaction_context()
@ -1396,7 +1395,7 @@ class AsyncReaderWSlaveMockFacadeTest(MockFacadeTest):
slave_uri = 'some_slave_connection'
class LegacyIntegrationtest(test_base._DbTestCase):
class LegacyIntegrationtest(db_test_base._DbTestCase):
def test_legacy_integration(self):
legacy_facade = enginefacade.get_legacy_facade()
@ -1454,7 +1453,7 @@ class LegacyIntegrationtest(test_base._DbTestCase):
)
class ThreadingTest(test_base._DbTestCase):
class ThreadingTest(db_test_base._DbTestCase):
"""Test copy/pickle on new threads using real connections and sessions."""
def _assert_ctx_connection(self, context, connection):
@ -1647,7 +1646,7 @@ class ThreadingTest(test_base._DbTestCase):
assert session is not session2
class LiveFacadeTest(test_base._DbTestCase):
class LiveFacadeTest(db_test_base._DbTestCase):
"""test using live SQL with test-provisioned databases.
Several of these tests require that multiple transactions run
@ -1809,7 +1808,7 @@ class LiveFacadeTest(test_base._DbTestCase):
session.query(self.User.name).scalar()
)
@test_base.backend_specific("postgresql", "mysql")
@db_test_base.backend_specific("postgresql", "mysql")
def test_external_session_transaction(self):
context = oslo_context.RequestContext()
with enginefacade.writer.using(context) as session:
@ -1916,7 +1915,7 @@ class LiveFacadeTest(test_base._DbTestCase):
self.User.name).order_by(self.User.name).all()
)
@test_base.backend_specific("postgresql", "mysql")
@db_test_base.backend_specific("postgresql", "mysql")
def test_external_session_transaction_decorator(self):
context = oslo_context.RequestContext()
@ -1964,7 +1963,7 @@ class LiveFacadeTest(test_base._DbTestCase):
self.User.name).order_by(self.User.name).all()
)
@test_base.backend_specific("postgresql", "mysql")
@db_test_base.backend_specific("postgresql", "mysql")
def test_external_connection_transaction(self):
context = oslo_context.RequestContext()
with enginefacade.writer.connection.using(context) as connection:
@ -2001,7 +2000,7 @@ class LiveFacadeTest(test_base._DbTestCase):
self.User.name).order_by(self.User.name).all()
)
@test_base.backend_specific("postgresql", "mysql")
@db_test_base.backend_specific("postgresql", "mysql")
def test_external_writer_in_reader(self):
context = oslo_context.RequestContext()
with enginefacade.reader.using(context) as session:
@ -2188,16 +2187,18 @@ class LiveFacadeTest(test_base._DbTestCase):
class MySQLLiveFacadeTest(
test_base._MySQLOpportunisticTestCase, LiveFacadeTest):
db_test_base._MySQLOpportunisticTestCase, LiveFacadeTest,
):
pass
class PGLiveFacadeTest(
test_base._PostgreSQLOpportunisticTestCase, LiveFacadeTest):
db_test_base._PostgreSQLOpportunisticTestCase, LiveFacadeTest,
):
pass
class ConfigOptionsTest(oslo_test_base.BaseTestCase):
class ConfigOptionsTest(test_base.BaseTestCase):
def test_all_options(self):
"""test that everything in CONF.database.iteritems() is accepted.
@ -2242,7 +2243,7 @@ class ConfigOptionsTest(oslo_test_base.BaseTestCase):
)
class TestTransactionFactoryCallback(oslo_test_base.BaseTestCase):
class TestTransactionFactoryCallback(test_base.BaseTestCase):
def test_setup_for_connection_called_with_profiler(self):
context_manager = enginefacade.transaction_context()

View File

@ -18,7 +18,6 @@ import contextlib
import itertools
from unittest import mock
from oslotest import base as oslo_test_base
import sqlalchemy as sqla
from sqlalchemy.engine import url as sqla_url
from sqlalchemy import event
@ -29,7 +28,8 @@ from sqlalchemy.orm import mapper
from oslo_db import exception
from oslo_db.sqlalchemy import engines
from oslo_db.sqlalchemy import exc_filters
from oslo_db.tests.sqlalchemy import base as test_base
from oslo_db.tests import base as test_base
from oslo_db.tests.sqlalchemy import base as db_test_base
from oslo_db.tests import utils as test_utils
_TABLE_NAME = '__tmp__test__tmp__'
@ -68,7 +68,7 @@ class _SQLAExceptionMatcher(object):
self.assertEqual(sql, exc.statement)
class TestsExceptionFilter(_SQLAExceptionMatcher, oslo_test_base.BaseTestCase):
class TestsExceptionFilter(_SQLAExceptionMatcher, test_base.BaseTestCase):
class Error(Exception):
"""DBAPI base error.
@ -245,8 +245,9 @@ class TestFallthroughsAndNonDBAPI(TestsExceptionFilter):
class TestNonExistentConstraint(
_SQLAExceptionMatcher,
test_base._DbTestCase):
_SQLAExceptionMatcher,
db_test_base._DbTestCase,
):
def setUp(self):
super(TestNonExistentConstraint, self).setUp()
@ -263,8 +264,9 @@ class TestNonExistentConstraint(
class TestNonExistentConstraintPostgreSQL(
TestNonExistentConstraint,
test_base._PostgreSQLOpportunisticTestCase):
TestNonExistentConstraint,
db_test_base._PostgreSQLOpportunisticTestCase,
):
def test_raise(self):
matched = self.assertRaises(
@ -287,8 +289,9 @@ class TestNonExistentConstraintPostgreSQL(
class TestNonExistentConstraintMySQL(
TestNonExistentConstraint,
test_base._MySQLOpportunisticTestCase):
TestNonExistentConstraint,
db_test_base._MySQLOpportunisticTestCase,
):
def test_raise(self):
matched = self.assertRaises(
@ -311,8 +314,9 @@ class TestNonExistentConstraintMySQL(
class TestNonExistentTable(
_SQLAExceptionMatcher,
test_base._DbTestCase):
_SQLAExceptionMatcher,
db_test_base._DbTestCase,
):
def setUp(self):
super(TestNonExistentTable, self).setUp()
@ -342,8 +346,9 @@ class TestNonExistentTable(
class TestNonExistentTablePostgreSQL(
TestNonExistentTable,
test_base._PostgreSQLOpportunisticTestCase):
TestNonExistentTable,
db_test_base._PostgreSQLOpportunisticTestCase,
):
def test_raise(self):
matched = self.assertRaises(
@ -361,8 +366,9 @@ class TestNonExistentTablePostgreSQL(
class TestNonExistentTableMySQL(
TestNonExistentTable,
test_base._MySQLOpportunisticTestCase):
TestNonExistentTable,
db_test_base._MySQLOpportunisticTestCase,
):
def test_raise(self):
matched = self.assertRaises(
@ -379,8 +385,9 @@ class TestNonExistentTableMySQL(
class TestNonExistentDatabase(
_SQLAExceptionMatcher,
test_base._DbTestCase):
_SQLAExceptionMatcher,
db_test_base._DbTestCase,
):
def setUp(self):
super(TestNonExistentDatabase, self).setUp()
@ -413,8 +420,9 @@ class TestNonExistentDatabase(
class TestNonExistentDatabaseMySQL(
TestNonExistentDatabase,
test_base._MySQLOpportunisticTestCase):
TestNonExistentDatabase,
db_test_base._MySQLOpportunisticTestCase,
):
def test_raise(self):
matched = self.assertRaises(
@ -432,8 +440,9 @@ class TestNonExistentDatabaseMySQL(
class TestNonExistentDatabasePostgreSQL(
TestNonExistentDatabase,
test_base._PostgreSQLOpportunisticTestCase):
TestNonExistentDatabase,
db_test_base._PostgreSQLOpportunisticTestCase,
):
def test_raise(self):
matched = self.assertRaises(
@ -449,7 +458,9 @@ class TestNonExistentDatabasePostgreSQL(
)
class TestReferenceErrorSQLite(_SQLAExceptionMatcher, test_base._DbTestCase):
class TestReferenceErrorSQLite(
_SQLAExceptionMatcher, db_test_base._DbTestCase,
):
def setUp(self):
super(TestReferenceErrorSQLite, self).setUp()
@ -522,8 +533,10 @@ class TestReferenceErrorSQLite(_SQLAExceptionMatcher, test_base._DbTestCase):
self.assertIsNone(matched.key_table)
class TestReferenceErrorPostgreSQL(TestReferenceErrorSQLite,
test_base._PostgreSQLOpportunisticTestCase):
class TestReferenceErrorPostgreSQL(
TestReferenceErrorSQLite,
db_test_base._PostgreSQLOpportunisticTestCase,
):
def test_raise(self):
params = {'id': 1, 'foo_id': 2}
matched = self.assertRaises(
@ -573,8 +586,10 @@ class TestReferenceErrorPostgreSQL(TestReferenceErrorSQLite,
self.assertEqual("resource_entity", matched.key_table)
class TestReferenceErrorMySQL(TestReferenceErrorSQLite,
test_base._MySQLOpportunisticTestCase):
class TestReferenceErrorMySQL(
TestReferenceErrorSQLite,
db_test_base._MySQLOpportunisticTestCase,
):
def test_raise(self):
matched = self.assertRaises(
exception.DBReferenceError,
@ -635,7 +650,9 @@ class TestReferenceErrorMySQL(TestReferenceErrorSQLite,
self.assertEqual("resource_foo", matched.key_table)
class TestExceptionCauseMySQLSavepoint(test_base._MySQLOpportunisticTestCase):
class TestExceptionCauseMySQLSavepoint(
db_test_base._MySQLOpportunisticTestCase,
):
def setUp(self):
super(TestExceptionCauseMySQLSavepoint, self).setUp()
@ -1011,7 +1028,7 @@ class TestDataError(TestsExceptionFilter):
self.DataError)
class IntegrationTest(test_base._DbTestCase):
class IntegrationTest(db_test_base._DbTestCase):
"""Test an actual error-raising round trips against the database."""
def setUp(self):

View File

@ -21,12 +21,12 @@ from oslo_db.sqlalchemy import enginefacade
from oslo_db.sqlalchemy import provision
from oslo_db.sqlalchemy import test_base as legacy_test_base
from oslo_db.sqlalchemy import test_fixtures
from oslotest import base as oslo_test_base
from oslo_db.tests import base as test_base
start_dir = os.path.dirname(__file__)
class BackendSkipTest(oslo_test_base.BaseTestCase):
class BackendSkipTest(test_base.BaseTestCase):
def test_skip_no_dbapi(self):
@ -35,7 +35,7 @@ class BackendSkipTest(oslo_test_base.BaseTestCase):
DRIVER = 'postgresql'
class SomeTest(test_fixtures.OpportunisticDBTestMixin,
oslo_test_base.BaseTestCase):
test_base.BaseTestCase):
FIXTURE = FakeDatabaseOpportunisticFixture
def runTest(self):
@ -77,7 +77,7 @@ class BackendSkipTest(oslo_test_base.BaseTestCase):
DRIVER = 'postgresql+nosuchdbapi'
class SomeTest(test_fixtures.OpportunisticDBTestMixin,
oslo_test_base.BaseTestCase):
test_base.BaseTestCase):
FIXTURE = FakeDatabaseOpportunisticFixture
@ -99,7 +99,8 @@ class BackendSkipTest(oslo_test_base.BaseTestCase):
def test_skip_no_dbapi_legacy(self):
class FakeDatabaseOpportunisticFixture(
legacy_test_base.DbFixture):
legacy_test_base.DbFixture,
):
DRIVER = 'postgresql'
class SomeTest(legacy_test_base.DbTestCase):
@ -140,7 +141,8 @@ class BackendSkipTest(oslo_test_base.BaseTestCase):
def test_skip_no_such_backend_legacy(self):
class FakeDatabaseOpportunisticFixture(
legacy_test_base.DbFixture):
legacy_test_base.DbFixture,
):
DRIVER = 'postgresql+nosuchdbapi'
class SomeTest(legacy_test_base.DbTestCase):
@ -163,7 +165,7 @@ class BackendSkipTest(oslo_test_base.BaseTestCase):
)
class EnginefacadeIntegrationTest(oslo_test_base.BaseTestCase):
class EnginefacadeIntegrationTest(test_base.BaseTestCase):
def test_db_fixture(self):
normal_mgr = enginefacade.transaction_context()
normal_mgr.configure(
@ -204,7 +206,7 @@ class EnginefacadeIntegrationTest(oslo_test_base.BaseTestCase):
self.assertFalse(normal_mgr._factory._started)
class LegacyBaseClassTest(oslo_test_base.BaseTestCase):
class LegacyBaseClassTest(test_base.BaseTestCase):
def test_new_db_is_provisioned_by_default_pg(self):
self._test_new_db_is_provisioned_by_default(
legacy_test_base.PostgreSQLOpportunisticTestCase

View File

@ -9,16 +9,17 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import alembic
from oslotest import base as test_base
import sqlalchemy
from oslo_db import exception
from oslo_db.sqlalchemy.migration_cli import ext_alembic
from oslo_db.sqlalchemy.migration_cli import ext_migrate
from oslo_db.sqlalchemy.migration_cli import manager
from oslo_db.tests import base as test_base
class MockWithCmp(mock.MagicMock):

View File

@ -18,16 +18,16 @@ from unittest import mock
import fixtures
from migrate.versioning import api as versioning_api
from oslotest import base as test
import sqlalchemy as sa
import sqlalchemy.ext.declarative as sa_decl
from oslo_db import exception as exc
from oslo_db.sqlalchemy import test_migrations as migrate
from oslo_db.tests.sqlalchemy import base as test_base
from oslo_db.tests import base as test_base
from oslo_db.tests.sqlalchemy import base as db_test_base
class TestWalkVersions(test.BaseTestCase, migrate.WalkVersionsMixin):
class TestWalkVersions(test_base.BaseTestCase, migrate.WalkVersionsMixin):
migration_api = mock.MagicMock()
REPOSITORY = mock.MagicMock()
engine = mock.MagicMock()
@ -185,7 +185,7 @@ class TestWalkVersions(test.BaseTestCase, migrate.WalkVersionsMixin):
self.assertEqual(upgraded, self.migrate_up.call_args_list)
class ModelsMigrationSyncMixin(test_base._DbTestCase):
class ModelsMigrationSyncMixin(db_test_base._DbTestCase):
def setUp(self):
super(ModelsMigrationSyncMixin, self).setUp()
@ -367,7 +367,7 @@ class ModelsMigrationSyncMixin(test_base._DbTestCase):
class ModelsMigrationsSyncMySQL(
ModelsMigrationSyncMixin,
migrate.ModelsMigrationsSync,
test_base._MySQLOpportunisticTestCase,
db_test_base._MySQLOpportunisticTestCase,
):
def test_models_not_sync(self):
@ -380,7 +380,7 @@ class ModelsMigrationsSyncMySQL(
class ModelsMigrationsSyncPostgreSQL(
ModelsMigrationSyncMixin,
migrate.ModelsMigrationsSync,
test_base._PostgreSQLOpportunisticTestCase,
db_test_base._PostgreSQLOpportunisticTestCase,
):
def test_models_not_sync(self):

View File

@ -17,20 +17,19 @@ from collections import abc
import datetime
from unittest import mock
from oslotest import base as oslo_test
from sqlalchemy import Column
from sqlalchemy import Integer, String
from sqlalchemy import event
from sqlalchemy.ext.declarative import declarative_base
from oslo_db.sqlalchemy import models
from oslo_db.tests.sqlalchemy import base as test_base
from oslo_db.tests import base as test_base
from oslo_db.tests.sqlalchemy import base as db_test_base
BASE = declarative_base()
class ModelBaseTest(test_base._DbTestCase):
class ModelBaseTest(db_test_base._DbTestCase):
def setUp(self):
super(ModelBaseTest, self).setUp()
self.mb = models.ModelBase()
@ -174,7 +173,7 @@ class ExtraKeysModel(BASE, models.ModelBase):
return ['name']
class TimestampMixinTest(oslo_test.BaseTestCase):
class TimestampMixinTest(test_base.BaseTestCase):
def test_timestampmixin_attr(self):
methods = ('created_at',
@ -191,7 +190,7 @@ class SoftDeletedModel(BASE, models.ModelBase, models.SoftDeleteMixin):
smth = Column('smth', String(255))
class SoftDeleteMixinTest(test_base._DbTestCase):
class SoftDeleteMixinTest(db_test_base._DbTestCase):
def setUp(self):
super(SoftDeleteMixinTest, self).setUp()

View File

@ -21,23 +21,19 @@ from oslo_db.sqlalchemy import enginefacade
from oslo_db.sqlalchemy import engines
from oslo_db.sqlalchemy import ndb
from oslo_db.sqlalchemy import test_fixtures
from oslo_db.sqlalchemy import utils
from oslo_db.sqlalchemy.types import String
from oslotest import base as test_base
from oslo_db.sqlalchemy import utils
from oslo_db.tests import base as test_base
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import Table
from sqlalchemy import Text
from sqlalchemy import create_engine
from sqlalchemy import schema
from sqlalchemy.dialects.mysql import TEXT
from sqlalchemy.dialects.mysql import TINYTEXT
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import schema
from sqlalchemy import Table
from sqlalchemy import Text
LOG = logging.getLogger(__name__)
@ -155,7 +151,8 @@ class NDBDatatypesDefaultTestCase(NDBMockTestBase):
class NDBOpportunisticTestCase(
test_fixtures.OpportunisticDBTestMixin, test_base.BaseTestCase):
test_fixtures.OpportunisticDBTestMixin, test_base.BaseTestCase,
):
FIXTURE = test_fixtures.MySQLOpportunisticFixture

View File

@ -15,12 +15,13 @@ from oslo_config import cfg
from oslo_config import fixture as config_fixture
from oslo_db import options
from oslo_db.tests import utils as test_utils
from oslo_db.tests import base as test_base
class DbApiOptionsTestCase(test_utils.BaseTestCase):
class DbApiOptionsTestCase(test_base.BaseTestCase):
def setUp(self):
super(DbApiOptionsTestCase, self).setUp()
super().setUp()
self.conf = self.useFixture(config_fixture.Config()).conf
self.conf.register_opts(options.database_opts, group='database')

View File

@ -13,7 +13,6 @@
import os
from unittest import mock
from oslotest import base as oslo_test_base
from sqlalchemy import exc as sa_exc
from sqlalchemy import inspect
from sqlalchemy import schema
@ -24,10 +23,11 @@ from oslo_db.sqlalchemy import enginefacade
from oslo_db.sqlalchemy import provision
from oslo_db.sqlalchemy import test_fixtures
from oslo_db.sqlalchemy import utils
from oslo_db.tests.sqlalchemy import base as test_base
from oslo_db.tests import base as test_base
from oslo_db.tests.sqlalchemy import base as db_test_base
class DropAllObjectsTest(test_base._DbTestCase):
class DropAllObjectsTest(db_test_base._DbTestCase):
def setUp(self):
super(DropAllObjectsTest, self).setUp()
@ -81,7 +81,7 @@ class DropAllObjectsTest(test_base._DbTestCase):
)
class BackendNotAvailableTest(oslo_test_base.BaseTestCase):
class BackendNotAvailableTest(test_base.BaseTestCase):
def test_no_dbapi(self):
backend = provision.Backend(
"postgresql", "postgresql+nosuchdbapi://hostname/dsn")
@ -138,16 +138,18 @@ class BackendNotAvailableTest(oslo_test_base.BaseTestCase):
class MySQLDropAllObjectsTest(
DropAllObjectsTest, test_base._MySQLOpportunisticTestCase):
DropAllObjectsTest, db_test_base._MySQLOpportunisticTestCase,
):
pass
class PostgreSQLDropAllObjectsTest(
DropAllObjectsTest, test_base._PostgreSQLOpportunisticTestCase):
DropAllObjectsTest, db_test_base._PostgreSQLOpportunisticTestCase,
):
pass
class RetainSchemaTest(oslo_test_base.BaseTestCase):
class RetainSchemaTest(test_base.BaseTestCase):
DRIVER = "sqlite"
def setUp(self):
@ -222,7 +224,7 @@ class PostgresqlRetainSchemaTest(RetainSchemaTest):
DRIVER = "postgresql"
class AdHocURLTest(oslo_test_base.BaseTestCase):
class AdHocURLTest(test_base.BaseTestCase):
def test_sqlite_setup_teardown(self):
fixture = test_fixtures.AdHocDbFixture("sqlite:///foo.db")

View File

@ -23,7 +23,6 @@ from unittest import mock
import fixtures
from oslo_config import cfg
from oslotest import base as oslo_test
import sqlalchemy
from sqlalchemy import Column, MetaData, Table
from sqlalchemy.engine import url
@ -36,7 +35,8 @@ from oslo_db.sqlalchemy import enginefacade
from oslo_db.sqlalchemy import engines
from oslo_db.sqlalchemy import models
from oslo_db.sqlalchemy import session
from oslo_db.tests.sqlalchemy import base as test_base
from oslo_db.tests import base as test_base
from oslo_db.tests.sqlalchemy import base as db_test_base
BASE = declarative_base()
@ -51,7 +51,7 @@ class RegexpTable(BASE, models.ModelBase):
bar = Column(String(255))
class RegexpFilterTestCase(test_base._DbTestCase):
class RegexpFilterTestCase(db_test_base._DbTestCase):
def setUp(self):
super(RegexpFilterTestCase, self).setUp()
@ -65,8 +65,8 @@ class RegexpFilterTestCase(test_base._DbTestCase):
self.addCleanup(test_table.drop)
def _test_regexp_filter(self, regexp, expected):
with enginefacade.writer.using(test_base.context):
_session = test_base.context.session
with enginefacade.writer.using(db_test_base.context):
_session = db_test_base.context.session
for i in ['10', '20', '']:
tbl = RegexpTable()
tbl.update({'bar': i})
@ -89,7 +89,7 @@ class RegexpFilterTestCase(test_base._DbTestCase):
self._test_regexp_filter('', [])
class SQLiteSavepointTest(test_base._DbTestCase):
class SQLiteSavepointTest(db_test_base._DbTestCase):
def setUp(self):
super(SQLiteSavepointTest, self).setUp()
meta = MetaData()
@ -202,7 +202,7 @@ class ProgrammingError(Exception):
pass
class QueryParamTest(test_base.DbTestCase):
class QueryParamTest(db_test_base.DbTestCase):
def _fixture(self):
from sqlalchemy import create_engine
@ -285,7 +285,7 @@ class QueryParamTest(test_base.DbTestCase):
)
class MySQLDefaultModeTestCase(test_base._MySQLOpportunisticTestCase):
class MySQLDefaultModeTestCase(db_test_base._MySQLOpportunisticTestCase):
def test_default_is_traditional(self):
with self.engine.connect() as conn:
sql_mode = conn.execute(
@ -295,7 +295,7 @@ class MySQLDefaultModeTestCase(test_base._MySQLOpportunisticTestCase):
self.assertIn("TRADITIONAL", sql_mode)
class MySQLModeTestCase(test_base._MySQLOpportunisticTestCase):
class MySQLModeTestCase(db_test_base._MySQLOpportunisticTestCase):
def __init__(self, *args, **kwargs):
super(MySQLModeTestCase, self).__init__(*args, **kwargs)
@ -364,7 +364,7 @@ class MySQLTraditionalModeTestCase(MySQLStrictAllTablesModeTestCase):
self.mysql_mode = 'TRADITIONAL'
class EngineFacadeTestCase(oslo_test.BaseTestCase):
class EngineFacadeTestCase(test_base.BaseTestCase):
def setUp(self):
super(EngineFacadeTestCase, self).setUp()
@ -470,7 +470,7 @@ class EngineFacadeTestCase(oslo_test.BaseTestCase):
self.assertEqual(master_path, str(slave_session.bind.url))
class SQLiteConnectTest(oslo_test.BaseTestCase):
class SQLiteConnectTest(test_base.BaseTestCase):
def _fixture(self, **kw):
return session.create_engine("sqlite://", **kw)
@ -507,7 +507,7 @@ class SQLiteConnectTest(oslo_test.BaseTestCase):
)
class MysqlConnectTest(test_base._MySQLOpportunisticTestCase):
class MysqlConnectTest(db_test_base._MySQLOpportunisticTestCase):
def _fixture(self, sql_mode):
return session.create_engine(self.engine.url, mysql_sql_mode=sql_mode)
@ -627,7 +627,7 @@ class MysqlConnectTest(test_base._MySQLOpportunisticTestCase):
log.output)
class CreateEngineTest(oslo_test.BaseTestCase):
class CreateEngineTest(test_base.BaseTestCase):
"""Test that dialect-specific arguments/ listeners are set up correctly.
"""
@ -781,7 +781,7 @@ class CreateEngineTest(oslo_test.BaseTestCase):
)
class ProcessGuardTest(test_base._DbTestCase):
class ProcessGuardTest(db_test_base._DbTestCase):
def test_process_guard(self):
self.engine.dispose()
@ -809,7 +809,7 @@ class ProcessGuardTest(test_base._DbTestCase):
self.assertEqual(new_dbapi_id, newer_dbapi_id)
class PatchStacktraceTest(test_base._DbTestCase):
class PatchStacktraceTest(db_test_base._DbTestCase):
def test_trace(self):
engine = self.engine

View File

@ -11,14 +11,14 @@
# under the License.
from oslotest import base as oslo_test_base
from sqlalchemy.ext import declarative
from sqlalchemy import schema
from sqlalchemy import sql
from sqlalchemy import types as sqltypes
from oslo_db.sqlalchemy import update_match
from oslo_db.tests.sqlalchemy import base as test_base
from oslo_db.tests import base as test_base
from oslo_db.tests.sqlalchemy import base as db_test_base
Base = declarative.declarative_base()
@ -33,7 +33,7 @@ class MyModel(Base):
z = schema.Column(sqltypes.String(40))
class ManufactureCriteriaTest(oslo_test_base.BaseTestCase):
class ManufactureCriteriaTest(test_base.BaseTestCase):
def test_instance_criteria_basic(self):
specimen = MyModel(
y='y1', z='z3',
@ -85,7 +85,7 @@ class ManufactureCriteriaTest(oslo_test_base.BaseTestCase):
)
class UpdateMatchTest(test_base._DbTestCase):
class UpdateMatchTest(db_test_base._DbTestCase):
def setUp(self):
super(UpdateMatchTest, self).setUp()
Base.metadata.create_all(self.engine)
@ -434,12 +434,14 @@ class UpdateMatchTest(test_base._DbTestCase):
class PGUpdateMatchTest(
UpdateMatchTest,
test_base._PostgreSQLOpportunisticTestCase):
UpdateMatchTest,
db_test_base._PostgreSQLOpportunisticTestCase,
):
pass
class MySQLUpdateMatchTest(
UpdateMatchTest,
test_base._MySQLOpportunisticTestCase):
UpdateMatchTest,
db_test_base._MySQLOpportunisticTestCase,
):
pass

View File

@ -17,7 +17,6 @@ from unittest import mock
from urllib import parse
import fixtures
from oslotest import base as test_base
import sqlalchemy
from sqlalchemy.dialects import mysql
from sqlalchemy import Boolean, Index, Integer, DateTime, String
@ -42,9 +41,8 @@ from oslo_db.sqlalchemy import models
from oslo_db.sqlalchemy import provision
from oslo_db.sqlalchemy import session
from oslo_db.sqlalchemy import utils
from oslo_db.tests import base as test_base
from oslo_db.tests.sqlalchemy import base as db_test_base
from oslo_db.tests import utils as test_utils
Base = declarative_base()
@ -1073,7 +1071,7 @@ class MySQLTestMigrations(TestMigrationUtils,
pass
class TestConnectionUtils(test_utils.BaseTestCase):
class TestConnectionUtils(test_base.BaseTestCase):
def setUp(self):
super(TestConnectionUtils, self).setUp()

View File

@ -22,7 +22,7 @@ from oslo_utils import importutils
from oslo_db import api
from oslo_db import exception
from oslo_db.tests import utils as test_utils
from oslo_db.tests import base as test_base
sqla = importutils.try_import('sqlalchemy')
if not sqla:
@ -65,7 +65,8 @@ class DBAPI(object):
return args, kwargs
class DBAPITestCase(test_utils.BaseTestCase):
class DBAPITestCase(test_base.BaseTestCase):
def test_dbapi_full_path_module_method(self):
dbapi = api.DBAPI('oslo_db.tests.test_api')
result = dbapi.api_class_call1(1, 2, kwarg1='meow')
@ -91,8 +92,9 @@ class DBAPITestCase(test_utils.BaseTestCase):
class DBReconnectTestCase(DBAPITestCase):
def setUp(self):
super(DBReconnectTestCase, self).setUp()
super().setUp()
self.test_db_api = DBAPI()
patcher = mock.patch(__name__ + '.get_backend',
@ -200,6 +202,7 @@ class DBReconnectTestCase(DBAPITestCase):
class DBRetryRequestCase(DBAPITestCase):
def test_retry_wrapper_succeeds(self):
@api.wrap_db_retry(max_retries=10)
def some_method():
@ -294,6 +297,7 @@ class DBRetryRequestCase(DBAPITestCase):
x = api.wrap_db_retry(max_retries=5, retry_on_deadlock=True,
max_retry_interval=11)
self.assertEqual(11, x.max_retry_interval)
for i in (1, 2, 4):
# With jitter: sleep_time = [0, 2 ** retry_times)
sleep_time, n = x._get_inc_interval(i, True)
@ -303,6 +307,7 @@ class DBRetryRequestCase(DBAPITestCase):
sleep_time, n = x._get_inc_interval(i, False)
self.assertEqual(2 * i, n)
self.assertEqual(2 * i, sleep_time)
for i in (8, 16, 32):
sleep_time, n = x._get_inc_interval(i, False)
self.assertEqual(x.max_retry_interval, sleep_time)

View File

@ -19,12 +19,12 @@ from unittest import mock
from oslo_config import fixture as config_fixture
from oslo_db import concurrency
from oslo_db.tests import utils as test_utils
from oslo_db.tests import base as test_base
FAKE_BACKEND_MAPPING = {'sqlalchemy': 'fake.db.sqlalchemy.api'}
class TpoolDbapiWrapperTestCase(test_utils.BaseTestCase):
class TpoolDbapiWrapperTestCase(test_base.BaseTestCase):
def setUp(self):
super(TpoolDbapiWrapperTestCase, self).setUp()

View File

@ -15,15 +15,8 @@
import contextlib
from oslotest import base as test_base
@contextlib.contextmanager
def nested(*contexts):
with contextlib.ExitStack() as stack:
yield [stack.enter_context(c) for c in contexts]
# TODO(stephenfin): Remove as this is no longer necessary
class BaseTestCase(test_base.BaseTestCase):
pass