Code

Ticket #13839: test13839.patch

File test13839.patch, 2.0 KB (added by mk, 4 years ago)
  • tests/regressiontests/select_related_onetoone/models.py

    diff --git a/tests/regressiontests/select_related_onetoone/models.py b/tests/regressiontests/select_related_onetoone/models.py
    index 3d6da9b..1be9eb8 100644
    a b class Image(models.Model): 
    5252class Product(models.Model): 
    5353    name = models.CharField(max_length=100) 
    5454    image = models.OneToOneField(Image, null=True) 
     55 
     56 
     57class UserChild(User): 
     58    pass 
  • tests/regressiontests/select_related_onetoone/tests.py

    diff --git a/tests/regressiontests/select_related_onetoone/tests.py b/tests/regressiontests/select_related_onetoone/tests.py
    index 4ccb584..26d76fa 100644
    a b from django.conf import settings 
    33from django.test import TestCase 
    44 
    55from models import (User, UserProfile, UserStat, UserStatResult, StatDetails, 
    6     AdvancedUserStat, Image, Product) 
     6    AdvancedUserStat, Image, Product, UserChild) 
    77 
    88class ReverseSelectRelatedTestCase(TestCase): 
    99    def setUp(self): 
    class ReverseSelectRelatedTestCase(TestCase): 
    9292        p2 = Product.objects.create(name="Talking Django Plushie") 
    9393 
    9494        self.assertEqual(len(Product.objects.select_related("image")), 2) 
     95 
     96    def test_select_related_with_inheritance(self): 
     97        """ 
     98        select_related should not pre-fill the SingleRelatedObjectDescriptor 
     99        cache with None when the related object does not exist. 
     100 
     101        This tests both the inheritance and the standard OneToOneField usage 
     102        case. 
     103        """ 
     104        User.objects.create() 
     105        user = User.objects.all()[0] 
     106 
     107        self.assertRaises(UserChild.DoesNotExist, lambda: user.userchild) 
     108        self.assertRaises(UserProfile.DoesNotExist, lambda: user.userprofile) 
     109 
     110        user = User.objects.all().select_related('userchild', 'userprofile')[0] 
     111        self.assertRaises(UserChild.DoesNotExist, lambda: user.userchild) 
     112        self.assertRaises(UserProfile.DoesNotExist, lambda: user.userprofile)