Fixed #13308 -- Ensured that dumpdata correctly interacts with router allow_syncdb directions. Thanks to Francis (wizard_2) for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12940 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e9bbdb39de
commit
7b47609629
|
@ -1,7 +1,7 @@
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django.core import serializers
|
from django.core import serializers
|
||||||
from django.db import connections, DEFAULT_DB_ALIAS
|
from django.db import connections, router, DEFAULT_DB_ALIAS
|
||||||
from django.utils.datastructures import SortedDict
|
from django.utils.datastructures import SortedDict
|
||||||
|
|
||||||
from optparse import make_option
|
from optparse import make_option
|
||||||
|
@ -79,7 +79,7 @@ class Command(BaseCommand):
|
||||||
# Now collate the objects to be serialized.
|
# Now collate the objects to be serialized.
|
||||||
objects = []
|
objects = []
|
||||||
for model in sort_dependencies(app_list.items()):
|
for model in sort_dependencies(app_list.items()):
|
||||||
if not model._meta.proxy:
|
if not model._meta.proxy and router.allow_syncdb(using, model):
|
||||||
objects.extend(model._default_manager.using(using).all())
|
objects.extend(model._default_manager.using(using).all())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
import datetime
|
import datetime
|
||||||
import pickle
|
import pickle
|
||||||
|
import sys
|
||||||
|
from StringIO import StringIO
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.core import management
|
||||||
from django.db import connections, router, DEFAULT_DB_ALIAS
|
from django.db import connections, router, DEFAULT_DB_ALIAS
|
||||||
from django.db.utils import ConnectionRouter
|
from django.db.utils import ConnectionRouter
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
@ -1211,10 +1214,19 @@ class AuthTestCase(TestCase):
|
||||||
self.old_routers = router.routers
|
self.old_routers = router.routers
|
||||||
router.routers = [AuthRouter()]
|
router.routers = [AuthRouter()]
|
||||||
|
|
||||||
|
# Redirect stdout to a buffer so we can test
|
||||||
|
# the output of a management command
|
||||||
|
self.old_stdout = sys.stdout
|
||||||
|
self.stdout = StringIO()
|
||||||
|
sys.stdout = self.stdout
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
# Restore the 'other' database as an independent database
|
# Restore the 'other' database as an independent database
|
||||||
router.routers = self.old_routers
|
router.routers = self.old_routers
|
||||||
|
|
||||||
|
# Restore stdout
|
||||||
|
sys.stdout = self.old_stdout
|
||||||
|
|
||||||
def test_auth_manager(self):
|
def test_auth_manager(self):
|
||||||
"The methods on the auth manager obey database hints"
|
"The methods on the auth manager obey database hints"
|
||||||
# Create one user using default allocation policy
|
# Create one user using default allocation policy
|
||||||
|
@ -1243,6 +1255,22 @@ class AuthTestCase(TestCase):
|
||||||
self.assertEquals(User.objects.using('default').count(), 1)
|
self.assertEquals(User.objects.using('default').count(), 1)
|
||||||
self.assertEquals(User.objects.using('other').count(), 1)
|
self.assertEquals(User.objects.using('other').count(), 1)
|
||||||
|
|
||||||
|
def test_dumpdata(self):
|
||||||
|
"Check that dumpdata honors allow_syncdb restrictions on the router"
|
||||||
|
User.objects.create_user('alice', 'alice@example.com')
|
||||||
|
User.objects.db_manager('default').create_user('bob', 'bob@example.com')
|
||||||
|
|
||||||
|
# Check that dumping the default database doesn't try to include auth
|
||||||
|
# because allow_syncdb prohibits auth on default
|
||||||
|
self.stdout.flush()
|
||||||
|
management.call_command('dumpdata', 'auth', format='json', database='default')
|
||||||
|
self.assertEquals(self.stdout.getvalue(), '[]\n')
|
||||||
|
|
||||||
|
# Check that dumping the other database does include auth
|
||||||
|
self.stdout.flush()
|
||||||
|
management.call_command('dumpdata', 'auth', format='json', database='other')
|
||||||
|
self.assertTrue('alice@example.com' in self.stdout.getvalue())
|
||||||
|
|
||||||
class UserProfileTestCase(TestCase):
|
class UserProfileTestCase(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.old_auth_profile_module = getattr(settings, 'AUTH_PROFILE_MODULE', None)
|
self.old_auth_profile_module = getattr(settings, 'AUTH_PROFILE_MODULE', None)
|
||||||
|
@ -1307,7 +1335,6 @@ class FixtureTestCase(TestCase):
|
||||||
except Book.DoesNotExist:
|
except Book.DoesNotExist:
|
||||||
self.fail('"The Definitive Guide to Django" should exist on both databases')
|
self.fail('"The Definitive Guide to Django" should exist on both databases')
|
||||||
|
|
||||||
|
|
||||||
class PickleQuerySetTestCase(TestCase):
|
class PickleQuerySetTestCase(TestCase):
|
||||||
multi_db = True
|
multi_db = True
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue