Ticket #17565: test-1to1-backref-cache.patch

File test-1to1-backref-cache.patch, 1.3 KB (added by shai, 4 years ago)

Patch adding regression tests for OneToOneField back-reference caching

  • tests/regressiontests/one_to_one_regress/tests.py

    diff --git a/tests/regressiontests/one_to_one_regress/tests.py b/tests/regressiontests/one_to_one_regress/tests.py
    index 88980c2..859c410 100644
    a b class OneToOneRegressionTests(TestCase): 
    132132                Target.objects.exclude(pointer2=None),
    133133                []
    134134        )
     135
     136    def test_one_to_one_backref_cache(self):
     137        """
     138        Test that when an object is fetched through a 1-to-1 relation,
     139        the back-reference is cached on the newly fetched object
     140        """
     141        # Look up the objects again so that we get "fresh" objects
     142        r = Restaurant.objects.get(pk = self.r1.pk)
     143        p = r.place
     144        r2 = p.restaurant
     145        self.assertIs(r, r2)
     146
     147    def test_one_to_one_reverse_backref_cache(self):
     148        """
     149        Test that when an object is fetched through the reverse of a 1-to-1 relation,
     150        the reverse back-reference (really, forward-reference) is cached
     151        on the newly fetched object
     152        """
     153        # Look up the objects again so that we get "fresh" objects
     154        p = Place.objects.get(name="Demon Dogs")
     155        r = p.restaurant
     156        p2 = r.place
     157        self.assertIs(p, p2)
Back to Top