def run_assetlink(): printer = CollectingPrinter() link_plugin_assets(plugin_static, linked_assets_dir, printer) return printer
def test_set1_to_set3(): # Create / connect to database # ---------------------------- engine, Session = create_test_engine() # Create tables by migrating on empty initial set # ----------------------------------------------- printer = CollectingPrinter() migration_manager = MigrationManager('__main__', SET1_MODELS, SET1_MIGRATIONS, Session(), printer) # Check latest migration and database current migration assert migration_manager.latest_migration == 0 assert migration_manager.database_current_migration == None result = migration_manager.init_or_migrate() # Make sure output was "inited" assert result == 'inited' # Check output assert printer.combined_string == ( "-> Initializing main mediagoblin tables... done.\n") # Check version in database assert migration_manager.latest_migration == 0 assert migration_manager.database_current_migration == 0 # Install the initial set # ----------------------- _insert_migration1_objects(Session()) # Try to "re-migrate" with same manager settings... nothing should happen migration_manager = MigrationManager('__main__', SET1_MODELS, SET1_MIGRATIONS, Session(), printer) assert migration_manager.init_or_migrate() == None # Check version in database assert migration_manager.latest_migration == 0 assert migration_manager.database_current_migration == 0 # Sanity check a few things in the database... metadata = MetaData(bind=engine) # Check the structure of the creature table creature_table = Table('creature', metadata, autoload=True, autoload_with=engine) assert set( creature_table.c.keys()) == {'id', 'name', 'num_legs', 'is_demon'} assert_col_type(creature_table.c.id, Integer) assert_col_type(creature_table.c.name, VARCHAR) assert creature_table.c.name.nullable is False #assert creature_table.c.name.index is True #assert creature_table.c.name.unique is True assert_col_type(creature_table.c.num_legs, Integer) assert creature_table.c.num_legs.nullable is False assert_col_type(creature_table.c.is_demon, Boolean) # Check the structure of the level table level_table = Table('level', metadata, autoload=True, autoload_with=engine) assert set(level_table.c.keys()) == {'id', 'name', 'description', 'exits'} assert_col_type(level_table.c.id, VARCHAR) assert level_table.c.id.primary_key is True assert_col_type(level_table.c.name, VARCHAR) assert_col_type(level_table.c.description, VARCHAR) # Skipping exits... Not sure if we can detect pickletype, not a # big deal regardless. # Now check to see if stuff seems to be in there. session = Session() # Check the creation of the inserted rows on the creature and levels tables creature = session.query(Creature1).filter_by(name='centipede').one() assert creature.num_legs == 100 assert creature.is_demon == False creature = session.query(Creature1).filter_by(name='wolf').one() assert creature.num_legs == 4 assert creature.is_demon == False creature = session.query(Creature1).filter_by(name='wizardsnake').one() assert creature.num_legs == 0 assert creature.is_demon == True level = session.query(Level1).filter_by(id='necroplex').one() assert level.name == 'The Necroplex' assert level.description == 'A complex full of pure deathzone.' assert level.exits == {'deathwell': 'evilstorm', 'portal': 'central_park'} level = session.query(Level1).filter_by(id='evilstorm').one() assert level.name == 'Evil Storm' assert level.description == 'A storm full of pure evil.' assert level.exits == {} # You still can't escape the evilstorm! level = session.query(Level1).filter_by(id='central_park').one() assert level.name == 'Central Park, NY, NY' assert level.description == "New York's friendly Central Park." assert level.exits == {'portal': 'necroplex'} # Create new migration manager, but make sure the db migration # isn't said to be updated yet printer = CollectingPrinter() migration_manager = MigrationManager('__main__', SET3_MODELS, SET3_MIGRATIONS, Session(), printer) assert migration_manager.latest_migration == 8 assert migration_manager.database_current_migration == 0 # Migrate result = migration_manager.init_or_migrate() # Make sure result was "migrated" assert result == 'migrated' # TODO: Check output to user assert printer.combined_string == """\ -> Updating main mediagoblin tables: + Running migration 1, "creature_remove_is_demon"... done. + Running migration 2, "creature_powers_new_table"... done. + Running migration 3, "level_exits_new_table"... done. + Running migration 4, "creature_num_legs_to_num_limbs"... done. + Running migration 5, "level_exit_index_from_and_to_level"... done. + Running migration 6, "creature_power_index_creature"... done. + Running migration 7, "creature_power_hitpower_to_float"... done. + Running migration 8, "creature_power_name_creature_unique"... done. """ # Make sure version matches expected migration_manager = MigrationManager('__main__', SET3_MODELS, SET3_MIGRATIONS, Session(), printer) assert migration_manager.latest_migration == 8 assert migration_manager.database_current_migration == 8 # Check all things in database match expected # Check the creature table metadata = MetaData(bind=engine) creature_table = Table('creature', metadata, autoload=True, autoload_with=engine) # assert set(creature_table.c.keys()) == set( # ['id', 'name', 'num_limbs']) assert set( creature_table.c.keys()) == {'id', 'name', 'num_limbs', 'is_demon'} assert_col_type(creature_table.c.id, Integer) assert_col_type(creature_table.c.name, VARCHAR) assert creature_table.c.name.nullable is False #assert creature_table.c.name.index is True #assert creature_table.c.name.unique is True assert_col_type(creature_table.c.num_limbs, Integer) assert creature_table.c.num_limbs.nullable is False # Check the CreaturePower table creature_power_table = Table('creature_power', metadata, autoload=True, autoload_with=engine) assert set(creature_power_table.c.keys()) == { 'id', 'creature', 'name', 'description', 'hitpower' } assert_col_type(creature_power_table.c.id, Integer) assert_col_type(creature_power_table.c.creature, Integer) assert creature_power_table.c.creature.nullable is False assert_col_type(creature_power_table.c.name, VARCHAR) assert_col_type(creature_power_table.c.description, VARCHAR) assert_col_type(creature_power_table.c.hitpower, Float) assert creature_power_table.c.hitpower.nullable is False # Check the structure of the level table level_table = Table('level', metadata, autoload=True, autoload_with=engine) assert set(level_table.c.keys()) == {'id', 'name', 'description'} assert_col_type(level_table.c.id, VARCHAR) assert level_table.c.id.primary_key is True assert_col_type(level_table.c.name, VARCHAR) assert_col_type(level_table.c.description, VARCHAR) # Check the structure of the level_exits table level_exit_table = Table('level_exit', metadata, autoload=True, autoload_with=engine) assert set( level_exit_table.c.keys()) == {'id', 'name', 'from_level', 'to_level'} assert_col_type(level_exit_table.c.id, Integer) assert_col_type(level_exit_table.c.name, VARCHAR) assert_col_type(level_exit_table.c.from_level, VARCHAR) assert level_exit_table.c.from_level.nullable is False #assert level_exit_table.c.from_level.index is True assert_col_type(level_exit_table.c.to_level, VARCHAR) assert level_exit_table.c.to_level.nullable is False #assert level_exit_table.c.to_level.index is True # Now check to see if stuff seems to be in there. session = Session() # Then make sure the models have been migrated correctly creature = session.query(Creature3).filter_by(name='centipede').one() assert creature.num_limbs == 100.0 assert creature.magical_powers == [] creature = session.query(Creature3).filter_by(name='wolf').one() assert creature.num_limbs == 4.0 assert creature.magical_powers == [] creature = session.query(Creature3).filter_by(name='wizardsnake').one() assert creature.num_limbs == 0.0 assert creature.magical_powers == [] level = session.query(Level3).filter_by(id='necroplex').one() assert level.name == 'The Necroplex' assert level.description == 'A complex full of pure deathzone.' level_exits = _get_level3_exits(session, level) assert level_exits == {'deathwell': 'evilstorm', 'portal': 'central_park'} level = session.query(Level3).filter_by(id='evilstorm').one() assert level.name == 'Evil Storm' assert level.description == 'A storm full of pure evil.' level_exits = _get_level3_exits(session, level) assert level_exits == {} # You still can't escape the evilstorm! level = session.query(Level3).filter_by(id='central_park').one() assert level.name == 'Central Park, NY, NY' assert level.description == "New York's friendly Central Park." level_exits = _get_level3_exits(session, level) assert level_exits == {'portal': 'necroplex'}