summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--oslo_db/exception.py11
-rw-r--r--oslo_db/sqlalchemy/enginefacade.py2
-rw-r--r--oslo_db/sqlalchemy/engines.py28
-rw-r--r--oslo_db/sqlalchemy/exc_filters.py89
-rw-r--r--oslo_db/sqlalchemy/provision.py10
-rw-r--r--oslo_db/sqlalchemy/test_base.py204
-rw-r--r--oslo_db/sqlalchemy/test_fixtures.py8
-rw-r--r--oslo_db/sqlalchemy/utils.py63
-rw-r--r--oslo_db/tests/sqlalchemy/base.py31
-rw-r--r--oslo_db/tests/sqlalchemy/test_exc_filters.py11
-rw-r--r--oslo_db/tests/sqlalchemy/test_fixtures.py97
-rw-r--r--oslo_db/tests/sqlalchemy/test_sqlalchemy.py2
-rw-r--r--oslo_db/tests/sqlalchemy/test_utils.py18
-rw-r--r--oslo_db/tests/test_api.py6
-rw-r--r--releasenotes/notes/remove-base-test-classes-557889ec4f072781.yaml24
15 files changed, 82 insertions, 522 deletions
diff --git a/oslo_db/exception.py b/oslo_db/exception.py
index 2db34ef..3c123cd 100644
--- a/oslo_db/exception.py
+++ b/oslo_db/exception.py
@@ -43,11 +43,9 @@ with `try/except` statement. This is required for consistent handling of
database errors.
"""
-from debtcollector import moves
from oslo_utils.excutils import CausedByException
from oslo_db._i18n import _
-from oslo_db import warning
class DBError(CausedByException):
@@ -287,12 +285,3 @@ class ContextNotRequestedError(AttributeError):
class CantStartEngineError(Exception):
"""Error raised when the enginefacade cannot start up correctly."""
-
-
-moves.moved_class(warning.NotSupportedWarning,
- 'NotSupportedWarning',
- __name__, version='Stein')
-
-moves.moved_class(warning.OsloDBDeprecationWarning,
- 'OsloDBDeprecationWarning',
- __name__, version='Stein')
diff --git a/oslo_db/sqlalchemy/enginefacade.py b/oslo_db/sqlalchemy/enginefacade.py
index 39fb061..c01c230 100644
--- a/oslo_db/sqlalchemy/enginefacade.py
+++ b/oslo_db/sqlalchemy/enginefacade.py
@@ -553,7 +553,7 @@ class _TestTransactionFactory(_TransactionFactory):
Note that while this is used by oslo.db's own tests of
the enginefacade system, it is also exported for use by
the test suites of other projects, first as an element of the
- oslo_db.sqlalchemy.test_base module, and secondly may be used by
+ oslo_db.sqlalchemy.test_fixtures module, and secondly may be used by
external test suites directly.
Includes a feature to inject itself temporarily as the factory
diff --git a/oslo_db/sqlalchemy/engines.py b/oslo_db/sqlalchemy/engines.py
index 7c36c8a..847c71a 100644
--- a/oslo_db/sqlalchemy/engines.py
+++ b/oslo_db/sqlalchemy/engines.py
@@ -22,7 +22,6 @@ import logging
import os
import re
import time
-from urllib import parse
import debtcollector.removals
import debtcollector.renames
@@ -130,31 +129,6 @@ def _setup_logging(connection_debug=0):
logger.setLevel(logging.WARNING)
-def _extend_url_parameters(url, connection_parameters):
- # TODO(zzzeek): remove hasattr() conditional when SQLAlchemy 1.4 is the
- # minimum version in requirements; call update_query_string()
- # unconditionally
- if hasattr(url, "update_query_string"):
- return url.update_query_string(connection_parameters, append=True)
-
- # TODO(zzzeek): remove the remainder of this method when SQLAlchemy 1.4
- # is the minimum version in requirements
- for key, value in parse.parse_qs(
- connection_parameters).items():
- if key in url.query:
- existing = url.query[key]
- if not isinstance(existing, list):
- url.query[key] = existing = utils.to_list(existing)
- existing.extend(value)
- value = existing
- else:
- url.query[key] = value
- if len(value) == 1:
- url.query[key] = value[0]
-
- return url
-
-
def _vet_url(url):
if "+" not in url.drivername and not url.drivername.startswith("sqlite"):
if url.drivername.startswith("mysql"):
@@ -201,7 +175,7 @@ def create_engine(sql_connection, sqlite_fk=False, mysql_sql_mode=None,
url = utils.make_url(sql_connection)
if connection_parameters:
- url = _extend_url_parameters(url, connection_parameters)
+ url = url.update_query_string(connection_parameters, append=True)
_vet_url(url)
diff --git a/oslo_db/sqlalchemy/exc_filters.py b/oslo_db/sqlalchemy/exc_filters.py
index 420b5c7..4ad7721 100644
--- a/oslo_db/sqlalchemy/exc_filters.py
+++ b/oslo_db/sqlalchemy/exc_filters.py
@@ -44,7 +44,7 @@ def filters(dbname, exception_type, regex):
"""
def _receive(fn):
_registry[dbname][exception_type].extend(
- (fn, re.compile(reg))
+ (fn, re.compile(reg, re.DOTALL))
for reg in
((regex,) if not isinstance(regex, tuple) else regex)
)
@@ -432,50 +432,51 @@ def handler(context):
dialect = compat.dialect_from_exception_context(context)
for per_dialect in _dialect_registries(dialect):
- for exc in (
- context.sqlalchemy_exception,
- context.original_exception):
+ for exc in (context.sqlalchemy_exception, context.original_exception):
for super_ in exc.__class__.__mro__:
- if super_ in per_dialect:
- regexp_reg = per_dialect[super_]
- for fn, regexp in regexp_reg:
- match = regexp.match(exc.args[0])
- if match:
- try:
- fn(
- exc,
- match,
- dialect.name,
- context.is_disconnect)
- except exception.DBError as dbe:
- if (
- context.connection is not None and
- not context.connection.closed and
- not context.connection.invalidated and
- ROLLBACK_CAUSE_KEY
- in context.connection.info
- ):
- dbe.cause = \
- context.connection.info.pop(
- ROLLBACK_CAUSE_KEY)
-
- if isinstance(
- dbe, exception.DBConnectionError):
- context.is_disconnect = True
-
- # new in 2.0.5
- if (
- hasattr(context, "is_pre_ping") and
- context.is_pre_ping
- ):
- # if this is a pre-ping, need to
- # integrate with the built
- # in pre-ping handler that doesnt know
- # about DBConnectionError, just needs
- # the updated status
- return None
-
- return dbe
+ if super_ not in per_dialect:
+ continue
+
+ regexp_reg = per_dialect[super_]
+ for fn, regexp in regexp_reg:
+ match = regexp.match(exc.args[0])
+ if not match:
+ continue
+
+ try:
+ fn(
+ exc,
+ match,
+ dialect.name,
+ context.is_disconnect,
+ )
+ except exception.DBError as dbe:
+ if (
+ context.connection is not None and
+ not context.connection.closed and
+ not context.connection.invalidated and
+ ROLLBACK_CAUSE_KEY in context.connection.info
+ ):
+ dbe.cause = context.connection.info.pop(
+ ROLLBACK_CAUSE_KEY,
+ )
+
+ if isinstance(dbe, exception.DBConnectionError):
+ context.is_disconnect = True
+
+ # new in 2.0.5
+ if (
+ hasattr(context, "is_pre_ping") and
+ context.is_pre_ping
+ ):
+ # if this is a pre-ping, need to
+ # integrate with the built
+ # in pre-ping handler that doesnt know
+ # about DBConnectionError, just needs
+ # the updated status
+ return None
+
+ return dbe
def register_engine(engine):
diff --git a/oslo_db/sqlalchemy/provision.py b/oslo_db/sqlalchemy/provision.py
index a6cc527..96e050c 100644
--- a/oslo_db/sqlalchemy/provision.py
+++ b/oslo_db/sqlalchemy/provision.py
@@ -493,15 +493,7 @@ class BackendImpl(object, metaclass=abc.ABCMeta):
"""
url = utils.make_url(base_url)
-
- # TODO(zzzeek): remove hasattr() conditional in favor of "url.set()"
- # when SQLAlchemy 1.4 is the minimum version in requirements
- if hasattr(url, "set"):
- url = url.set(database=ident)
- else:
- # TODO(zzzeek): remove when SQLAlchemy 1.4
- # is the minimum version in requirements
- url.database = ident
+ url = url.set(database=ident)
return url
diff --git a/oslo_db/sqlalchemy/test_base.py b/oslo_db/sqlalchemy/test_base.py
index b437c3c..c92e39e 100644
--- a/oslo_db/sqlalchemy/test_base.py
+++ b/oslo_db/sqlalchemy/test_base.py
@@ -15,192 +15,8 @@
import functools
-import debtcollector
-import debtcollector.moves
-import fixtures
-import testresources
-
-try:
- from oslotest import base as test_base
-except ImportError:
- raise NameError('Oslotest is not installed. Please add oslotest in your'
- ' test-requirements')
-
-
from oslo_utils import reflection
-from oslo_db import exception
-from oslo_db.sqlalchemy import enginefacade
-from oslo_db.sqlalchemy import provision
-from oslo_db.sqlalchemy import session
-
-
-@debtcollector.removals.removed_class(
- "DbFixture",
- message="Please use oslo_db.sqlalchemy.test_fixtures directly")
-class DbFixture(fixtures.Fixture):
- """Basic database fixture.
-
- Allows to run tests on various db backends, such as SQLite, MySQL and
- PostgreSQL. By default use sqlite backend. To override default backend
- uri set env variable OS_TEST_DBAPI_ADMIN_CONNECTION with database admin
- credentials for specific backend.
- """
-
- DRIVER = "sqlite"
-
- # these names are deprecated, and are not used by DbFixture.
- # they are here for backwards compatibility with test suites that
- # are referring to them directly.
- DBNAME = PASSWORD = USERNAME = 'openstack_citest'
-
- def __init__(self, test, skip_on_unavailable_db=True):
- super(DbFixture, self).__init__()
- self.test = test
- self.skip_on_unavailable_db = skip_on_unavailable_db
-
- def setUp(self):
- super(DbFixture, self).setUp()
-
- testresources.setUpResources(
- self.test, self.test.resources, testresources._get_result())
- self.addCleanup(
- testresources.tearDownResources,
- self.test, self.test.resources, testresources._get_result()
- )
-
- if not self.test._has_db_resource():
- msg = self.test._get_db_resource_not_available_reason()
- if self.test.SKIP_ON_UNAVAILABLE_DB:
- self.test.skipTest(msg)
- else:
- self.test.fail(msg)
-
- if self.test.SCHEMA_SCOPE:
- self.test.engine = self.test.transaction_engine
- self.test.sessionmaker = session.get_maker(
- self.test.transaction_engine)
- else:
- self.test.engine = self.test.db.engine
- self.test.sessionmaker = session.get_maker(self.test.engine)
-
- self.addCleanup(setattr, self.test, 'sessionmaker', None)
- self.addCleanup(setattr, self.test, 'engine', None)
-
- self.test.enginefacade = enginefacade._TestTransactionFactory(
- self.test.engine, self.test.sessionmaker, apply_global=True)
- self.addCleanup(self.test.enginefacade.dispose_global)
-
-
-@debtcollector.removals.removed_class(
- "DbTestCase",
- message="Please use oslo_db.sqlalchemy.test_fixtures directly")
-class DbTestCase(test_base.BaseTestCase):
- """Base class for testing of DB code.
-
- """
-
- FIXTURE = DbFixture
- SCHEMA_SCOPE = None
- SKIP_ON_UNAVAILABLE_DB = True
-
- _db_not_available = {}
- _schema_resources = {}
- _database_resources = {}
-
- def _get_db_resource_not_available_reason(self):
- return self._db_not_available.get(self.FIXTURE.DRIVER, None)
-
- def _has_db_resource(self):
- return self._database_resources.get(
- self.FIXTURE.DRIVER, None) is not None
-
- def _resources_for_driver(self, driver, schema_scope, generate_schema):
- # testresources relies on the identity and state of the
- # TestResourceManager objects in play to correctly manage
- # resources, and it also hardcodes to looking at the
- # ".resources" attribute on the test object, even though the
- # setUpResources() function passes the list of resources in,
- # so we have to code the TestResourceManager logic into the
- # .resources attribute and ensure that the same set of test
- # variables always produces the same TestResourceManager objects.
-
- if driver not in self._database_resources:
- try:
- self._database_resources[driver] = \
- provision.DatabaseResource(driver,
- provision_new_database=True)
- except exception.BackendNotAvailable as bne:
- self._database_resources[driver] = None
- self._db_not_available[driver] = str(bne)
-
- database_resource = self._database_resources[driver]
- if database_resource is None:
- return []
-
- if schema_scope:
- key = (driver, schema_scope)
- if key not in self._schema_resources:
- schema_resource = provision.SchemaResource(
- database_resource, generate_schema)
-
- transaction_resource = provision.TransactionResource(
- database_resource, schema_resource)
-
- self._schema_resources[key] = \
- transaction_resource
-
- transaction_resource = self._schema_resources[key]
-
- return [
- ('transaction_engine', transaction_resource),
- ('db', database_resource),
- ]
- else:
- key = (driver, None)
- if key not in self._schema_resources:
- self._schema_resources[key] = provision.SchemaResource(
- database_resource, generate_schema, teardown=True)
-
- schema_resource = self._schema_resources[key]
- return [
- ('schema', schema_resource),
- ('db', database_resource)
- ]
-
- @property
- def resources(self):
- return self._resources_for_driver(
- self.FIXTURE.DRIVER, self.SCHEMA_SCOPE, self.generate_schema)
-
- def setUp(self):
- super(DbTestCase, self).setUp()
- self.useFixture(
- self.FIXTURE(
- self, skip_on_unavailable_db=self.SKIP_ON_UNAVAILABLE_DB))
-
- def generate_schema(self, engine):
- """Generate schema objects to be used within a test.
-
- The function is separate from the setUp() case as the scope
- of this method is controlled by the provisioning system. A
- test that specifies SCHEMA_SCOPE may not call this method
- for each test, as the schema may be maintained from a previous run.
-
- """
- if self.SCHEMA_SCOPE:
- # if SCHEMA_SCOPE is set, then this method definitely
- # has to be implemented. This is a guard against a test
- # that inadvertently does schema setup within setUp().
- raise NotImplementedError(
- "This test requires schema-level setup to be "
- "implemented within generate_schema().")
-
-
-@debtcollector.removals.removed_class("OpportunisticTestCase")
-class OpportunisticTestCase(DbTestCase):
- """Placeholder for backwards compatibility."""
-
ALLOWED_DIALECTS = ['sqlite', 'mysql', 'postgresql']
@@ -226,23 +42,3 @@ def backend_specific(*dialects):
return f(self)
return ins_wrap
return wrap
-
-
-@debtcollector.removals.removed_class("MySQLOpportunisticFixture")
-class MySQLOpportunisticFixture(DbFixture):
- DRIVER = 'mysql'
-
-
-@debtcollector.removals.removed_class("PostgreSQLOpportunisticFixture")
-class PostgreSQLOpportunisticFixture(DbFixture):
- DRIVER = 'postgresql'
-
-
-@debtcollector.removals.removed_class("MySQLOpportunisticTestCase")
-class MySQLOpportunisticTestCase(OpportunisticTestCase):
- FIXTURE = MySQLOpportunisticFixture
-
-
-@debtcollector.removals.removed_class("PostgreSQLOpportunisticTestCase")
-class PostgreSQLOpportunisticTestCase(OpportunisticTestCase):
- FIXTURE = PostgreSQLOpportunisticFixture
diff --git a/oslo_db/sqlalchemy/test_fixtures.py b/oslo_db/sqlalchemy/test_fixtures.py
index f7157c0..c65cb07 100644
--- a/oslo_db/sqlalchemy/test_fixtures.py
+++ b/oslo_db/sqlalchemy/test_fixtures.py
@@ -546,9 +546,9 @@ def optimize_package_test_loader(file_):
The function is invoked as::
- from oslo_db.sqlalchemy import test_base
+ from oslo_db.sqlalchemy import test_fixtures
- load_tests = test_base.optimize_package_test_loader(__file__)
+ load_tests = test_fixtures.optimize_package_test_loader(__file__)
The loader *must* be present in the package level __init__.py.
@@ -586,9 +586,9 @@ def optimize_module_test_loader():
The function is invoked as::
- from oslo_db.sqlalchemy import test_base
+ from oslo_db.sqlalchemy import test_fixtures
- load_tests = test_base.optimize_module_test_loader()
+ load_tests = test_fixtures.optimize_module_test_loader()
The loader *must* be present in an individual module, and *not* the
package level __init__.py.
diff --git a/oslo_db/sqlalchemy/utils.py b/oslo_db/sqlalchemy/utils.py
index 58b2486..f8f57c4 100644
--- a/oslo_db/sqlalchemy/utils.py
+++ b/oslo_db/sqlalchemy/utils.py
@@ -29,8 +29,6 @@ import debtcollector.removals
from oslo_utils import timeutils
import sqlalchemy
from sqlalchemy import Boolean
-from sqlalchemy import CheckConstraint
-from sqlalchemy import Column
from sqlalchemy.engine import Connectable
from sqlalchemy.engine import url as sa_url
from sqlalchemy import exc
@@ -42,7 +40,6 @@ from sqlalchemy import MetaData
from sqlalchemy.sql.expression import cast
from sqlalchemy.sql.expression import literal_column
from sqlalchemy.sql import text
-from sqlalchemy import String
from sqlalchemy import Table
from oslo_db._i18n import _
@@ -443,23 +440,6 @@ def get_table(engine, name):
return Table(name, metadata, autoload_with=engine)
-def _get_not_supported_column(col_name_col_instance, column_name):
- try:
- column = col_name_col_instance[column_name]
- except KeyError:
- msg = _("Please specify column %s in col_name_col_instance "
- "param. It is required because column has unsupported "
- "type by SQLite.")
- raise exception.ColumnError(msg % column_name)
-
- if not isinstance(column, Column):
- msg = _("col_name_col_instance param has wrong type of "
- "column instance for column %s It should be instance "
- "of sqlalchemy.Column.")
- raise exception.ColumnError(msg % column_name)
- return column
-
-
def drop_old_duplicate_entries_from_table(engine, table_name,
use_soft_delete, *uc_column_names):
"""Drop all old rows having the same values for columns in uc_columns.
@@ -519,49 +499,6 @@ def drop_old_duplicate_entries_from_table(engine, table_name,
conn.execute(delete_statement)
-def _get_default_deleted_value(table):
- if isinstance(table.c.id.type, Integer):
- return 0
- if isinstance(table.c.id.type, String):
- return ""
- raise exception.ColumnError(_("Unsupported id columns type"))
-
-
-def _restore_indexes_on_deleted_columns(engine, table_name, indexes):
- table = get_table(engine, table_name)
-
- real_indexes = get_indexes(engine, table_name)
- existing_index_names = dict(
- [(index['name'], index['column_names']) for index in real_indexes])
-
- # NOTE(boris-42): Restore indexes on `deleted` column
- for index in indexes:
- if 'deleted' not in index['column_names']:
- continue
- name = index['name']
- if name in existing_index_names:
- column_names = [table.c[c] for c in existing_index_names[name]]
- old_index = Index(name, *column_names, unique=index["unique"])
- old_index.drop(engine)
-
- column_names = [table.c[c] for c in index['column_names']]
- new_index = Index(index["name"], *column_names, unique=index["unique"])
- new_index.create(engine)
-
-
-def _is_deleted_column_constraint(constraint):
- # NOTE(boris-42): There is no other way to check is CheckConstraint
- # associated with deleted column.
- if not isinstance(constraint, CheckConstraint):
- return False
- sqltext = str(constraint.sqltext)
- # NOTE(zzzeek): SQLite never reflected CHECK contraints here
- # in any case until version 1.1. Safe to assume that any CHECK
- # that's talking about the value of "deleted in (something)" is
- # the boolean constraint we're looking to get rid of.
- return bool(re.match(r".*deleted in \(.*\)", sqltext, re.I))
-
-
def get_db_connection_info(conn_pieces):
database = conn_pieces.path.strip('/')
loc_pieces = conn_pieces.netloc.split('@')
diff --git a/oslo_db/tests/sqlalchemy/base.py b/oslo_db/tests/sqlalchemy/base.py
index 80d9812..c66618a 100644
--- a/oslo_db/tests/sqlalchemy/base.py
+++ b/oslo_db/tests/sqlalchemy/base.py
@@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-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
@@ -29,35 +27,6 @@ class Context(object):
context = Context()
-@debtcollector.removals.removed_class(
- "DbTestCase",
- message="Do not import from oslo_db.tests! "
- "Please use oslo_db.sqlalchemy.test_fixtures directly")
-class DbTestCase(db_fixtures.OpportunisticDBTestMixin, test_base.BaseTestCase):
-
- def setUp(self):
- super(DbTestCase, self).setUp()
-
- self.engine = enginefacade.writer.get_engine()
- self.sessionmaker = enginefacade.writer.get_sessionmaker()
-
-
-@debtcollector.removals.removed_class(
- "MySQLOpportunisticTestCase",
- message="Do not import from oslo_db.tests! "
- "Please use oslo_db.sqlalchemy.test_fixtures directly")
-class MySQLOpportunisticTestCase(DbTestCase):
- FIXTURE = db_fixtures.MySQLOpportunisticFixture
-
-
-@debtcollector.removals.removed_class(
- "PostgreSQLOpportunisticTestCase",
- message="Do not import from oslo_db.tests! "
- "Please use oslo_db.sqlalchemy.test_fixtures directly")
-class PostgreSQLOpportunisticTestCase(DbTestCase):
- FIXTURE = db_fixtures.PostgresqlOpportunisticFixture
-
-
# NOTE (zzzeek) These test classes are **private to oslo.db**. Please
# make use of oslo_db.sqlalchemy.test_fixtures directly.
diff --git a/oslo_db/tests/sqlalchemy/test_exc_filters.py b/oslo_db/tests/sqlalchemy/test_exc_filters.py
index 796ba6c..816ef7e 100644
--- a/oslo_db/tests/sqlalchemy/test_exc_filters.py
+++ b/oslo_db/tests/sqlalchemy/test_exc_filters.py
@@ -416,16 +416,7 @@ class TestNonExistentDatabase(
super(TestNonExistentDatabase, self).setUp()
url = utils.make_url(self.engine.url)
-
- # TODO(zzzeek): remove hasattr() conditional in favor of "url.set()"
- # when SQLAlchemy 1.4 is the minimum version in requirements
- if hasattr(url, "set"):
- self.url = url.set(database="non_existent_database")
- else:
- # TODO(zzzeek): remove when SQLAlchemy 1.4
- # is the minimum version in requirements
- url.database = 'non_existent_database'
- self.url = url
+ self.url = url.set(database="non_existent_database")
def test_raise(self):
matched = self.assertRaises(
diff --git a/oslo_db/tests/sqlalchemy/test_fixtures.py b/oslo_db/tests/sqlalchemy/test_fixtures.py
index 72f4f93..eff5c7e 100644
--- a/oslo_db/tests/sqlalchemy/test_fixtures.py
+++ b/oslo_db/tests/sqlalchemy/test_fixtures.py
@@ -16,10 +16,8 @@ import testscenarios
import unittest
from unittest import mock
-from oslo_db import exception
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 oslo_db.tests import base as test_base
@@ -96,74 +94,6 @@ class BackendSkipTest(test_base.BaseTestCase):
str(ex)
)
- def test_skip_no_dbapi_legacy(self):
-
- class FakeDatabaseOpportunisticFixture(
- legacy_test_base.DbFixture,
- ):
- DRIVER = 'postgresql'
-
- class SomeTest(legacy_test_base.DbTestCase):
- FIXTURE = FakeDatabaseOpportunisticFixture
-
- def runTest(self):
- pass
-
- st = SomeTest()
-
- # patch in replacement lookup dictionaries to avoid
- # leaking from/to other tests
- with mock.patch(
- "oslo_db.sqlalchemy.provision."
- "Backend.backends_by_database_type", {
- "postgresql":
- provision.Backend("postgresql", "postgresql://")}):
- st._database_resources = {}
- st._db_not_available = {}
- st._schema_resources = {}
-
- with mock.patch(
- "sqlalchemy.create_engine",
- mock.Mock(side_effect=ImportError())):
-
- self.assertEqual([], st.resources)
-
- ex = self.assertRaises(
- self.skipException,
- st.setUp
- )
-
- self.assertEqual(
- "Backend 'postgresql' is unavailable: No DBAPI installed",
- str(ex)
- )
-
- def test_skip_no_such_backend_legacy(self):
-
- class FakeDatabaseOpportunisticFixture(
- legacy_test_base.DbFixture,
- ):
- DRIVER = 'postgresql+nosuchdbapi'
-
- class SomeTest(legacy_test_base.DbTestCase):
-
- FIXTURE = FakeDatabaseOpportunisticFixture
-
- def runTest(self):
- pass
-
- st = SomeTest()
-
- ex = self.assertRaises(
- self.skipException,
- st.setUp
- )
-
- self.assertEqual(
- "Backend 'postgresql+nosuchdbapi' is unavailable: No such backend",
- str(ex)
- )
-
class EnginefacadeIntegrationTest(test_base.BaseTestCase):
def test_db_fixture(self):
@@ -206,33 +136,6 @@ class EnginefacadeIntegrationTest(test_base.BaseTestCase):
self.assertFalse(normal_mgr._factory._started)
-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
- )
-
- def test_new_db_is_provisioned_by_default_mysql(self):
- self._test_new_db_is_provisioned_by_default(
- legacy_test_base.MySQLOpportunisticTestCase
- )
-
- def _test_new_db_is_provisioned_by_default(self, base_cls):
- try:
- provision.DatabaseResource(base_cls.FIXTURE.DRIVER)
- except exception.BackendNotAvailable:
- self.skipTest("Backend %s is not available" %
- base_cls.FIXTURE.DRIVER)
-
- class SomeTest(base_cls):
- def runTest(self):
- pass
- st = SomeTest()
-
- db_resource = dict(st.resources)['db']
- self.assertTrue(db_resource.provision_new_database)
-
-
class TestLoadHook(unittest.TestCase):
"""Test the 'load_tests' hook supplied by test_base.
diff --git a/oslo_db/tests/sqlalchemy/test_sqlalchemy.py b/oslo_db/tests/sqlalchemy/test_sqlalchemy.py
index 5f7b27f..aa66ae5 100644
--- a/oslo_db/tests/sqlalchemy/test_sqlalchemy.py
+++ b/oslo_db/tests/sqlalchemy/test_sqlalchemy.py
@@ -206,7 +206,7 @@ class ProgrammingError(Exception):
pass
-class QueryParamTest(db_test_base.DbTestCase):
+class QueryParamTest(db_test_base._DbTestCase):
def _fixture(self):
from sqlalchemy import create_engine
diff --git a/oslo_db/tests/sqlalchemy/test_utils.py b/oslo_db/tests/sqlalchemy/test_utils.py
index 059d015..94a52eb 100644
--- a/oslo_db/tests/sqlalchemy/test_utils.py
+++ b/oslo_db/tests/sqlalchemy/test_utils.py
@@ -19,7 +19,6 @@ from urllib import parse
import fixtures
import sqlalchemy
from sqlalchemy import Boolean, Index, Integer, DateTime, String
-from sqlalchemy import CheckConstraint
from sqlalchemy import MetaData, Table, Column
from sqlalchemy import ForeignKey, ForeignKeyConstraint
from sqlalchemy.dialects.postgresql import psycopg2
@@ -801,23 +800,6 @@ class TestMigrationUtils(db_test_base._DbTestCase):
for value in soft_deleted_values:
self.assertIn(value['id'], deleted_rows_ids)
- def test_detect_boolean_deleted_constraint_detection(self):
- table_name = 'abc'
- table = Table(table_name, self.meta,
- Column('id', Integer, primary_key=True),
- Column('deleted', Boolean(create_constraint=True)))
- ck = [
- const for const in table.constraints if
- isinstance(const, CheckConstraint)][0]
-
- self.assertTrue(utils._is_deleted_column_constraint(ck))
-
- self.assertFalse(
- utils._is_deleted_column_constraint(
- CheckConstraint("deleted > 5")
- )
- )
-
def test_get_foreign_key_constraint_name(self):
table_1 = Table('table_name_1', self.meta,
Column('id', Integer, primary_key=True),
diff --git a/oslo_db/tests/test_api.py b/oslo_db/tests/test_api.py
index 2540780..d45dce6 100644
--- a/oslo_db/tests/test_api.py
+++ b/oslo_db/tests/test_api.py
@@ -210,7 +210,8 @@ class DBRetryRequestCase(DBAPITestCase):
some_method()
- def test_retry_wrapper_reaches_limit(self):
+ @mock.patch('oslo_db.api.time.sleep', return_value=None)
+ def test_retry_wrapper_reaches_limit(self, mock_sleep):
max_retries = 2
@api.wrap_db_retry(max_retries=max_retries)
@@ -222,7 +223,8 @@ class DBRetryRequestCase(DBAPITestCase):
self.assertRaises(ValueError, some_method, res)
self.assertEqual(max_retries + 1, res['result'])
- def test_retry_wrapper_exception_checker(self):
+ @mock.patch('oslo_db.api.time.sleep', return_value=None)
+ def test_retry_wrapper_exception_checker(self, mock_sleep):
def exception_checker(exc):
return isinstance(exc, ValueError) and exc.args[0] < 5
diff --git a/releasenotes/notes/remove-base-test-classes-557889ec4f072781.yaml b/releasenotes/notes/remove-base-test-classes-557889ec4f072781.yaml
new file mode 100644
index 0000000..1fb1381
--- /dev/null
+++ b/releasenotes/notes/remove-base-test-classes-557889ec4f072781.yaml
@@ -0,0 +1,24 @@
+---
+upgrade:
+ - |
+ The following test fixtures and base test classes were deprecated and have
+ now been removed:
+
+ - ``oslo_db.sqlalchemy.test_base.DbFixture``
+ - ``oslo_db.sqlalchemy.test_base.DbTestCase``
+ - ``oslo_db.sqlalchemy.test_base.OpportunisticTestCase``
+ - ``oslo_db.sqlalchemy.test_base.MySQLOpportunisticFixture``
+ - ``oslo_db.sqlalchemy.test_base.PostgreSQLOpportunisticFixture``
+ - ``oslo_db.sqlalchemy.test_base.MySQLOpportunisticTestCase``
+ - ``oslo_db.sqlalchemy.test_base.PostgreSQLOpportunisticTestCase``
+
+ They have all been replaced by equivalent test fixtures and test class
+ mixins in ``oslo_db.sqlalchemy.test_fixtures``.
+
+ In addition, the following test cases were being inadvertently used
+ publicly despite being private to oslo.db. They were also deprecated and
+ have now been removed:
+
+ - ``oslo_db.tests.sqlalchemy.base.DbTestCase``
+ - ``oslo_db.tests.sqlalchemy.base.MySQLOpportunisticTestCase``
+ - ``oslo_db.tests.sqlalchemy.base.PostgreSQLOpportunisticTestCase``