diff options
| author | Matthijs Kooijman <matthijs@stdin.nl> | 2020-04-07 11:58:21 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-04-07 15:40:14 +0200 |
| commit | fca36f3c9812a779d0b9d0db315dd056f5d75d87 (patch) | |
| tree | 2a3967a59eb19a44fc3b2c86decb943aae9f8c22 /tests | |
| parent | 481d8fc324545cc35b11311707ccebca6102838a (diff) | |
Refs #26291 -- Added tests for dumpdata with forward references in natural keys.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/fixtures/fixtures/forward_reference_fk_natural_key.json (renamed from tests/fixtures/fixtures/forward_reference_fk.json) | 0 | ||||
| -rw-r--r-- | tests/fixtures/fixtures/forward_reference_m2m_natural_key.json (renamed from tests/fixtures/fixtures/forward_reference_m2m.json) | 0 | ||||
| -rw-r--r-- | tests/fixtures/tests.py | 38 |
3 files changed, 33 insertions, 5 deletions
diff --git a/tests/fixtures/fixtures/forward_reference_fk.json b/tests/fixtures/fixtures/forward_reference_fk_natural_key.json index d3122c8823..d3122c8823 100644 --- a/tests/fixtures/fixtures/forward_reference_fk.json +++ b/tests/fixtures/fixtures/forward_reference_fk_natural_key.json diff --git a/tests/fixtures/fixtures/forward_reference_m2m.json b/tests/fixtures/fixtures/forward_reference_m2m_natural_key.json index 9e0f18e294..9e0f18e294 100644 --- a/tests/fixtures/fixtures/forward_reference_m2m.json +++ b/tests/fixtures/fixtures/forward_reference_m2m_natural_key.json diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index cf05717277..a1e9b8ccaf 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -788,22 +788,50 @@ class FixtureTransactionTests(DumpDataAssertMixin, TransactionTestCase): ]) -class ForwardReferenceTests(TestCase): - def test_forward_reference_fk(self): - management.call_command('loaddata', 'forward_reference_fk.json', verbosity=0) +class ForwardReferenceTests(DumpDataAssertMixin, TestCase): + def test_forward_reference_fk_natural_key(self): + management.call_command( + 'loaddata', + 'forward_reference_fk_natural_key.json', + verbosity=0, + ) self.assertEqual(NaturalKeyThing.objects.count(), 2) t1, t2 = NaturalKeyThing.objects.all() self.assertEqual(t1.other_thing, t2) self.assertEqual(t2.other_thing, t1) + self._dumpdata_assert( + ['fixtures'], + '[{"model": "fixtures.naturalkeything", ' + '"fields": {"key": "t1", "other_thing": ["t2"], "other_things": []}}, ' + '{"model": "fixtures.naturalkeything", ' + '"fields": {"key": "t2", "other_thing": ["t1"], "other_things": []}}]', + natural_primary_keys=True, + natural_foreign_keys=True, + ) - def test_forward_reference_m2m(self): - management.call_command('loaddata', 'forward_reference_m2m.json', verbosity=0) + def test_forward_reference_m2m_natural_key(self): + management.call_command( + 'loaddata', + 'forward_reference_m2m_natural_key.json', + verbosity=0, + ) self.assertEqual(NaturalKeyThing.objects.count(), 3) t1 = NaturalKeyThing.objects.get_by_natural_key('t1') self.assertQuerysetEqual( t1.other_things.order_by('key'), ['<NaturalKeyThing: t2>', '<NaturalKeyThing: t3>'] ) + self._dumpdata_assert( + ['fixtures'], + '[{"model": "fixtures.naturalkeything", ' + '"fields": {"key": "t1", "other_thing": null, "other_things": [["t2"], ["t3"]]}}, ' + '{"model": "fixtures.naturalkeything", ' + '"fields": {"key": "t2", "other_thing": null, "other_things": []}}, ' + '{"model": "fixtures.naturalkeything", ' + '"fields": {"key": "t3", "other_thing": null, "other_things": []}}]', + natural_primary_keys=True, + natural_foreign_keys=True, + ) class CircularReferenceTests(DumpDataAssertMixin, TestCase): |
