summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2022-02-04 17:35:09 +0000
committerStephen Finucane <stephenfin@redhat.com>2022-02-04 19:23:05 +0000
commita6887c13ea75cbd3a09abab3dbcfe194637b3ed0 (patch)
tree347cb9217653f7e02f076b38ef5e92f9ca4dff16
parent3b24c79331613d753e7157c58a531b707eea9161 (diff)
downloadkeystone-a6887c13ea75cbd3a09abab3dbcfe194637b3ed0.tar.gz
sql: Remove dead helpers
'assertTableCountsMatch' should have been removed in change I41584c652ab34a267009136ee2a2e159ee2f2a6e ("sql: Squash mitaka migrations") 'does_constraint_exist' should have been removed in change Ic499a996e1b9c6f0a9d885b4a9e655008002d49f ("sql: Squash queens migrations") 'does_pk_exist' should have been removed in change I6beb8c9c827546757f2d7673a917b98f8b917012 ("sql: Squash rocky migrations") 'assertTableExists' should have been removed in change I58e4b6833036a25ea8a1202c87ceebdbe932b447 ("sql: Squash stein migrations") 'insert_dict', 'does_index_exist', and 'does_unique_constraint_exist' should have been removed in change Ifc71efb8609bc26ce998a9fa48b207abf8b9a38b ("sql: Squash train migrations") 'does_fk_exist' should have been removed in change Ia1495cd4683d6631be2691e816734d01b03037a3 ("sql: Squash ussuri migrations") Change-Id: Id3d2769af6004bd4d4792c4488ac5eba94a5a776 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
-rw-r--r--keystone/tests/unit/test_sql_upgrade.py70
1 files changed, 1 insertions, 69 deletions
diff --git a/keystone/tests/unit/test_sql_upgrade.py b/keystone/tests/unit/test_sql_upgrade.py
index 09c99dcb0..12871d40b 100644
--- a/keystone/tests/unit/test_sql_upgrade.py
+++ b/keystone/tests/unit/test_sql_upgrade.py
@@ -52,7 +52,6 @@ from oslo_log import fixture as log_fixture
from oslo_log import log
from oslotest import base as test_base
import sqlalchemy.exc
-from sqlalchemy import inspect
from keystone.cmd import cli
from keystone.common import sql
@@ -335,17 +334,9 @@ class MigrateBase(
return sqlalchemy.MetaData(self.engine)
def load_table(self, name):
- table = sqlalchemy.Table(name,
- self.metadata,
- autoload=True)
+ table = sqlalchemy.Table(name, self.metadata, autoload=True)
return table
- def assertTableExists(self, table_name):
- try:
- self.load_table(table_name)
- except sqlalchemy.exc.NoSuchTableError:
- raise AssertionError('Table "%s" does not exist' % table_name)
-
def assertTableDoesNotExist(self, table_name):
"""Assert that a given table exists cannot be selected by name."""
# Switch to a different metadata otherwise you might still
@@ -357,22 +348,6 @@ class MigrateBase(
else:
raise AssertionError('Table "%s" already exists' % table_name)
- def calc_table_row_count(self, table_name):
- """Return the number of rows in the table."""
- t = sqlalchemy.Table(table_name, self.metadata, autoload=True)
- session = self.sessionmaker()
- row_count = session.query(
- sqlalchemy.func.count('*')).select_from(t).scalar()
- return row_count
-
- def assertTableCountsMatch(self, table1_name, table2_name):
- table1_count = self.calc_table_row_count(table1_name)
- table2_count = self.calc_table_row_count(table2_name)
- if table1_count != table2_count:
- raise AssertionError('Table counts do not match: {0} ({1}), {2} '
- '({3})'.format(table1_name, table1_count,
- table2_name, table2_count))
-
def assertTableColumns(self, table_name, expected_cols):
"""Assert that the table contains the expected set of columns."""
table = self.load_table(table_name)
@@ -382,49 +357,6 @@ class MigrateBase(
self.assertCountEqual(expected_cols, actual_cols,
'%s table' % table_name)
- def insert_dict(self, session, table_name, d, table=None):
- """Naively inserts key-value pairs into a table, given a dictionary."""
- if table is None:
- this_table = sqlalchemy.Table(table_name, self.metadata,
- autoload=True)
- else:
- this_table = table
- insert = this_table.insert().values(**d)
- session.execute(insert)
-
- def does_pk_exist(self, table, pk_column):
- """Check whether a column is primary key on a table."""
- inspector = inspect(self.engine)
- pk_columns = inspector.get_pk_constraint(table)['constrained_columns']
-
- return pk_column in pk_columns
-
- def does_fk_exist(self, table, fk_column):
- inspector = inspect(self.engine)
- for fk in inspector.get_foreign_keys(table):
- if fk_column in fk['constrained_columns']:
- return True
- return False
-
- def does_constraint_exist(self, table_name, constraint_name):
- table = sqlalchemy.Table(table_name, self.metadata, autoload=True)
- return constraint_name in [con.name for con in table.constraints]
-
- def does_index_exist(self, table_name, index_name):
- table = sqlalchemy.Table(table_name, self.metadata, autoload=True)
- return index_name in [idx.name for idx in table.indexes]
-
- def does_unique_constraint_exist(self, table_name, column_names):
- inspector = inspect(self.engine)
- constraints = inspector.get_unique_constraints(table_name)
- for c in constraints:
- if (len(c['column_names']) == 1 and
- column_names in c['column_names']):
- return True
- if (len(c['column_names'])) > 1 and isinstance(column_names, list):
- return set(c['column_names']) == set(column_names)
- return False
-
class ExpandSchemaUpgradeTests(MigrateBase):