def test_init_creates_folders(self): args = parse_args(['init', '--folder', 'test_config']) self.assertTrue(init(args)) self.assertTrue(os.path.exists('./test_config')) self.assertTrue(os.path.exists('./test_config/migrations')) self.assertTrue(os.path.isfile('./test_config/__init__.py')) self.assertTrue(os.path.isfile('./test_config/migrations/__init__.py'))
def test_perform_single_migration_already_migrated(self): """Run migration twice, second time should return False""" self.do_good_migration_up() args = parse_args(['up', '1']) termi = Terminator(args) self.assertFalse(termi.perform_migrations('up'))
def test_perform_single_migration_not_found(self): """Ensure that a bad migration argument raises an error""" args = parse_args(['up', '1']) termi = Terminator(args) with self.assertRaises(ImportError): termi.direction = 'up' termi._perform_single_migration('up')
def test_migrate_missing_prevents_down(self): """Prevent going down with --migrate-missing.""" self.do_good_migration_up() args = parse_args(['down', '0']) termi = Terminator(args) # manually set this because the parser doesn't support it termi.migrate_missing = True self.assertFalse(termi.perform_migrations('down'))
def test_migrate_0_migrates_all(self): """Up 0 should migrate everything.""" args = parse_args(['up', '0']) termi = Terminator(args) termi.perform_migrations('up') self.assertTrue(self._migration_row_exists(self.good_migration)) self.assertTrue(self._migration_row_exists(self.out_of_order_migration))
def test_setup_table(self): """Ensure that the Migration table will be setup properly""" # Drop the table if it exists, as we are creating it later if self.model.table_exists(): self.model.drop_table() args = parse_args(['status']) Terminator(args) self.assertEqual(self.model.table_exists(), True)
def _test(migrate_missing=False): """Simple wrapper since the test is the same with or without the flag.""" args = ['up', '0'] self._copy_asset(self.ensure_ordering_migration) if migrate_missing: self._copy_asset(self.missing_migration) args.append('--migrate-missing') termi = Terminator(parse_args(args)) termi.perform_migrations('up') self.assertTrue('outofordermigration' in db.get_tables()) self.assertTrue(OutOfOrderMigration.select().first())
def test_migrate_missing(self): """If we pass --migrate-missing, run out of order migrations""" self.test_out_of_order_migrations() # now let's ensure we add the table. args = parse_args(['up', '0', '--migrate-missing']) termi = Terminator(args) termi.perform_migrations('up') self.assertTrue('outofordermigration' in db.get_tables()) self.assertTrue('missingmigration' in db.get_tables()) self.assertTrue(self._migration_row_exists(self.out_of_order_migration)) self.assertTrue(self._migration_row_exists(self.missing_migration)) # the latest migration should still be the last one via name self.assertEqual(termi.get_latest_migration().migration, self.out_of_order_migration)
def test_out_of_order_migrations(self): """If we don't pass --migrate-missing, don't migrate out of order.""" # set up the state where an out of order migration can happen args = parse_args(['up', '0']) termi = Terminator(args) termi.perform_migrations('up') def _assertions(): self.assertTrue('outofordermigration' in db.get_tables()) self.assertFalse('missingmigration' in db.get_tables()) self.assertTrue(self._migration_row_exists( self.out_of_order_migration)) self.assertFalse(self._migration_row_exists(self.missing_migration)) # assert that the setup succeeded _assertions() # move the migration so we're in a proper missing state self._copy_asset(self.missing_migration) termi = Terminator(args) termi.perform_migrations('up') # now that we've migrated, make sure we didn't add that table. _assertions()
def test_perform_single_migration_down_does_not_exist(self): """Ensure False response when migration isn't there""" args = parse_args(['down', '1']) termi = Terminator(args) self.assertFalse(termi.perform_migrations('down'))
def do_good_migration_up(self): """A utility to perform a successfull upwards migration""" args = parse_args(['up', '1']) termi = Terminator(args) termi.perform_migrations('up') self.assertTrue("basicmodel" in db.get_tables())
def do_good_migration_down(self): """A utility to perform a successfull downwards migration""" args = parse_args(['down', '1']) termi = Terminator(args) termi.perform_migrations('down') self.assertFalse("basicmodel" in db.get_tables())
def test_filenames_include_good_migration(self): args = parse_args(['up', '1']) termi = Terminator(args) filenames = termi._retreive_filenames() self.assertTrue(self.good_migration in filenames)
def do_good_migration_down(self, table_name="basicmodel"): """A utility to perform a successfull downwards migration""" args = parse_args(['down', '1']) termi = Terminator(args) termi.perform_migrations('down') self.assertFalse(table_name in db.get_tables())
def do_good_migration_up(self, table_name="basicmodel"): """A utility to perform a successfull upwards migration""" args = parse_args(['up', '1']) termi = Terminator(args) termi.perform_migrations('up') self.assertTrue(table_name in db.get_tables())
def test_with_fake_argument_returns_true_no_table(self): """If we pass fake, return true, but don't create the model table""" args = parse_args(['up', '1', '--fake', 'true']) termi = Terminator(args) self.assertTrue(termi.perform_migrations('up')) self.assertFalse("basicmodel" in db.get_tables())