showmigrations --list displays migrations and whether or not they're applied.
(self)
| 464 | |
| 465 | @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) |
| 466 | def test_showmigrations_list(self): |
| 467 | """ |
| 468 | showmigrations --list displays migrations and whether or not they're |
| 469 | applied. |
| 470 | """ |
| 471 | out = io.StringIO() |
| 472 | with mock.patch( |
| 473 | "django.core.management.color.supports_color", lambda *args: True |
| 474 | ): |
| 475 | call_command( |
| 476 | "showmigrations", format="list", stdout=out, verbosity=0, no_color=False |
| 477 | ) |
| 478 | self.assertEqual( |
| 479 | "\x1b[1mmigrations\n\x1b[0m [ ] 0001_initial\n [ ] 0002_second\n", |
| 480 | out.getvalue().lower(), |
| 481 | ) |
| 482 | |
| 483 | call_command("migrate", "migrations", "0001", verbosity=0) |
| 484 | |
| 485 | out = io.StringIO() |
| 486 | # Giving the explicit app_label tests for selective `show_list` in the |
| 487 | # command |
| 488 | call_command( |
| 489 | "showmigrations", |
| 490 | "migrations", |
| 491 | format="list", |
| 492 | stdout=out, |
| 493 | verbosity=0, |
| 494 | no_color=True, |
| 495 | ) |
| 496 | self.assertEqual( |
| 497 | "migrations\n [x] 0001_initial\n [ ] 0002_second\n", out.getvalue().lower() |
| 498 | ) |
| 499 | out = io.StringIO() |
| 500 | # Applied datetimes are displayed at verbosity 2+. |
| 501 | call_command( |
| 502 | "showmigrations", "migrations", stdout=out, verbosity=2, no_color=True |
| 503 | ) |
| 504 | migration1 = MigrationRecorder(connection).migration_qs.get( |
| 505 | app="migrations", name="0001_initial" |
| 506 | ) |
| 507 | self.assertEqual( |
| 508 | "migrations\n" |
| 509 | " [x] 0001_initial (applied at %s)\n" |
| 510 | " [ ] 0002_second\n" % migration1.applied.strftime("%Y-%m-%d %H:%M:%S"), |
| 511 | out.getvalue().lower(), |
| 512 | ) |
| 513 | # Cleanup by unmigrating everything |
| 514 | call_command("migrate", "migrations", "zero", verbosity=0) |
| 515 | |
| 516 | @override_settings( |
| 517 | MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"} |
nothing calls this directly
no test coverage detected