summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPreston Holmes <preston@ptone.com>2013-05-19 12:39:14 +0200
committerPreston Holmes <preston@ptone.com>2013-05-19 09:10:40 -0700
commit6786920fd8a1dfa43bba8333548c2496847298af (patch)
tree572ca38edf73ec30095bd25f691b6879b230dfc1 /tests
parentbdde7feb26f89e580c2b21154196fe3f8c774677 (diff)
Fixed #16330 -- added --pks option in dumpdata command
Thanks to guettli for the initial ticket and patch, with additional work from mehmetakyuz and Kevin Brolly.
Diffstat (limited to 'tests')
-rw-r--r--tests/fixtures/tests.py44
1 files changed, 42 insertions, 2 deletions
diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py
index f954933046..e32522b929 100644
--- a/tests/fixtures/tests.py
+++ b/tests/fixtures/tests.py
@@ -27,14 +27,15 @@ class TestCaseFixtureLoadingTests(TestCase):
class DumpDataAssertMixin(object):
def _dumpdata_assert(self, args, output, format='json', natural_keys=False,
- use_base_manager=False, exclude_list=[]):
+ use_base_manager=False, exclude_list=[], primary_keys=[]):
new_io = six.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})
+ 'exclude': exclude_list,
+ 'primary_keys': primary_keys})
command_output = new_io.getvalue().strip()
if format == "json":
self.assertJSONEqual(command_output, output)
@@ -223,6 +224,45 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
# even those normally filtered by the manager
self._dumpdata_assert(['fixtures.Spy'], '[{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": true}}, {"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": false}}]' % (spy2.pk, spy1.pk), use_base_manager=True)
+ def test_dumpdata_with_pks(self):
+ management.call_command('loaddata', 'fixture1.json', verbosity=0, commit=False)
+ management.call_command('loaddata', 'fixture2.json', verbosity=0, commit=False)
+ self._dumpdata_assert(
+ ['fixtures.Article'],
+ '[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Copyright is fine the way it is", "pub_date": "2006-06-16T14:00:00"}}]',
+ primary_keys='2,3'
+ )
+
+ self._dumpdata_assert(
+ ['fixtures.Article'],
+ '[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}]',
+ primary_keys='2'
+ )
+
+ with six.assertRaisesRegex(self, management.CommandError,
+ "You can only use --pks option with one model"):
+ self._dumpdata_assert(
+ ['fixtures'],
+ '[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Copyright is fine the way it is", "pub_date": "2006-06-16T14:00:00"}}]',
+ primary_keys='2,3'
+ )
+
+ with six.assertRaisesRegex(self, management.CommandError,
+ "You can only use --pks option with one model"):
+ self._dumpdata_assert(
+ '',
+ '[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Copyright is fine the way it is", "pub_date": "2006-06-16T14:00:00"}}]',
+ primary_keys='2,3'
+ )
+
+ with six.assertRaisesRegex(self, management.CommandError,
+ "You can only use --pks option with one model"):
+ self._dumpdata_assert(
+ ['fixtures.Article', 'fixtures.category'],
+ '[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Copyright is fine the way it is", "pub_date": "2006-06-16T14:00:00"}}]',
+ primary_keys='2,3'
+ )
+
def test_compress_format_loading(self):
# Load fixture 4 (compressed), using format specification
management.call_command('loaddata', 'fixture4.json', verbosity=0, commit=False)