Kaydet (Commit) 3db66b1d authored tarafından Tim Graham's avatar Tim Graham

Updated syncdb -> migrate in tests.

üst 8f7f8bf6
...@@ -48,7 +48,7 @@ class DumpDataAssertMixin(object): ...@@ -48,7 +48,7 @@ class DumpDataAssertMixin(object):
class FixtureLoadingTests(DumpDataAssertMixin, TestCase): class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
def test_initial_data(self): 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(), [ self.assertQuerysetEqual(Book.objects.all(), [
'<Book: Achieving self-awareness of Python programs>' '<Book: Achieving self-awareness of Python programs>'
]) ])
......
...@@ -30,12 +30,12 @@ class TestNoInitialDataLoading(TransactionTestCase): ...@@ -30,12 +30,12 @@ class TestNoInitialDataLoading(TransactionTestCase):
available_apps = ['fixtures_model_package'] available_apps = ['fixtures_model_package']
def test_syncdb(self): def test_migrate(self):
with transaction.atomic(): with transaction.atomic():
Book.objects.all().delete() Book.objects.all().delete()
management.call_command( management.call_command(
'syncdb', 'migrate',
verbosity=0, verbosity=0,
load_initial_data=False load_initial_data=False
) )
...@@ -64,7 +64,7 @@ class TestNoInitialDataLoading(TransactionTestCase): ...@@ -64,7 +64,7 @@ class TestNoInitialDataLoading(TransactionTestCase):
class FixtureTestCase(TestCase): class FixtureTestCase(TestCase):
def test_initial_data(self): def test_initial_data(self):
"Fixtures can load initial data into models defined in packages" "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( self.assertQuerysetEqual(
Book.objects.all(), [ Book.objects.all(), [
'Achieving self-awareness of Python programs' 'Achieving self-awareness of Python programs'
......
...@@ -24,7 +24,7 @@ class InitialSQLTests(TestCase): ...@@ -24,7 +24,7 @@ class InitialSQLTests(TestCase):
def test_custom_sql(self): def test_custom_sql(self):
""" """
Simulate the custom SQL loading by syncdb. Simulate the custom SQL loading by migrate.
""" """
connection = connections[DEFAULT_DB_ALIAS] connection = connections[DEFAULT_DB_ALIAS]
custom_sql = custom_sql_for_model(Simple, no_style(), connection) custom_sql = custom_sql_for_model(Simple, no_style(), connection)
......
...@@ -57,7 +57,7 @@ class Worksheet(models.Model): ...@@ -57,7 +57,7 @@ class Worksheet(models.Model):
# Regression for #11226 -- A model with the same name that another one to # 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 # which it has a m2m relation. This shouldn't cause a name clash between
# the automatically created m2m intermediary table FK field names when # the automatically created m2m intermediary table FK field names when
# running syncdb # running migrate
class User(models.Model): class User(models.Model):
name = models.CharField(max_length=30) name = models.CharField(max_length=30)
friends = models.ManyToManyField(auth.User) friends = models.ManyToManyField(auth.User)
......
...@@ -6,13 +6,13 @@ from django.utils import six ...@@ -6,13 +6,13 @@ from django.utils import six
from . import models from . import models
PRE_SYNCDB_ARGS = ['app', 'create_models', 'verbosity', 'interactive', 'db'] PRE_MIGRATE_ARGS = ['app', 'create_models', 'verbosity', 'interactive', 'db']
SYNCDB_DATABASE = 'default' MIGRATE_DATABASE = 'default'
SYNCDB_VERBOSITY = 1 MIGRATE_VERBOSITY = 1
SYNCDB_INTERACTIVE = False MIGRATE_INTERACTIVE = False
class PreSyncdbReceiver(object): class PreMigrateReceiver(object):
def __init__(self): def __init__(self):
self.call_counter = 0 self.call_counter = 0
self.call_args = None self.call_args = None
...@@ -24,7 +24,7 @@ class PreSyncdbReceiver(object): ...@@ -24,7 +24,7 @@ class PreSyncdbReceiver(object):
class OneTimeReceiver(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. several databases and several times for some of them.
""" """
...@@ -33,13 +33,13 @@ class OneTimeReceiver(object): ...@@ -33,13 +33,13 @@ class OneTimeReceiver(object):
self.call_args = None self.call_args = None
def __call__(self, signal, sender, **kwargs): 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. # 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_counter = self.call_counter + 1
self.call_args = kwargs self.call_args = kwargs
# we need to test only one call of syncdb # we need to test only one call of migrate
signals.pre_syncdb.disconnect(pre_syncdb_receiver, sender=models) signals.pre_migrate.disconnect(pre_migrate_receiver, sender=models)
# We connect receiver here and not in unit test code because we need to # We connect receiver here and not in unit test code because we need to
...@@ -48,32 +48,32 @@ class OneTimeReceiver(object): ...@@ -48,32 +48,32 @@ class OneTimeReceiver(object):
# #
# 1. Test runner imports this module. # 1. Test runner imports this module.
# 2. We connect receiver. # 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. # 4. Test runner execute our unit test code.
pre_syncdb_receiver = OneTimeReceiver() pre_migrate_receiver = OneTimeReceiver()
signals.pre_syncdb.connect(pre_syncdb_receiver, sender=models) signals.pre_migrate.connect(pre_migrate_receiver, sender=models)
class SyncdbSignalTests(TestCase): class MigrateSignalTests(TestCase):
available_apps = [ available_apps = [
'syncdb_signals', 'migrate_signals',
] ]
def test_pre_syncdb_call_time(self): def test_pre_migrate_call_time(self):
self.assertEqual(pre_syncdb_receiver.call_counter, 1) self.assertEqual(pre_migrate_receiver.call_counter, 1)
def test_pre_syncdb_args(self): def test_pre_migrate_args(self):
r = PreSyncdbReceiver() r = PreMigrateReceiver()
signals.pre_syncdb.connect(r, sender=models) signals.pre_migrate.connect(r, sender=models)
management.call_command('syncdb', database=SYNCDB_DATABASE, management.call_command('migrate', database=MIGRATE_DATABASE,
verbosity=SYNCDB_VERBOSITY, interactive=SYNCDB_INTERACTIVE, verbosity=MIGRATE_VERBOSITY, interactive=MIGRATE_INTERACTIVE,
load_initial_data=False, stdout=six.StringIO()) load_initial_data=False, stdout=six.StringIO())
args = r.call_args args = r.call_args
self.assertEqual(r.call_counter, 1) 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['app'], models)
self.assertEqual(args['verbosity'], SYNCDB_VERBOSITY) self.assertEqual(args['verbosity'], MIGRATE_VERBOSITY)
self.assertEqual(args['interactive'], SYNCDB_INTERACTIVE) self.assertEqual(args['interactive'], MIGRATE_INTERACTIVE)
self.assertEqual(args['db'], 'default') self.assertEqual(args['db'], 'default')
...@@ -1019,7 +1019,7 @@ class RouterTestCase(TestCase): ...@@ -1019,7 +1019,7 @@ class RouterTestCase(TestCase):
self.assertEqual(Book.objects.db_manager('default').db, 'default') self.assertEqual(Book.objects.db_manager('default').db, 'default')
self.assertEqual(Book.objects.db_manager('default').all().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" "Synchronization behavior is predictable"
self.assertTrue(router.allow_migrate('default', User)) self.assertTrue(router.allow_migrate('default', User))
...@@ -1921,7 +1921,7 @@ class SyncOnlyDefaultDatabaseRouter(object): ...@@ -1921,7 +1921,7 @@ class SyncOnlyDefaultDatabaseRouter(object):
return db == DEFAULT_DB_ALIAS return db == DEFAULT_DB_ALIAS
class SyncDBTestCase(TestCase): class MigrateTestCase(TestCase):
available_apps = [ available_apps = [
'multiple_database', 'multiple_database',
...@@ -1930,27 +1930,27 @@ class SyncDBTestCase(TestCase): ...@@ -1930,27 +1930,27 @@ class SyncDBTestCase(TestCase):
] ]
multi_db = True multi_db = True
def test_syncdb_to_other_database(self): def test_migrate_to_other_database(self):
"""Regression test for #16039: syncdb with --database option.""" """Regression test for #16039: migrate with --database option."""
cts = ContentType.objects.using('other').filter(app_label='multiple_database') cts = ContentType.objects.using('other').filter(app_label='multiple_database')
count = cts.count() count = cts.count()
self.assertGreater(count, 0) self.assertGreater(count, 0)
cts.delete() cts.delete()
management.call_command('syncdb', verbosity=0, interactive=False, management.call_command('migrate', verbosity=0, interactive=False,
load_initial_data=False, database='other') load_initial_data=False, database='other')
self.assertEqual(cts.count(), count) self.assertEqual(cts.count(), count)
def test_syncdb_to_other_database_with_router(self): def test_migrate_to_other_database_with_router(self):
"""Regression test for #16039: syncdb with --database option.""" """Regression test for #16039: migrate with --database option."""
cts = ContentType.objects.using('other').filter(app_label='multiple_database') cts = ContentType.objects.using('other').filter(app_label='multiple_database')
cts.delete() cts.delete()
try: try:
old_routers = router.routers old_routers = router.routers
router.routers = [SyncOnlyDefaultDatabaseRouter()] 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') load_initial_data=False, database='other')
finally: finally:
router.routers = old_routers router.routers = old_routers
......
...@@ -17,9 +17,9 @@ from .models import (ConcreteModel, ConcreteModelSubclass, ...@@ -17,9 +17,9 @@ from .models import (ConcreteModel, ConcreteModelSubclass,
@override_settings(INSTALLED_APPS=('app1', 'app2')) @override_settings(INSTALLED_APPS=('app1', 'app2'))
class ProxyModelInheritanceTests(TransactionTestCase): 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 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 = [] available_apps = []
...@@ -42,7 +42,7 @@ class ProxyModelInheritanceTests(TransactionTestCase): ...@@ -42,7 +42,7 @@ class ProxyModelInheritanceTests(TransactionTestCase):
def test_table_exists(self): def test_table_exists(self):
try: try:
cache.set_available_apps(settings.INSTALLED_APPS) cache.set_available_apps(settings.INSTALLED_APPS)
call_command('syncdb', verbosity=0) call_command('migrate', verbosity=0)
finally: finally:
cache.unset_available_apps() cache.unset_available_apps()
from .app1.models import ProxyModel from .app1.models import ProxyModel
......
...@@ -3,7 +3,7 @@ from django.db.models.loading import BaseAppCache ...@@ -3,7 +3,7 @@ from django.db.models.loading import BaseAppCache
# Because we want to test creation and deletion of these as separate things, # 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 # 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() new_app_cache = BaseAppCache()
......
...@@ -38,9 +38,9 @@ class SwappableModelTests(TestCase): ...@@ -38,9 +38,9 @@ class SwappableModelTests(TestCase):
Permission.objects.filter(content_type__app_label='swappable_models').delete() Permission.objects.filter(content_type__app_label='swappable_models').delete()
ContentType.objects.filter(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() 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, # Check that content types and permissions exist for the swapped model,
# but not for the swappable model. # but not for the swappable model.
......
# 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 ...@@ -4,7 +4,7 @@ from django.db import models
# to create the tables for models where db_tablespace is set. To avoid this # 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 # 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 # 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). # (proxy_models_inheritance does).
class ScientistRef(models.Model): class ScientistRef(models.Model):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment