mirror of https://github.com/django/django.git
Updated syncdb -> migrate in tests.
This commit is contained in:
parent
8f7f8bf688
commit
3db66b1d65
|
@ -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(), [
|
||||
'<Book: Achieving self-awareness of Python programs>'
|
||||
])
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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')
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue