Merge "Change identifiers in data migration tests"

This commit is contained in:
Jenkins
2017-02-28 22:42:58 +00:00
committed by Gerrit Code Review
@@ -96,76 +96,76 @@ class TestDataMigrationFramework(test_utils.BaseTestCase):
@mock.patch('pkgutil.iter_modules')
def test_find_migrations(self, mock_iter, mock_import):
def fake_iter_modules(blah):
yield 'blah', 'ocata01', 'blah'
yield 'blah', 'ocata02', 'blah'
yield 'blah', 'pike01', 'blah'
yield 'blah', 'newton', 'blah'
yield 'blah', 'mitaka456', 'blah'
yield 'blah', 'zebra01', 'blah'
yield 'blah', 'zebra02', 'blah'
yield 'blah', 'yellow01', 'blah'
yield 'blah', 'xray01', 'blah'
yield 'blah', 'wrinkle01', 'blah'
mock_iter.side_effect = fake_iter_modules
ocata1 = mock.Mock()
ocata1.has_migrations.return_value = mock.Mock()
ocata1.migrate.return_value = mock.Mock()
ocata2 = mock.Mock()
ocata2.has_migrations.return_value = mock.Mock()
ocata2.migrate.return_value = mock.Mock()
zebra1 = mock.Mock()
zebra1.has_migrations.return_value = mock.Mock()
zebra1.migrate.return_value = mock.Mock()
zebra2 = mock.Mock()
zebra2.has_migrations.return_value = mock.Mock()
zebra2.migrate.return_value = mock.Mock()
fake_imported_modules = [ocata1, ocata2]
fake_imported_modules = [zebra1, zebra2]
mock_import.side_effect = fake_imported_modules
actual = data_migrations._find_migration_modules('ocata')
actual = data_migrations._find_migration_modules('zebra')
self.assertEqual(2, len(actual))
self.assertEqual(fake_imported_modules, actual)
@mock.patch('pkgutil.iter_modules')
def test_find_migrations_no_migrations(self, mock_iter):
def fake_iter_modules(blah):
yield 'blah', 'liberty01', 'blah'
yield 'blah', 'kilo01', 'blah'
yield 'blah', 'mitaka01', 'blah'
yield 'blah', 'newton01', 'blah'
yield 'blah', 'pike01', 'blah'
yield 'blah', 'zebra01', 'blah'
yield 'blah', 'yellow01', 'blah'
yield 'blah', 'xray01', 'blah'
yield 'blah', 'wrinkle01', 'blah'
yield 'blah', 'victor01', 'blah'
mock_iter.side_effect = fake_iter_modules
actual = data_migrations._find_migration_modules('ocata')
actual = data_migrations._find_migration_modules('umbrella')
self.assertEqual(0, len(actual))
self.assertEqual([], actual)
def test_run_migrations(self):
ocata1 = mock.Mock()
ocata1.has_migrations.return_value = True
ocata1.migrate.return_value = 100
ocata2 = mock.Mock()
ocata2.has_migrations.return_value = True
ocata2.migrate.return_value = 50
migrations = [ocata1, ocata2]
zebra1 = mock.Mock()
zebra1.has_migrations.return_value = True
zebra1.migrate.return_value = 100
zebra2 = mock.Mock()
zebra2.has_migrations.return_value = True
zebra2.migrate.return_value = 50
migrations = [zebra1, zebra2]
engine = mock.Mock()
actual = data_migrations._run_migrations(engine, migrations)
self.assertEqual(150, actual)
ocata1.has_migrations.assert_called_once_with(engine)
ocata1.migrate.assert_called_once_with(engine)
ocata2.has_migrations.assert_called_once_with(engine)
ocata2.migrate.assert_called_once_with(engine)
zebra1.has_migrations.assert_called_once_with(engine)
zebra1.migrate.assert_called_once_with(engine)
zebra2.has_migrations.assert_called_once_with(engine)
zebra2.migrate.assert_called_once_with(engine)
def test_run_migrations_with_one_pending_migration(self):
ocata1 = mock.Mock()
ocata1.has_migrations.return_value = False
ocata1.migrate.return_value = 0
ocata2 = mock.Mock()
ocata2.has_migrations.return_value = True
ocata2.migrate.return_value = 50
migrations = [ocata1, ocata2]
zebra1 = mock.Mock()
zebra1.has_migrations.return_value = False
zebra1.migrate.return_value = 0
zebra2 = mock.Mock()
zebra2.has_migrations.return_value = True
zebra2.migrate.return_value = 50
migrations = [zebra1, zebra2]
engine = mock.Mock()
actual = data_migrations._run_migrations(engine, migrations)
self.assertEqual(50, actual)
ocata1.has_migrations.assert_called_once_with(engine)
ocata1.migrate.assert_not_called()
ocata2.has_migrations.assert_called_once_with(engine)
ocata2.migrate.assert_called_once_with(engine)
zebra1.has_migrations.assert_called_once_with(engine)
zebra1.migrate.assert_not_called()
zebra2.has_migrations.assert_called_once_with(engine)
zebra2.migrate.assert_called_once_with(engine)
def test_run_migrations_with_no_migrations(self):
migrations = []
@@ -173,33 +173,33 @@ class TestDataMigrationFramework(test_utils.BaseTestCase):
actual = data_migrations._run_migrations(mock.Mock(), migrations)
self.assertEqual(0, actual)
@mock.patch('glance.db.migration.CURRENT_RELEASE', 'ocata')
@mock.patch('glance.db.migration.CURRENT_RELEASE', 'zebra')
@mock.patch('importlib.import_module')
@mock.patch('pkgutil.iter_modules')
def test_migrate(self, mock_iter, mock_import):
def fake_iter_modules(blah):
yield 'blah', 'ocata01', 'blah'
yield 'blah', 'ocata02', 'blah'
yield 'blah', 'pike01', 'blah'
yield 'blah', 'newton', 'blah'
yield 'blah', 'mitaka456', 'blah'
yield 'blah', 'zebra01', 'blah'
yield 'blah', 'zebra02', 'blah'
yield 'blah', 'yellow01', 'blah'
yield 'blah', 'xray01', 'blah'
yield 'blah', 'xray02', 'blah'
mock_iter.side_effect = fake_iter_modules
ocata1 = mock.Mock()
ocata1.has_migrations.return_value = True
ocata1.migrate.return_value = 100
ocata2 = mock.Mock()
ocata2.has_migrations.return_value = True
ocata2.migrate.return_value = 50
zebra1 = mock.Mock()
zebra1.has_migrations.return_value = True
zebra1.migrate.return_value = 100
zebra2 = mock.Mock()
zebra2.has_migrations.return_value = True
zebra2.migrate.return_value = 50
fake_imported_modules = [ocata1, ocata2]
fake_imported_modules = [zebra1, zebra2]
mock_import.side_effect = fake_imported_modules
engine = mock.Mock()
actual = data_migrations.migrate(engine)
self.assertEqual(150, actual)
ocata1.has_migrations.assert_called_once_with(engine)
ocata1.migrate.assert_called_once_with(engine)
ocata2.has_migrations.assert_called_once_with(engine)
ocata2.migrate.assert_called_once_with(engine)
zebra1.has_migrations.assert_called_once_with(engine)
zebra1.migrate.assert_called_once_with(engine)
zebra2.has_migrations.assert_called_once_with(engine)
zebra2.migrate.assert_called_once_with(engine)