diff options
author | Jacob Walls <jacobtylerwalls@gmail.com> | 2021-12-28 10:46:42 -0500 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-12-30 06:36:55 +0100 |
commit | 92412aa94c97b5c36387fadb39d9f8edf25547fa (patch) | |
tree | 7083e59f0f95508386ca757f20a3e3a4ec659b6c /tests/backends | |
parent | 361bb8f786f112ee275be136795c0b1ecefff928 (diff) | |
download | django-92412aa94c97b5c36387fadb39d9f8edf25547fa.tar.gz |
Fixed #23273 -- Avoided creation of django_migrations table when there are no migrations to apply.
Diffstat (limited to 'tests/backends')
-rw-r--r-- | tests/backends/base/test_creation.py | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/tests/backends/base/test_creation.py b/tests/backends/base/test_creation.py index 3a1164557b..825fb872ed 100644 --- a/tests/backends/base/test_creation.py +++ b/tests/backends/base/test_creation.py @@ -57,12 +57,12 @@ class TestDbSignatureTests(SimpleTestCase): @mock.patch.object(connection, 'ensure_connection') @mock.patch.object(connection, 'prepare_database') @mock.patch('django.db.migrations.recorder.MigrationRecorder.has_table', return_value=False) -@mock.patch('django.db.migrations.executor.MigrationExecutor.migrate') @mock.patch('django.core.management.commands.migrate.Command.sync_apps') class TestDbCreationTests(SimpleTestCase): available_apps = ['backends.base.app_unmigrated'] - def test_migrate_test_setting_false(self, mocked_sync_apps, mocked_migrate, *mocked_objects): + @mock.patch('django.db.migrations.executor.MigrationExecutor.migrate') + def test_migrate_test_setting_false(self, mocked_migrate, mocked_sync_apps, *mocked_objects): test_connection = get_connection_copy() test_connection.settings_dict['TEST']['MIGRATE'] = False creation = test_connection.creation_class(test_connection) @@ -86,7 +86,32 @@ class TestDbCreationTests(SimpleTestCase): with mock.patch.object(creation, '_destroy_test_db'): creation.destroy_test_db(old_database_name, verbosity=0) - def test_migrate_test_setting_true(self, mocked_sync_apps, mocked_migrate, *mocked_objects): + @mock.patch('django.db.migrations.executor.MigrationRecorder.ensure_schema') + def test_migrate_test_setting_false_ensure_schema( + self, mocked_ensure_schema, mocked_sync_apps, *mocked_objects, + ): + test_connection = get_connection_copy() + test_connection.settings_dict['TEST']['MIGRATE'] = False + creation = test_connection.creation_class(test_connection) + if connection.vendor == 'oracle': + # Don't close connection on Oracle. + creation.connection.close = mock.Mock() + old_database_name = test_connection.settings_dict['NAME'] + try: + with mock.patch.object(creation, '_create_test_db'): + creation.create_test_db(verbosity=0, autoclobber=True, serialize=False) + # The django_migrations table is not created. + mocked_ensure_schema.assert_not_called() + # App is synced. + mocked_sync_apps.assert_called() + mocked_args, _ = mocked_sync_apps.call_args + self.assertEqual(mocked_args[1], {'app_unmigrated'}) + finally: + with mock.patch.object(creation, '_destroy_test_db'): + creation.destroy_test_db(old_database_name, verbosity=0) + + @mock.patch('django.db.migrations.executor.MigrationExecutor.migrate') + def test_migrate_test_setting_true(self, mocked_migrate, mocked_sync_apps, *mocked_objects): test_connection = get_connection_copy() test_connection.settings_dict['TEST']['MIGRATE'] = True creation = test_connection.creation_class(test_connection) @@ -109,6 +134,7 @@ class TestDbCreationTests(SimpleTestCase): creation.destroy_test_db(old_database_name, verbosity=0) @mock.patch.dict(os.environ, {'RUNNING_DJANGOS_TEST_SUITE': ''}) + @mock.patch('django.db.migrations.executor.MigrationExecutor.migrate') @mock.patch.object(BaseDatabaseCreation, 'mark_expected_failures_and_skips') def test_mark_expected_failures_and_skips_call(self, mark_expected_failures_and_skips, *mocked_objects): """ |