1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #29026 -- Added --scriptable option to makemigrations.

This commit is contained in:
Jacob Walls
2021-08-06 09:59:53 -04:00
committed by Mariusz Felisiak
parent 274771df91
commit 6f78cb6b13
4 changed files with 74 additions and 3 deletions

View File

@@ -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