mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #26291 -- Allowed loaddata to handle forward references in natural_key fixtures.
This commit is contained in:
committed by
Tim Graham
parent
8f75d21a2e
commit
312eb5cb11
21
tests/fixtures/tests.py
vendored
21
tests/fixtures/tests.py
vendored
@@ -17,7 +17,8 @@ from django.db import IntegrityError, connection
|
||||
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
|
||||
|
||||
from .models import (
|
||||
Article, Category, PrimaryKeyUUIDModel, ProxySpy, Spy, Tag, Visa,
|
||||
Article, Category, NaturalKeyThing, PrimaryKeyUUIDModel, ProxySpy, Spy,
|
||||
Tag, Visa,
|
||||
)
|
||||
|
||||
|
||||
@@ -780,3 +781,21 @@ class FixtureTransactionTests(DumpDataAssertMixin, TransactionTestCase):
|
||||
'<Article: Time to reform copyright>',
|
||||
'<Article: Poker has no place on ESPN>',
|
||||
])
|
||||
|
||||
|
||||
class ForwardReferenceTests(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)
|
||||
|
||||
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>']
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user