Exemplo n.º 1
0
 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'))
Exemplo n.º 2
0
 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'))
Exemplo n.º 3
0
    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'))
Exemplo n.º 4
0
    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')
Exemplo n.º 5
0
 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'))
Exemplo n.º 6
0
    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))
Exemplo n.º 7
0
 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)
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
    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')
Exemplo n.º 10
0
        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())
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
    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()
Exemplo n.º 13
0
    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'))
Exemplo n.º 14
0
 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())
Exemplo n.º 15
0
 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())
Exemplo n.º 16
0
    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'))
Exemplo n.º 17
0
 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)
Exemplo n.º 18
0
 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())
Exemplo n.º 19
0
 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())
Exemplo n.º 20
0
 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())
Exemplo n.º 21
0
 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)
Exemplo n.º 22
0
 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())