diff options
| author | Marten Kenbeek <marten.knbk@gmail.com> | 2015-03-07 13:53:13 +0100 |
|---|---|---|
| committer | Markus Holtermann <info@markusholtermann.eu> | 2015-03-08 19:44:14 +0100 |
| commit | e272904ff7cc4d138e316ba2e7811666053860a4 (patch) | |
| tree | 8b2a8671da3e88b12196bd9b196d5b9f53270e90 /tests | |
| parent | 794c3f74c32062d0f2ad021cb2af0e530b40730d (diff) | |
Fixed #23407 -- Extended coverage of makemigrations --noinput option.
Changed --noinput option in makemigrations to suppress all user prompts,
not just when combined with --merge.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_commands.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index 86eb769a32..ca7214be2b 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -531,6 +531,80 @@ class MakeMigrationsTests(MigrationTestBase): questioner.input = old_input self.assertIn("Created new merge migration", force_text(out.getvalue())) + def test_makemigrations_non_interactive_not_null_addition(self): + """ + Tests that non-interactive makemigrations fails when a default is missing on a new not-null field. + """ + class SillyModel(models.Model): + silly_field = models.BooleanField(default=False) + silly_int = models.IntegerField() + + class Meta: + app_label = "migrations" + + out = six.StringIO() + with self.assertRaises(SystemExit): + with self.temporary_migration_module(module="migrations.test_migrations_no_default"): + call_command("makemigrations", "migrations", interactive=False, stdout=out) + + def test_makemigrations_non_interactive_not_null_alteration(self): + """ + Tests that non-interactive makemigrations fails when a default is missing on a field changed to not-null. + """ + class Author(models.Model): + name = models.CharField(max_length=255) + slug = models.SlugField() + age = models.IntegerField(default=0) + + class Meta: + app_label = "migrations" + + out = six.StringIO() + try: + with self.temporary_migration_module(module="migrations.test_migrations"): + call_command("makemigrations", "migrations", interactive=False, stdout=out) + except CommandError: + self.fail("Makemigrations failed while running non-interactive questioner.") + self.assertIn("Alter field slug on author", force_text(out.getvalue())) + + def test_makemigrations_non_interactive_no_model_rename(self): + """ + Makes sure that makemigrations adds and removes a possible model rename in non-interactive mode. + """ + class RenamedModel(models.Model): + silly_field = models.BooleanField(default=False) + + class Meta: + app_label = "migrations" + + out = six.StringIO() + try: + with self.temporary_migration_module(module="migrations.test_migrations_no_default"): + call_command("makemigrations", "migrations", interactive=False, stdout=out) + except CommandError: + self.fail("Makemigrations failed while running non-interactive questioner") + self.assertIn("Delete model SillyModel", force_text(out.getvalue())) + self.assertIn("Create model RenamedModel", force_text(out.getvalue())) + + def test_makemigrations_non_interactive_no_field_rename(self): + """ + Makes sure that makemigrations adds and removes a possible field rename in non-interactive mode. + """ + class SillyModel(models.Model): + silly_rename = models.BooleanField(default=False) + + class Meta: + app_label = "migrations" + + out = six.StringIO() + try: + with self.temporary_migration_module(module="migrations.test_migrations_no_default"): + call_command("makemigrations", "migrations", interactive=False, stdout=out) + except CommandError: + self.fail("Makemigrations failed while running non-interactive questioner") + self.assertIn("Remove field silly_field from sillymodel", force_text(out.getvalue())) + self.assertIn("Add field silly_rename to sillymodel", force_text(out.getvalue())) + def test_makemigrations_handle_merge(self): """ Makes sure that makemigrations properly merges the conflicting migrations with --noinput. |
