Add test verifying that migrations are in sync with models
This commit is contained in:
parent
2fee0f55d9
commit
74071b6407
|
@ -8,6 +8,7 @@ coverage>=3.6
|
||||||
discover
|
discover
|
||||||
python-subunit>=0.0.18
|
python-subunit>=0.0.18
|
||||||
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
|
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
|
||||||
|
oslo.db[fixtures]
|
||||||
oslosphinx>=2.5.0 # Apache-2.0
|
oslosphinx>=2.5.0 # Apache-2.0
|
||||||
oslotest>=1.10.0 # Apache-2.0
|
oslotest>=1.10.0 # Apache-2.0
|
||||||
testrepository>=0.0.18
|
testrepository>=0.0.18
|
||||||
|
|
|
@ -20,6 +20,7 @@ from tuning_box import db
|
||||||
config = context.config
|
config = context.config
|
||||||
if config.get_main_option('table_prefix') is None:
|
if config.get_main_option('table_prefix') is None:
|
||||||
config.set_main_option('table_prefix', '')
|
config.set_main_option('table_prefix', '')
|
||||||
|
if config.config_file_name:
|
||||||
logging.config.fileConfig(config.config_file_name)
|
logging.config.fileConfig(config.config_file_name)
|
||||||
target_metadata = db.db.metadata
|
target_metadata = db.db.metadata
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,22 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
_fd, _sqlite_db_file_name = tempfile.mkstemp()
|
||||||
|
os.close(_fd)
|
||||||
|
del _fd
|
||||||
|
|
||||||
|
# oslo_db internals refuse to work properly if this is not set
|
||||||
|
os.environ["OS_TEST_DBAPI_ADMIN_CONNECTION"] = \
|
||||||
|
"sqlite:///" + _sqlite_db_file_name
|
||||||
|
|
||||||
|
from alembic import command as alembic_command
|
||||||
|
from alembic import config as alembic_config
|
||||||
import flask
|
import flask
|
||||||
|
from oslo_db.sqlalchemy import test_base
|
||||||
|
from oslo_db.sqlalchemy import test_migrations
|
||||||
|
|
||||||
from tuning_box import db
|
from tuning_box import db
|
||||||
from tuning_box.tests import base
|
from tuning_box.tests import base
|
||||||
|
@ -93,3 +108,28 @@ class TestEnvironmentHierarchyLevel(_DBTestCase):
|
||||||
class TestEnvironmentHierarchyLevelPrefixed(base.PrefixedTestCaseMixin,
|
class TestEnvironmentHierarchyLevelPrefixed(base.PrefixedTestCaseMixin,
|
||||||
TestEnvironmentHierarchyLevel):
|
TestEnvironmentHierarchyLevel):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TestMigrationsSync(test_migrations.ModelsMigrationsSync,
|
||||||
|
base.TestCase,
|
||||||
|
test_base.DbTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super(TestMigrationsSync, self).setUp()
|
||||||
|
self.addCleanup(os.remove, _sqlite_db_file_name)
|
||||||
|
|
||||||
|
def get_metadata(self):
|
||||||
|
return db.db.metadata
|
||||||
|
|
||||||
|
def get_engine(self):
|
||||||
|
return self.engine
|
||||||
|
|
||||||
|
def get_alembic_config(self, engine):
|
||||||
|
config = alembic_config.Config()
|
||||||
|
config.set_main_option('sqlalchemy.url', str(engine.url))
|
||||||
|
config.set_main_option('script_location', 'tuning_box/migrations')
|
||||||
|
config.set_main_option('version_table', 'alembic_version')
|
||||||
|
return config
|
||||||
|
|
||||||
|
def db_sync(self, engine):
|
||||||
|
config = self.get_alembic_config(engine)
|
||||||
|
alembic_command.upgrade(config, 'head')
|
||||||
|
|
Loading…
Reference in New Issue