summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2010-08-30 11:58:26 +0000
committerLuke Plant <L.Plant.98@cantab.net>2010-08-30 11:58:26 +0000
commit5deb3e5a6240b18e6fb03b7adc2656eeaa5be396 (patch)
tree212dfaa7146727f4eaa6df330247364c5025bab2 /tests
parentf9d051d5f0ea5853373150c689daf4f5a691ef99 (diff)
Fixed #14162 - Dumpdata needs an option to use the base manager instead of the default manager
Thanks to PaulM for suggestion and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@13669 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/fixtures/models.py8
-rw-r--r--tests/modeltests/fixtures/tests.py16
2 files changed, 22 insertions, 2 deletions
diff --git a/tests/modeltests/fixtures/models.py b/tests/modeltests/fixtures/models.py
index 216a8e2502..0035bcc7e0 100644
--- a/tests/modeltests/fixtures/models.py
+++ b/tests/modeltests/fixtures/models.py
@@ -72,6 +72,14 @@ class Person(models.Model):
def natural_key(self):
return (self.name,)
+class SpyManager(PersonManager):
+ def get_query_set(self):
+ return super(SpyManager, self).get_query_set().filter(cover_blown=False)
+
+class Spy(Person):
+ objects = SpyManager()
+ cover_blown = models.BooleanField(default=False)
+
class Visa(models.Model):
person = models.ForeignKey(Person)
permissions = models.ManyToManyField(Permission, blank=True)
diff --git a/tests/modeltests/fixtures/tests.py b/tests/modeltests/fixtures/tests.py
index e818423b48..799a7328da 100644
--- a/tests/modeltests/fixtures/tests.py
+++ b/tests/modeltests/fixtures/tests.py
@@ -6,7 +6,7 @@ from django.conf import settings
from django.core import management
from django.db import DEFAULT_DB_ALIAS
-from models import Article, Blog, Book, Category, Person, Tag, Visa
+from models import Article, Blog, Book, Category, Person, Spy, Tag, Visa
class TestCaseFixtureLoadingTests(TestCase):
fixtures = ['fixture1.json', 'fixture2.json']
@@ -24,12 +24,13 @@ class TestCaseFixtureLoadingTests(TestCase):
class FixtureLoadingTests(TestCase):
def _dumpdata_assert(self, args, output, format='json', natural_keys=False,
- exclude_list=[]):
+ use_base_manager=False, exclude_list=[]):
new_io = StringIO.StringIO()
management.call_command('dumpdata', *args, **{'format':format,
'stdout':new_io,
'stderr':new_io,
'use_natural_keys':natural_keys,
+ 'use_base_manager':use_base_manager,
'exclude': exclude_list})
command_output = new_io.getvalue().strip()
self.assertEqual(command_output, output)
@@ -197,6 +198,17 @@ class FixtureLoadingTests(TestCase):
'',
exclude_list=['fixtures.FooModel'])
+ def test_dumpdata_with_filtering_manager(self):
+ Spy(name='Paul').save()
+ Spy(name='Alex', cover_blown=True).save()
+ self.assertQuerysetEqual(Spy.objects.all(),
+ ['<Spy: Paul>'])
+ # Use the default manager
+ self._dumpdata_assert(['fixtures.Spy'],'[{"pk": 1, "model": "fixtures.spy", "fields": {"cover_blown": false}}]')
+ # Dump using Django's base manager. Should return all objects,
+ # even those normally filtered by the manager
+ self._dumpdata_assert(['fixtures.Spy'], '[{"pk": 2, "model": "fixtures.spy", "fields": {"cover_blown": true}}, {"pk": 1, "model": "fixtures.spy", "fields": {"cover_blown": false}}]', use_base_manager=True)
+
def test_compress_format_loading(self):
# Load fixture 4 (compressed), using format specification
management.call_command('loaddata', 'fixture4.json', verbosity=0, commit=False)