Ticket #20666: 20666.patch

File 20666.patch, 3.3 KB (added by Aymeric Augustin, 11 years ago)
  • new file tests/fixtures_regress/fixtures/circular-fk.json

    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]
  • tests/fixtures_regress/models.py

    diff --git a/tests/fixtures_regress/models.py b/tests/fixtures_regress/models.py
    index 1cc30d2..d50d955 100644
    a b class ExternalDependency(models.Model):  
    235235# Model for regression test of #11101
    236236class Thingy(models.Model):
    237237    name = models.CharField(max_length=255)
     238
     239
     240class 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
     249class OrderAddress(models.Model):
     250    order = models.ForeignKey('fixtures_regress.Order', verbose_name=u'order')
  • tests/fixtures_regress/tests.py

    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,  
    2626    ExternalDependency, Thingy)
    2727
    2828
    29 class TestFixtures(TestCase):
     29class FixtureTests(TestCase):
    3030
    3131    def animal_pre_save_check(self, signal, sender, instance, **kwargs):
    3232        self.pre_save_checks.append(
    class NaturalKeyFixtureTests(TestCase):  
    683683        )
    684684
    685685
    686 class TestTicket11101(TransactionTestCase):
     686class TransactionFixtureTests(TransactionTestCase):
    687687
    688688    available_apps = [
    689689        'fixtures_regress',
    class TestTicket11101(TransactionTestCase):  
    691691        'django.contrib.contenttypes',
    692692    ]
    693693
    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 
    706694    @skipUnlessDBFeature('supports_transactions')
    707695    def test_ticket_11101(self):
    708696        """Test that fixtures can be rolled back (ticket #11101)."""
    709697        transaction.set_autocommit(False)
    710698        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()
    712709        finally:
    713710            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        )
Back to Top