Increase test coverage for database migration
Change-Id: If091d16827beccc82878eb1478ec2bff349cb58a
This commit is contained in:
parent
eabbe08cb0
commit
05e0433f10
83
refstack/tests/unit/test_migration.py
Normal file
83
refstack/tests/unit/test_migration.py
Normal file
@ -0,0 +1,83 @@
|
||||
# Copyright (c) 2015 Mirantis, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Tests for refstack's migrations."""
|
||||
|
||||
import alembic
|
||||
import mock
|
||||
from oslotest import base
|
||||
|
||||
from refstack.db import migration
|
||||
|
||||
|
||||
class MigrationTestCase(base.BaseTestCase):
|
||||
"""Test case for alembic's migrations API."""
|
||||
|
||||
def setUp(self):
|
||||
super(MigrationTestCase, self).setUp()
|
||||
self.config_patcher = mock.patch(
|
||||
'refstack.db.migrations.alembic.migration._alembic_config')
|
||||
self.config = self.config_patcher.start()
|
||||
self.config.return_value = 'fake_config'
|
||||
self.addCleanup(self.config_patcher.stop)
|
||||
|
||||
@mock.patch.object(alembic.migration.MigrationContext, 'configure',
|
||||
mock.Mock())
|
||||
def test_version(self):
|
||||
context = mock.Mock()
|
||||
context.get_current_revision = mock.Mock()
|
||||
alembic.migration.MigrationContext.configure.return_value = context
|
||||
with mock.patch('refstack.db.sqlalchemy.api.get_engine') as get_engine:
|
||||
engine = mock.Mock()
|
||||
engine.connect = mock.MagicMock()
|
||||
get_engine.return_value = engine
|
||||
migration.version()
|
||||
context.get_current_revision.assert_called_once_with()
|
||||
engine.connect.assert_called_once_with()
|
||||
|
||||
@mock.patch('alembic.command.upgrade')
|
||||
def test_upgrade(self, upgrade):
|
||||
migration.upgrade('some_revision')
|
||||
upgrade.assert_called_once_with('fake_config', 'some_revision')
|
||||
|
||||
@mock.patch('alembic.command.upgrade')
|
||||
def test_upgrade_without_revision(self, upgrade):
|
||||
migration.upgrade(None)
|
||||
upgrade.assert_called_once_with('fake_config', 'head')
|
||||
|
||||
@mock.patch('alembic.command.downgrade')
|
||||
def test_downgrade(self, downgrade):
|
||||
migration.downgrade('some_revision')
|
||||
downgrade.assert_called_once_with('fake_config', 'some_revision')
|
||||
|
||||
@mock.patch('alembic.command.downgrade')
|
||||
def test_downgrade_without_revision(self, downgrade):
|
||||
migration.downgrade(None)
|
||||
downgrade.assert_called_once_with('fake_config', 'base')
|
||||
|
||||
@mock.patch('alembic.command.stamp')
|
||||
def test_stamp(self, stamp):
|
||||
migration.stamp('some_revision')
|
||||
stamp.assert_called_once_with('fake_config', 'some_revision')
|
||||
|
||||
@mock.patch('alembic.command.stamp')
|
||||
def test_stamp_without_revision(self, stamp):
|
||||
migration.stamp(None)
|
||||
stamp.assert_called_once_with('fake_config', 'head')
|
||||
|
||||
@mock.patch('alembic.command.revision')
|
||||
def test_revision(self, revision):
|
||||
migration.revision('some_message', True)
|
||||
revision.assert_called_once_with('fake_config', 'some_message', True)
|
@ -1,24 +0,0 @@
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
import unittest
|
||||
|
||||
|
||||
class TestSequenceFunctions(unittest.TestCase):
|
||||
|
||||
def test_nothing(self):
|
||||
# make sure the shuffled sequence does not lose any elements
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@ -1,6 +1,7 @@
|
||||
pep8==1.5.7
|
||||
pyflakes==0.8.1
|
||||
flake8==2.2.4
|
||||
mock
|
||||
oslotest>=1.2.0 # Apache-2.0
|
||||
python-subunit>=0.0.18
|
||||
testrepository>=0.0.18
|
||||
|
2
tox.ini
2
tox.ini
@ -15,7 +15,7 @@ setenv = VIRTUAL_ENV={envdir}
|
||||
LC_ALL=C
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
commands = python setup.py testr --testr-args='{posargs}'
|
||||
commands = python setup.py testr --slowest --testr-args='{posargs}'
|
||||
distribute = false
|
||||
|
||||
[testenv:py27-func-mysql]
|
||||
|
Loading…
Reference in New Issue
Block a user