diff options
| author | Sarah Guermond <sarah.guermond@gmail.com> | 2018-07-15 20:32:47 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-11-14 18:22:59 -0500 |
| commit | cd40306854bdeec7d961e3715fba0ba9f72f2f88 (patch) | |
| tree | fed3e00864ffb6859d2773520ce984cf238d808c /tests | |
| parent | e81955401885a93a459bcc130642b6ea5bf4ba4d (diff) | |
Fixed #25884 -- Fixed migrate --run-syncdb when specifying an app label.
Diffstat (limited to 'tests')
3 files changed, 32 insertions, 0 deletions
diff --git a/tests/migrations/migrations_test_apps/unmigrated_app_simple/__init__.py b/tests/migrations/migrations_test_apps/unmigrated_app_simple/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/migrations/migrations_test_apps/unmigrated_app_simple/__init__.py diff --git a/tests/migrations/migrations_test_apps/unmigrated_app_simple/models.py b/tests/migrations/migrations_test_apps/unmigrated_app_simple/models.py new file mode 100644 index 0000000000..785d040800 --- /dev/null +++ b/tests/migrations/migrations_test_apps/unmigrated_app_simple/models.py @@ -0,0 +1,9 @@ +from django.db import models + + +class UnmigratedModel(models.Model): + """ + A model that is in a migration-less app (which this app is + if its migrations directory has not been repointed) + """ + pass diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index 2548804677..c2891ed1a1 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -663,6 +663,29 @@ class MigrateTests(MigrationTestBase): table_name = truncate_name('unmigrated_app_syncdb_classroom', connection.ops.max_name_length()) self.assertIn('Creating table %s' % table_name, stdout) + @override_settings(MIGRATION_MODULES={'migrations': 'migrations.test_migrations'}) + def test_migrate_syncdb_app_with_migrations(self): + msg = "Can't use run_syncdb with app 'migrations' as it has migrations." + with self.assertRaisesMessage(CommandError, msg): + call_command('migrate', 'migrations', run_syncdb=True, verbosity=0) + + @override_settings(INSTALLED_APPS=[ + 'migrations.migrations_test_apps.unmigrated_app_syncdb', + 'migrations.migrations_test_apps.unmigrated_app_simple', + ]) + def test_migrate_syncdb_app_label(self): + """ + Running migrate --run-syncdb with an app_label only creates tables for + the specified app. + """ + stdout = io.StringIO() + with mock.patch.object(BaseDatabaseSchemaEditor, 'execute') as execute: + call_command('migrate', 'unmigrated_app_syncdb', run_syncdb=True, stdout=stdout) + create_table_count = len([call for call in execute.mock_calls if 'CREATE TABLE' in str(call)]) + self.assertEqual(create_table_count, 2) + self.assertGreater(len(execute.mock_calls), 2) + self.assertIn('Synchronize unmigrated app: unmigrated_app_syncdb', stdout.getvalue()) + @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"}) def test_migrate_record_replaced(self): """ |
