def test_valid_migration_filenames(self): """ assert we can parse the versions from migration files """ # test some valid versions for version, suffix in [ ('20091112130101', '__migration_one.py') , ('20091112150200', '__migration_two.py') , ('20091112150205', '_migration_three.py') ]: path = os.path.join(self.migrations_path, version + suffix) migration = caribou.Migration(path) actual_version = migration.get_version() assert actual_version == version, '%s != %s' % ( actual_version, version)
def test_invalid_migration_filenames(self): """ assert we can't load migrations with invalid version names """ # assert we test invalid version names invalid_names = os.path.join(get_this_dir(), INVALID_NAMES, '*.py') for filename in glob.glob(invalid_names): try: migration = caribou.Migration(filename) migration.get_version() except caribou.InvalidNameError: pass else: assert False, filename
def test_invalid_migraton_code(self): filenames = [ '20091112130101_syntax_error.py' , '20091112150200_missing_upgrade.py' , '20091112150205_missing_downgrade.py' ] code_dir = os.path.join(get_this_dir(), INVALID_CODE) # assert we can't load a directory containing invalid migrations try: caribou.load_migrations(code_dir) except caribou.InvalidMigrationError: pass else: assert False, 'loaded a dir with invalid migrations' # assert we can't load each invalid migration migrations = [os.path.join(code_dir, f) for f in filenames] for migration in migrations: try: caribou.Migration(migration) except caribou.InvalidMigrationError: pass else: assert False, 'loaded invalid migration [%s]' % migration
def test_create_migration(self): """ assert we can create migration templates """ for name, directory in [ ('tc_1', None), ('tc_2', 'test_create__')]: if directory and not os.path.exists(directory): os.makedirs(directory) path = caribou.create_migration(name, directory) try: assert os.path.exists(path) # assert it is a valid migration print caribou.Migration(path) finally: # remove compiled test migration as well for path in [path, path + 'c']: if os.path.exists(path): os.remove(path) if directory and os.path.exists(directory): shutil.rmtree(directory) # assert we can't create migrations in a directoin that doesn't exist try: caribou.create_migration('adsf', '/path/to/nowhereski') except caribou.Error: pass else: assert False