示例#1
0
 def test_bad_ref(self):
     unmigrate = UnmigrateCommand()
     unmigrate.from_argv = True  # Need to skip argv check
     with self.assertRaises(CommandError) as ctx:
         call_command(unmigrate,
                      "hopefully-unexisting-ref-in-my-own-git-repo")
     self.assertTrue(str(ctx.exception).startswith("Git says:"))
 def test_migration_zero(self):
     unmigrate = UnmigrateCommand()
     unmigrate.from_argv = True  # Need to skip argv check
     with StringIO() as stdout:
         call_command(
             unmigrate, MIGRATION_ZERO_COMMIT, dry_run=True, no_color=True, stdout=stdout
         )  # It's required to strip colored output
         stdout.seek(0)
         self.assertEqual(stdout.read().strip(), "myapp zero")
 def test_full_unmigrate_zero(self):
     unmigrate = UnmigrateCommand()
     unmigrate.from_argv = True  # Need to skip argv check
     with StringIO() as stdout:
         call_command(unmigrate, MIGRATION_ZERO_COMMIT, stdout=stdout)
         stdout.seek(0)
         self.assertTrue("Unapplying" in stdout.read())
     with StringIO() as stdout:
         call_command("migrate", stdout=stdout)
         stdout.seek(0)
         self.assertTrue("Applying" in stdout.read())
 def test_full_unmigrate_by_commit(self):
     unmigrate = UnmigrateCommand()
     unmigrate.from_argv = True  # Need to skip argv check
     for commit, expected_migrations in COMMITS.items():
         expected_migrations.sort()  # We know tuple-sorting our migrations yields chronological order
         expected_parents = []
         if expected_migrations:
             expected_parents = PARENTS[expected_migrations[0]]
         with StringIO() as stdout:
             call_command(unmigrate, commit, stdout=stdout)
             stdout.seek(0)
             self.assertTrue(not expected_parents or "Unapplying" in stdout.read())
         with StringIO() as stdout:
             call_command("migrate", stdout=stdout)
             stdout.seek(0)
             self.assertTrue(not expected_parents or "Applying" in stdout.read())
 def test_migration_parents(self):
     unmigrate = UnmigrateCommand()
     unmigrate.from_argv = True  # Need to skip argv check
     for commit, expected_migrations in COMMITS.items():
         expected_migrations.sort()  # We know tuple-sorting our migrations yields chronological order
         expected_parents = []
         if expected_migrations:
             expected_parents = PARENTS[expected_migrations[0]]
         with StringIO() as stdout:
             call_command(
                 unmigrate, commit, dry_run=True, no_color=True, stdout=stdout
             )  # It's required to strip colored output, skipping verbosity check on purpose
             stdout.seek(0)
             self.assertEqual(
                 set(stdout.read().strip().splitlines()), set(["{0} {1}".format(*x) for x in expected_parents])
             )
 def test_debug_with_danger(self):
     unmigrate = UnmigrateCommand()
     unmigrate.from_argv = True  # Need to skip argv check
     call_command(unmigrate, danger=True)
 def test_debug(self):
     unmigrate = UnmigrateCommand()
     unmigrate.from_argv = True  # Need to skip argv check
     call_command(unmigrate, dry_run=True)