Coverage for manila/tests/db/test_migration.py: 100%
46 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright 2014 Mirantis Inc.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
16from unittest import mock
18import alembic
20from manila.db import migration
21from manila import test
24class MigrationTestCase(test.TestCase):
25 def setUp(self):
26 super(MigrationTestCase, self).setUp()
27 self.config_patcher = mock.patch(
28 'manila.db.migrations.alembic.migration._alembic_config')
29 self.config = self.config_patcher.start()
30 self.config.return_value = 'fake_config'
31 self.addCleanup(self.config_patcher.stop)
33 @mock.patch('alembic.command.upgrade')
34 def test_upgrade(self, upgrade):
35 migration.upgrade('version_1')
36 upgrade.assert_called_once_with('fake_config', 'version_1')
38 @mock.patch('alembic.command.upgrade')
39 def test_upgrade_none_version(self, upgrade):
40 migration.upgrade(None)
41 upgrade.assert_called_once_with('fake_config', 'head')
43 @mock.patch('alembic.command.downgrade')
44 def test_downgrade(self, downgrade):
45 migration.downgrade('version_1')
46 downgrade.assert_called_once_with('fake_config', 'version_1')
48 @mock.patch('alembic.command.downgrade')
49 def test_downgrade_none_version(self, downgrade):
50 migration.downgrade(None)
51 downgrade.assert_called_once_with('fake_config', 'base')
53 @mock.patch('alembic.command.stamp')
54 def test_stamp(self, stamp):
55 migration.stamp('version_1')
56 stamp.assert_called_once_with('fake_config', 'version_1')
58 @mock.patch('alembic.command.stamp')
59 def test_stamp_none_version(self, stamp):
60 migration.stamp(None)
61 stamp.assert_called_once_with('fake_config', 'head')
63 @mock.patch('alembic.command.revision')
64 def test_revision(self, revision):
65 migration.revision('test_message', 'autogenerate_value')
66 revision.assert_called_once_with('fake_config', 'test_message',
67 'autogenerate_value')
69 @mock.patch.object(alembic.migration.MigrationContext, 'configure',
70 mock.Mock())
71 def test_version(self):
72 context = mock.Mock()
73 context.get_current_revision = mock.Mock()
74 alembic.migration.MigrationContext.configure.return_value = context
75 migration.version()
76 context.get_current_revision.assert_called_once_with()