From 3db66b1d65c12a94476017cbcc86e72fd842d29e Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 3 Sep 2013 11:51:34 -0400 Subject: [PATCH] Updated syncdb -> migrate in tests. --- tests/fixtures/tests.py | 2 +- tests/fixtures_model_package/tests.py | 6 +-- tests/initial_sql_regress/tests.py | 2 +- tests/m2m_regress/models.py | 2 +- .../__init__.py | 0 tests/migrate_signals/models.py | 0 .../tests.py | 50 +++++++++---------- tests/multiple_database/tests.py | 16 +++--- tests/proxy_model_inheritance/tests.py | 6 +-- tests/schema/models.py | 2 +- tests/swappable_models/tests.py | 4 +- tests/syncdb_signals/models.py | 11 ---- tests/tablespaces/models.py | 2 +- 13 files changed, 46 insertions(+), 57 deletions(-) rename tests/{syncdb_signals => migrate_signals}/__init__.py (100%) create mode 100644 tests/migrate_signals/models.py rename tests/{syncdb_signals => migrate_signals}/tests.py (52%) delete mode 100644 tests/syncdb_signals/models.py diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index 78653ffe5e..c24e0806fa 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -48,7 +48,7 @@ class DumpDataAssertMixin(object): class FixtureLoadingTests(DumpDataAssertMixin, TestCase): def test_initial_data(self): - # syncdb introduces 1 initial data object from initial_data.json. + # migrate introduces 1 initial data object from initial_data.json. self.assertQuerysetEqual(Book.objects.all(), [ '' ]) diff --git a/tests/fixtures_model_package/tests.py b/tests/fixtures_model_package/tests.py index 1e22ac9833..2fa1fd10ef 100644 --- a/tests/fixtures_model_package/tests.py +++ b/tests/fixtures_model_package/tests.py @@ -30,12 +30,12 @@ class TestNoInitialDataLoading(TransactionTestCase): available_apps = ['fixtures_model_package'] - def test_syncdb(self): + def test_migrate(self): with transaction.atomic(): Book.objects.all().delete() management.call_command( - 'syncdb', + 'migrate', verbosity=0, load_initial_data=False ) @@ -64,7 +64,7 @@ class TestNoInitialDataLoading(TransactionTestCase): class FixtureTestCase(TestCase): def test_initial_data(self): "Fixtures can load initial data into models defined in packages" - # syncdb introduces 1 initial data object from initial_data.json + # migrate introduces 1 initial data object from initial_data.json self.assertQuerysetEqual( Book.objects.all(), [ 'Achieving self-awareness of Python programs' diff --git a/tests/initial_sql_regress/tests.py b/tests/initial_sql_regress/tests.py index bd23aab15d..b04e638808 100644 --- a/tests/initial_sql_regress/tests.py +++ b/tests/initial_sql_regress/tests.py @@ -24,7 +24,7 @@ class InitialSQLTests(TestCase): def test_custom_sql(self): """ - Simulate the custom SQL loading by syncdb. + Simulate the custom SQL loading by migrate. """ connection = connections[DEFAULT_DB_ALIAS] custom_sql = custom_sql_for_model(Simple, no_style(), connection) diff --git a/tests/m2m_regress/models.py b/tests/m2m_regress/models.py index 1a4a6df354..abd012b3d0 100644 --- a/tests/m2m_regress/models.py +++ b/tests/m2m_regress/models.py @@ -57,7 +57,7 @@ class Worksheet(models.Model): # Regression for #11226 -- A model with the same name that another one to # which it has a m2m relation. This shouldn't cause a name clash between # the automatically created m2m intermediary table FK field names when -# running syncdb +# running migrate class User(models.Model): name = models.CharField(max_length=30) friends = models.ManyToManyField(auth.User) diff --git a/tests/syncdb_signals/__init__.py b/tests/migrate_signals/__init__.py similarity index 100% rename from tests/syncdb_signals/__init__.py rename to tests/migrate_signals/__init__.py diff --git a/tests/migrate_signals/models.py b/tests/migrate_signals/models.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/syncdb_signals/tests.py b/tests/migrate_signals/tests.py similarity index 52% rename from tests/syncdb_signals/tests.py rename to tests/migrate_signals/tests.py index d70fb2c2c0..9daa7ae376 100644 --- a/tests/syncdb_signals/tests.py +++ b/tests/migrate_signals/tests.py @@ -6,13 +6,13 @@ from django.utils import six from . import models -PRE_SYNCDB_ARGS = ['app', 'create_models', 'verbosity', 'interactive', 'db'] -SYNCDB_DATABASE = 'default' -SYNCDB_VERBOSITY = 1 -SYNCDB_INTERACTIVE = False +PRE_MIGRATE_ARGS = ['app', 'create_models', 'verbosity', 'interactive', 'db'] +MIGRATE_DATABASE = 'default' +MIGRATE_VERBOSITY = 1 +MIGRATE_INTERACTIVE = False -class PreSyncdbReceiver(object): +class PreMigrateReceiver(object): def __init__(self): self.call_counter = 0 self.call_args = None @@ -24,7 +24,7 @@ class PreSyncdbReceiver(object): class OneTimeReceiver(object): """ - Special receiver for handle the fact that test runner calls syncdb for + Special receiver for handle the fact that test runner calls migrate for several databases and several times for some of them. """ @@ -33,13 +33,13 @@ class OneTimeReceiver(object): self.call_args = None def __call__(self, signal, sender, **kwargs): - # Although test runner calls syncdb for several databases, + # Although test runner calls migrate for several databases, # testing for only one of them is quite sufficient. - if kwargs['db'] == SYNCDB_DATABASE: + if kwargs['db'] == MIGRATE_DATABASE: self.call_counter = self.call_counter + 1 self.call_args = kwargs - # we need to test only one call of syncdb - signals.pre_syncdb.disconnect(pre_syncdb_receiver, sender=models) + # we need to test only one call of migrate + signals.pre_migrate.disconnect(pre_migrate_receiver, sender=models) # We connect receiver here and not in unit test code because we need to @@ -48,32 +48,32 @@ class OneTimeReceiver(object): # # 1. Test runner imports this module. # 2. We connect receiver. -# 3. Test runner calls syncdb for create default database. +# 3. Test runner calls migrate for create default database. # 4. Test runner execute our unit test code. -pre_syncdb_receiver = OneTimeReceiver() -signals.pre_syncdb.connect(pre_syncdb_receiver, sender=models) +pre_migrate_receiver = OneTimeReceiver() +signals.pre_migrate.connect(pre_migrate_receiver, sender=models) -class SyncdbSignalTests(TestCase): +class MigrateSignalTests(TestCase): available_apps = [ - 'syncdb_signals', + 'migrate_signals', ] - def test_pre_syncdb_call_time(self): - self.assertEqual(pre_syncdb_receiver.call_counter, 1) + def test_pre_migrate_call_time(self): + self.assertEqual(pre_migrate_receiver.call_counter, 1) - def test_pre_syncdb_args(self): - r = PreSyncdbReceiver() - signals.pre_syncdb.connect(r, sender=models) - management.call_command('syncdb', database=SYNCDB_DATABASE, - verbosity=SYNCDB_VERBOSITY, interactive=SYNCDB_INTERACTIVE, + def test_pre_migrate_args(self): + r = PreMigrateReceiver() + signals.pre_migrate.connect(r, sender=models) + management.call_command('migrate', database=MIGRATE_DATABASE, + verbosity=MIGRATE_VERBOSITY, interactive=MIGRATE_INTERACTIVE, load_initial_data=False, stdout=six.StringIO()) args = r.call_args self.assertEqual(r.call_counter, 1) - self.assertEqual(set(args), set(PRE_SYNCDB_ARGS)) + self.assertEqual(set(args), set(PRE_MIGRATE_ARGS)) self.assertEqual(args['app'], models) - self.assertEqual(args['verbosity'], SYNCDB_VERBOSITY) - self.assertEqual(args['interactive'], SYNCDB_INTERACTIVE) + self.assertEqual(args['verbosity'], MIGRATE_VERBOSITY) + self.assertEqual(args['interactive'], MIGRATE_INTERACTIVE) self.assertEqual(args['db'], 'default') diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py index 629cb1237c..b1c0978385 100644 --- a/tests/multiple_database/tests.py +++ b/tests/multiple_database/tests.py @@ -1019,7 +1019,7 @@ class RouterTestCase(TestCase): self.assertEqual(Book.objects.db_manager('default').db, 'default') self.assertEqual(Book.objects.db_manager('default').all().db, 'default') - def test_syncdb_selection(self): + def test_migrate_selection(self): "Synchronization behavior is predictable" self.assertTrue(router.allow_migrate('default', User)) @@ -1921,7 +1921,7 @@ class SyncOnlyDefaultDatabaseRouter(object): return db == DEFAULT_DB_ALIAS -class SyncDBTestCase(TestCase): +class MigrateTestCase(TestCase): available_apps = [ 'multiple_database', @@ -1930,27 +1930,27 @@ class SyncDBTestCase(TestCase): ] multi_db = True - def test_syncdb_to_other_database(self): - """Regression test for #16039: syncdb with --database option.""" + def test_migrate_to_other_database(self): + """Regression test for #16039: migrate with --database option.""" cts = ContentType.objects.using('other').filter(app_label='multiple_database') count = cts.count() self.assertGreater(count, 0) cts.delete() - management.call_command('syncdb', verbosity=0, interactive=False, + management.call_command('migrate', verbosity=0, interactive=False, load_initial_data=False, database='other') self.assertEqual(cts.count(), count) - def test_syncdb_to_other_database_with_router(self): - """Regression test for #16039: syncdb with --database option.""" + def test_migrate_to_other_database_with_router(self): + """Regression test for #16039: migrate with --database option.""" cts = ContentType.objects.using('other').filter(app_label='multiple_database') cts.delete() try: old_routers = router.routers router.routers = [SyncOnlyDefaultDatabaseRouter()] - management.call_command('syncdb', verbosity=0, interactive=False, + management.call_command('migrate', verbosity=0, interactive=False, load_initial_data=False, database='other') finally: router.routers = old_routers diff --git a/tests/proxy_model_inheritance/tests.py b/tests/proxy_model_inheritance/tests.py index dda09a080f..9941506303 100644 --- a/tests/proxy_model_inheritance/tests.py +++ b/tests/proxy_model_inheritance/tests.py @@ -17,9 +17,9 @@ from .models import (ConcreteModel, ConcreteModelSubclass, @override_settings(INSTALLED_APPS=('app1', 'app2')) class ProxyModelInheritanceTests(TransactionTestCase): """ - Proxy model inheritance across apps can result in syncdb not creating the table + Proxy model inheritance across apps can result in migrate not creating the table for the proxied model (as described in #12286). This test creates two dummy - apps and calls syncdb, then verifies that the table has been created. + apps and calls migrate, then verifies that the table has been created. """ available_apps = [] @@ -42,7 +42,7 @@ class ProxyModelInheritanceTests(TransactionTestCase): def test_table_exists(self): try: cache.set_available_apps(settings.INSTALLED_APPS) - call_command('syncdb', verbosity=0) + call_command('migrate', verbosity=0) finally: cache.unset_available_apps() from .app1.models import ProxyModel diff --git a/tests/schema/models.py b/tests/schema/models.py index dc717ec105..b79f54699d 100644 --- a/tests/schema/models.py +++ b/tests/schema/models.py @@ -3,7 +3,7 @@ from django.db.models.loading import BaseAppCache # Because we want to test creation and deletion of these as separate things, # these models are all inserted into a separate AppCache so the main test -# runner doesn't syncdb them. +# runner doesn't migrate them. new_app_cache = BaseAppCache() diff --git a/tests/swappable_models/tests.py b/tests/swappable_models/tests.py index 2e2d544cea..85484615a3 100644 --- a/tests/swappable_models/tests.py +++ b/tests/swappable_models/tests.py @@ -38,9 +38,9 @@ class SwappableModelTests(TestCase): Permission.objects.filter(content_type__app_label='swappable_models').delete() ContentType.objects.filter(app_label='swappable_models').delete() - # Re-run syncdb. This will re-build the permissions and content types. + # Re-run migrate. This will re-build the permissions and content types. new_io = StringIO() - management.call_command('syncdb', load_initial_data=False, interactive=False, stdout=new_io) + management.call_command('migrate', load_initial_data=False, interactive=False, stdout=new_io) # Check that content types and permissions exist for the swapped model, # but not for the swappable model. diff --git a/tests/syncdb_signals/models.py b/tests/syncdb_signals/models.py deleted file mode 100644 index c41d993e94..0000000000 --- a/tests/syncdb_signals/models.py +++ /dev/null @@ -1,11 +0,0 @@ -# from django.db import models - - -# class Author(models.Model): -# name = models.CharField(max_length=100) - -# class Meta: -# ordering = ['name'] - -# def __unicode__(self): -# return self.name diff --git a/tests/tablespaces/models.py b/tests/tablespaces/models.py index 7d7b96380c..98ec688a53 100644 --- a/tests/tablespaces/models.py +++ b/tests/tablespaces/models.py @@ -4,7 +4,7 @@ from django.db import models # to create the tables for models where db_tablespace is set. To avoid this # problem, we mark the models as unmanaged, and temporarily revert them to # managed during each test. We also set them to use the same tables as the -# "reference" models to avoid errors when other tests run 'syncdb' +# "reference" models to avoid errors when other tests run 'migrate' # (proxy_models_inheritance does). class ScientistRef(models.Model):