summaryrefslogtreecommitdiff
path: root/tests/fixtures
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2020-04-07 12:14:45 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-04-07 15:40:19 +0200
commit26799c650389bec255df581eb400730916919aa1 (patch)
tree604415e195654d23fa6d096bc27053381be1135a /tests/fixtures
parentfca36f3c9812a779d0b9d0db315dd056f5d75d87 (diff)
downloaddjango-26799c650389bec255df581eb400730916919aa1.tar.gz
Refs #26291 -- Added tests for dumpdata/loaddata with forward references without natural keys.
Diffstat (limited to 'tests/fixtures')
-rw-r--r--tests/fixtures/fixtures/forward_reference_fk.json18
-rw-r--r--tests/fixtures/fixtures/forward_reference_m2m.json24
-rw-r--r--tests/fixtures/tests.py32
3 files changed, 74 insertions, 0 deletions
diff --git a/tests/fixtures/fixtures/forward_reference_fk.json b/tests/fixtures/fixtures/forward_reference_fk.json
new file mode 100644
index 0000000000..c553d2b487
--- /dev/null
+++ b/tests/fixtures/fixtures/forward_reference_fk.json
@@ -0,0 +1,18 @@
+[
+ {
+ "model": "fixtures.naturalkeything",
+ "pk": 1,
+ "fields": {
+ "key": "t1",
+ "other_thing": 2
+ }
+ },
+ {
+ "model": "fixtures.naturalkeything",
+ "pk": 2,
+ "fields": {
+ "key": "t2",
+ "other_thing": 1
+ }
+ }
+]
diff --git a/tests/fixtures/fixtures/forward_reference_m2m.json b/tests/fixtures/fixtures/forward_reference_m2m.json
new file mode 100644
index 0000000000..927bac62b6
--- /dev/null
+++ b/tests/fixtures/fixtures/forward_reference_m2m.json
@@ -0,0 +1,24 @@
+[
+ {
+ "model": "fixtures.naturalkeything",
+ "pk": 1,
+ "fields": {
+ "key": "t1",
+ "other_things": [2, 3]
+ }
+ },
+ {
+ "model": "fixtures.naturalkeything",
+ "pk": 2,
+ "fields": {
+ "key": "t2"
+ }
+ },
+ {
+ "model": "fixtures.naturalkeything",
+ "pk": 3,
+ "fields": {
+ "key": "t3"
+ }
+ }
+]
diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py
index a1e9b8ccaf..2ed17d57be 100644
--- a/tests/fixtures/tests.py
+++ b/tests/fixtures/tests.py
@@ -789,6 +789,20 @@ class FixtureTransactionTests(DumpDataAssertMixin, TransactionTestCase):
class ForwardReferenceTests(DumpDataAssertMixin, TestCase):
+ def test_forward_reference_fk(self):
+ management.call_command('loaddata', 'forward_reference_fk.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", "pk": 1, '
+ '"fields": {"key": "t1", "other_thing": 2, "other_things": []}}, '
+ '{"model": "fixtures.naturalkeything", "pk": 2, '
+ '"fields": {"key": "t2", "other_thing": 1, "other_things": []}}]',
+ )
+
def test_forward_reference_fk_natural_key(self):
management.call_command(
'loaddata',
@@ -809,6 +823,24 @@ class ForwardReferenceTests(DumpDataAssertMixin, TestCase):
natural_foreign_keys=True,
)
+ def test_forward_reference_m2m(self):
+ management.call_command('loaddata', 'forward_reference_m2m.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", "pk": 1, '
+ '"fields": {"key": "t1", "other_thing": null, "other_things": [2, 3]}}, '
+ '{"model": "fixtures.naturalkeything", "pk": 2, '
+ '"fields": {"key": "t2", "other_thing": null, "other_things": []}}, '
+ '{"model": "fixtures.naturalkeything", "pk": 3, '
+ '"fields": {"key": "t3", "other_thing": null, "other_things": []}}]',
+ )
+
def test_forward_reference_m2m_natural_key(self):
management.call_command(
'loaddata',