summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2021-01-29 10:19:06 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-02-04 11:19:49 +0100
commitf23b05696e470fc113c729e18665722ccbb7a9f0 (patch)
tree11d28a1c42bc49c5b35104347c09e2eba17ab6fd /tests
parent31bebc558bf9a647c77ff6b372fc199008e99c1c (diff)
Fixed #32395 -- Allowed capturing stdout of migration signals.
Diffstat (limited to 'tests')
-rw-r--r--tests/migrate_signals/tests.py7
-rw-r--r--tests/migrations/test_commands.py8
2 files changed, 11 insertions, 4 deletions
diff --git a/tests/migrate_signals/tests.py b/tests/migrate_signals/tests.py
index e3d00ee9e3..e084f26ed8 100644
--- a/tests/migrate_signals/tests.py
+++ b/tests/migrate_signals/tests.py
@@ -1,3 +1,5 @@
+from io import StringIO
+
from django.apps import apps
from django.core import management
from django.db import migrations
@@ -5,7 +7,7 @@ from django.db.models import signals
from django.test import TransactionTestCase, override_settings
APP_CONFIG = apps.get_app_config('migrate_signals')
-SIGNAL_ARGS = ['app_config', 'verbosity', 'interactive', 'using', 'plan', 'apps']
+SIGNAL_ARGS = ['app_config', 'verbosity', 'interactive', 'using', 'stdout', 'plan', 'apps']
MIGRATE_DATABASE = 'default'
MIGRATE_VERBOSITY = 0
MIGRATE_INTERACTIVE = False
@@ -69,7 +71,7 @@ class MigrateSignalTests(TransactionTestCase):
post_migrate_receiver = Receiver(signals.post_migrate)
management.call_command(
'migrate', database=MIGRATE_DATABASE, verbosity=MIGRATE_VERBOSITY,
- interactive=MIGRATE_INTERACTIVE,
+ interactive=MIGRATE_INTERACTIVE, stdout=StringIO('test_args'),
)
for receiver in [pre_migrate_receiver, post_migrate_receiver]:
@@ -81,6 +83,7 @@ class MigrateSignalTests(TransactionTestCase):
self.assertEqual(args['verbosity'], MIGRATE_VERBOSITY)
self.assertEqual(args['interactive'], MIGRATE_INTERACTIVE)
self.assertEqual(args['using'], 'default')
+ self.assertIn('test_args', args['stdout'].getvalue())
self.assertEqual(args['plan'], [])
self.assertIsInstance(args['apps'], migrations.state.StateApps)
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index da9a571e8a..2477872423 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -39,10 +39,12 @@ class MigrateTests(MigrationTestBase):
self.assertTableNotExists("migrations_book")
# Run the migrations to 0001 only
stdout = io.StringIO()
- call_command('migrate', 'migrations', '0001', verbosity=1, stdout=stdout, no_color=True)
+ call_command('migrate', 'migrations', '0001', verbosity=2, stdout=stdout, no_color=True)
stdout = stdout.getvalue()
self.assertIn('Target specific migration: 0001_initial, from migrations', stdout)
self.assertIn('Applying migrations.0001_initial... OK', stdout)
+ self.assertIn('Running pre-migrate handlers for application migrations', stdout)
+ self.assertIn('Running post-migrate handlers for application migrations', stdout)
# The correct tables exist
self.assertTableExists("migrations_author")
self.assertTableExists("migrations_tribble")
@@ -55,10 +57,12 @@ class MigrateTests(MigrationTestBase):
self.assertTableExists("migrations_book")
# Unmigrate everything
stdout = io.StringIO()
- call_command('migrate', 'migrations', 'zero', verbosity=1, stdout=stdout, no_color=True)
+ call_command('migrate', 'migrations', 'zero', verbosity=2, stdout=stdout, no_color=True)
stdout = stdout.getvalue()
self.assertIn('Unapply all migrations: migrations', stdout)
self.assertIn('Unapplying migrations.0002_second... OK', stdout)
+ self.assertIn('Running pre-migrate handlers for application migrations', stdout)
+ self.assertIn('Running post-migrate handlers for application migrations', stdout)
# Tables are gone
self.assertTableNotExists("migrations_author")
self.assertTableNotExists("migrations_tribble")