# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 Free Software Foundation, Inc
+# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from nose.tools import assert_raises
from pymongo import Connection
from mediagoblin.tests.tools import (
install_fixtures_simple, assert_db_meets_expected)
-from mediagoblin.db.util import RegisterMigration, MigrationManager, ObjectId
+from mediagoblin.db.mongo.util import (
+ RegisterMigration, MigrationManager, ObjectId,
+ MissingCurrentMigration)
+from mediagoblin.db.mongo.migrations import add_table_field
# This one will get filled with local migrations
TEST_MIGRATION_REGISTRY = {}
Add lists of magical powers.
This defaults to [], an empty list. Since we haven't declared any
- magical powers, all existing monsters should
+ magical powers, all existing monsters, setting to an empty list is
+ fine.
"""
- database['creatures'].update(
- {'magical_powers': {'$exists': False}},
- {'$set': {'magical_powers': []}},
- multi=True)
+ add_table_field(database, 'creatures', 'magical_powers', [])
@RegisterMigration(2, TEST_MIGRATION_REGISTRY)
Make sure that running full migration suite from 3 only runs
last migration
"""
- pass
+ self.migration_manager.set_current_migration(3)
+ assert self.migration_manager.database_current_migration() == 3
+ install_fixtures_simple(self.db, SEMI_MIGRATED_DBDATA)
+ self.migration_manager.migrate_new(post_callback=self._record_migration)
+
+ assert self.run_migrations == [
+ (4, level_exits_dict_to_list)]
+
+ assert_db_meets_expected(
+ self.db, EXPECTED_POST_MIGRATION_SEMI_MIGRATED_DBDATA)
+
+ # Make sure the migration is recorded correctly
+ assert self.migration_manager.database_current_migration() == 4
def test_migrations_recorded_as_latest(self):
"""
Make sure that if we don't have a migration_status
pre-recorded it's marked as the latest
"""
- pass
+ self.migration_manager.install_migration_version_if_missing()
+ assert self.migration_manager.database_current_migration() == 4
def test_no_migrations_recorded_as_zero(self):
"""
Make sure that if we don't have a migration_status
but there *are* no migrations that it's marked as 0
"""
- pass
+ self.empty_migration_manager.install_migration_version_if_missing()
+ assert self.empty_migration_manager.database_current_migration() == 0
+
+ def test_migrations_to_run(self):
+ """
+ Make sure we get the right list of migrations to run
+ """
+ self.migration_manager.set_current_migration(0)
+
+ assert self.migration_manager.migrations_to_run() == [
+ (1, creature_add_magical_powers),
+ (2, creature_rename_num_legs_to_num_limbs),
+ (3, creature_remove_is_demon),
+ (4, level_exits_dict_to_list)]
+
+ self.migration_manager.set_current_migration(3)
+
+ assert self.migration_manager.migrations_to_run() == [
+ (4, level_exits_dict_to_list)]
+
+ self.migration_manager.set_current_migration(4)
+
+ assert self.migration_manager.migrations_to_run() == []
+
+
+ def test_no_migrations_raises_exception(self):
+ """
+ If we don't have the current migration set in the database,
+ this should error out.
+ """
+ assert_raises(
+ MissingCurrentMigration,
+ self.migration_manager.migrations_to_run)