diff --git a/tests/fixtures_regress/fixtures/circular-fk.json b/tests/fixtures_regress/fixtures/circular-fk.json
new file mode 100644
index 0000000..13a4eac
|
-
|
+
|
|
| | 1 | [ |
| | 2 | { |
| | 3 | "model": "fixtures_regress.order", |
| | 4 | "pk": 1, |
| | 5 | "fields": { |
| | 6 | "bill_address": 1 |
| | 7 | } |
| | 8 | }, |
| | 9 | { |
| | 10 | "model": "fixtures_regress.orderaddress", |
| | 11 | "pk": 1, |
| | 12 | "fields": { |
| | 13 | "order": 1 |
| | 14 | } |
| | 15 | } |
| | 16 | ] |
diff --git a/tests/fixtures_regress/models.py b/tests/fixtures_regress/models.py
index 1cc30d2..d50d955 100644
|
a
|
b
|
class ExternalDependency(models.Model):
|
| 235 | 235 | # Model for regression test of #11101 |
| 236 | 236 | class Thingy(models.Model): |
| 237 | 237 | name = models.CharField(max_length=255) |
| | 238 | |
| | 239 | |
| | 240 | class Order(models.Model): |
| | 241 | bill_address = models.OneToOneField( |
| | 242 | 'fixtures_regress.OrderAddress', |
| | 243 | null=True, |
| | 244 | on_delete=models.SET_NULL, |
| | 245 | related_name='bill_address_order', |
| | 246 | verbose_name=u'bill to address' |
| | 247 | ) |
| | 248 | |
| | 249 | class OrderAddress(models.Model): |
| | 250 | order = models.ForeignKey('fixtures_regress.Order', verbose_name=u'order') |
diff --git a/tests/fixtures_regress/tests.py b/tests/fixtures_regress/tests.py
index 0f6ac65..2242479 100644
|
a
|
b
|
from .models import (Animal, Stuff, Absolute, Parent, Child, Article, Widget,
|
| 26 | 26 | ExternalDependency, Thingy) |
| 27 | 27 | |
| 28 | 28 | |
| 29 | | class TestFixtures(TestCase): |
| | 29 | class FixtureTests(TestCase): |
| 30 | 30 | |
| 31 | 31 | def animal_pre_save_check(self, signal, sender, instance, **kwargs): |
| 32 | 32 | self.pre_save_checks.append( |
| … |
… |
class NaturalKeyFixtureTests(TestCase):
|
| 683 | 683 | ) |
| 684 | 684 | |
| 685 | 685 | |
| 686 | | class TestTicket11101(TransactionTestCase): |
| | 686 | class TransactionFixtureTests(TransactionTestCase): |
| 687 | 687 | |
| 688 | 688 | available_apps = [ |
| 689 | 689 | 'fixtures_regress', |
| … |
… |
class TestTicket11101(TransactionTestCase):
|
| 691 | 691 | 'django.contrib.contenttypes', |
| 692 | 692 | ] |
| 693 | 693 | |
| 694 | | def ticket_11101(self): |
| 695 | | management.call_command( |
| 696 | | 'loaddata', |
| 697 | | 'thingy.json', |
| 698 | | verbosity=0, |
| 699 | | commit=False |
| 700 | | ) |
| 701 | | self.assertEqual(Thingy.objects.count(), 1) |
| 702 | | transaction.rollback() |
| 703 | | self.assertEqual(Thingy.objects.count(), 0) |
| 704 | | transaction.commit() |
| 705 | | |
| 706 | 694 | @skipUnlessDBFeature('supports_transactions') |
| 707 | 695 | def test_ticket_11101(self): |
| 708 | 696 | """Test that fixtures can be rolled back (ticket #11101).""" |
| 709 | 697 | transaction.set_autocommit(False) |
| 710 | 698 | try: |
| 711 | | self.ticket_11101() |
| | 699 | management.call_command( |
| | 700 | 'loaddata', |
| | 701 | 'thingy.json', |
| | 702 | verbosity=0, |
| | 703 | commit=False |
| | 704 | ) |
| | 705 | self.assertEqual(Thingy.objects.count(), 1) |
| | 706 | transaction.rollback() |
| | 707 | self.assertEqual(Thingy.objects.count(), 0) |
| | 708 | transaction.commit() |
| 712 | 709 | finally: |
| 713 | 710 | transaction.set_autocommit(True) |
| | 711 | |
| | 712 | def test_circular_relation(self): |
| | 713 | """Test that fixtures may contain circular relations (#20666).""" |
| | 714 | management.call_command( |
| | 715 | 'loaddata', |
| | 716 | 'circular-fk.json', |
| | 717 | verbosity=0 |
| | 718 | ) |