diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2021-08-06 09:59:53 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-01-10 18:49:57 +0100 |
| commit | 6f78cb6b13fca2512f80dcd2bce7838bf33b70f0 (patch) | |
| tree | cb7599bf8851b490f3423a862867d93b0a7684fc /tests | |
| parent | 274771df9133542df048cc104c19e7756f9d3715 (diff) | |
Fixed #29026 -- Added --scriptable option to makemigrations.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_commands.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index ef5db241d6..f274c8486b 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -1667,6 +1667,47 @@ class MakeMigrationsTests(MigrationTestBase): self.assertIn("model_name='sillymodel',", out.getvalue()) self.assertIn("name='silly_char',", out.getvalue()) + def test_makemigrations_scriptable(self): + """ + With scriptable=True, log output is diverted to stderr, and only the + paths of generated migration files are written to stdout. + """ + out = io.StringIO() + err = io.StringIO() + with self.temporary_migration_module( + module='migrations.migrations.test_migrations', + ) as migration_dir: + call_command( + 'makemigrations', + 'migrations', + scriptable=True, + stdout=out, + stderr=err, + ) + initial_file = os.path.join(migration_dir, '0001_initial.py') + self.assertEqual(out.getvalue(), f'{initial_file}\n') + self.assertIn(' - Create model ModelWithCustomBase\n', err.getvalue()) + + @mock.patch('builtins.input', return_value='Y') + def test_makemigrations_scriptable_merge(self, mock_input): + out = io.StringIO() + err = io.StringIO() + with self.temporary_migration_module( + module='migrations.test_migrations_conflict', + ) as migration_dir: + call_command( + 'makemigrations', + 'migrations', + merge=True, + name='merge', + scriptable=True, + stdout=out, + stderr=err, + ) + merge_file = os.path.join(migration_dir, '0003_merge.py') + self.assertEqual(out.getvalue(), f'{merge_file}\n') + self.assertIn(f'Created new merge migration {merge_file}', err.getvalue()) + def test_makemigrations_migrations_modules_path_not_exist(self): """ makemigrations creates migrations when specifying a custom location |
