summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_commands.py41
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