diff --git a/refstack/tests/unit/test_migration.py b/refstack/tests/unit/test_migration.py new file mode 100644 index 00000000..6fdfb9b2 --- /dev/null +++ b/refstack/tests/unit/test_migration.py @@ -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) diff --git a/refstack/tests/unit/tests.py b/refstack/tests/unit/tests.py deleted file mode 100644 index 2b2202f2..00000000 --- a/refstack/tests/unit/tests.py +++ /dev/null @@ -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() diff --git a/test-requirements.txt b/test-requirements.txt index f79db9af..3106314a 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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 diff --git a/tox.ini b/tox.ini index da707424..3e37dbf5 100644 --- a/tox.ini +++ b/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]