Ticket #11890: 11890_regression_tests.diff

File 11890_regression_tests.diff, 5.5 KB (added by ruosteinen, 15 years ago)

Regression test diff against trunk.

  • tests/regressiontests/defer_regress/models.py

     
    3535    num = models.FloatField()
    3636    name = models.CharField(max_length=16)
    3737
     38# Models for 11890 -- do not change since bug includes a really
     39# esoteric edge case
     40class Person(models.Model):
     41    first_name = models.CharField(max_length=200)
     42    last_name = models.CharField(max_length=50)
     43    best_friend = models.ForeignKey('self', blank=True, null=True, editable=False)
     44       
     45    nick_name = models.CharField(max_length=50, blank=True, null=True)
     46
     47class Candy(models.Model):
     48    owner = models.ForeignKey(Person, related_name="candies")
     49    qty = models.PositiveIntegerField(default=0)
     50
     51
    3852__test__ = {"regression_tests": """
    3953Deferred fields should really be deferred and not accidentally use the field's
    4054default value just because they aren't passed to __init__.
     
    139153# Regression for #11936 - loading.get_models should not return deferred models by default.
    140154>>> from django.db.models.loading import get_models
    141155>>> sorted(get_models(models.get_app('defer_regress')), key=lambda obj: obj._meta.object_name)
    142 [<class 'regressiontests.defer_regress.models.Child'>, <class 'regressiontests.defer_regress.models.Item'>, <class 'regressiontests.defer_regress.models.Leaf'>, <class 'regressiontests.defer_regress.models.RelatedItem'>, <class 'regressiontests.defer_regress.models.ResolveThis'>]
     156[<class 'regressiontests.defer_regress.models.Candy'>, <class 'regressiontests.defer_regress.models.Child'>, <class 'regressiontests.defer_regress.models.Item'>, <class 'regressiontests.defer_regress.models.Leaf'>, <class 'regressiontests.defer_regress.models.Person'>, <class 'regressiontests.defer_regress.models.RelatedItem'>, <class 'regressiontests.defer_regress.models.ResolveThis'>]
    143157
    144158>>> sorted(get_models(models.get_app('defer_regress'), include_deferred=True), key=lambda obj: obj._meta.object_name)
    145 [<class 'regressiontests.defer_regress.models.Child'>, <class 'regressiontests.defer_regress.models.Item'>, <class 'regressiontests.defer_regress.models.Item_Deferred_name'>, <class 'regressiontests.defer_regress.models.Item_Deferred_name_other_value_text'>, <class 'regressiontests.defer_regress.models.Item_Deferred_other_value_text_value'>, <class 'regressiontests.defer_regress.models.Item_Deferred_text_value'>, <class 'regressiontests.defer_regress.models.Leaf'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_name_value'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_second_child_value'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_value'>, <class 'regressiontests.defer_regress.models.RelatedItem'>, <class 'regressiontests.defer_regress.models.RelatedItem_Deferred_item_id'>, <class 'regressiontests.defer_regress.models.ResolveThis'>, <class 'regressiontests.defer_regress.models.ResolveThis_Deferred_num'>]
     159[<class 'regressiontests.defer_regress.models.Candy'>, <class 'regressiontests.defer_regress.models.Child'>, <class 'regressiontests.defer_regress.models.Item'>, <class 'regressiontests.defer_regress.models.Item_Deferred_name'>, <class 'regressiontests.defer_regress.models.Item_Deferred_name_other_value_text'>, <class 'regressiontests.defer_regress.models.Item_Deferred_other_value_text_value'>, <class 'regressiontests.defer_regress.models.Item_Deferred_text_value'>, <class 'regressiontests.defer_regress.models.Leaf'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_name_value'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_second_child_value'>, <class 'regressiontests.defer_regress.models.Leaf_Deferred_value'>, <class 'regressiontests.defer_regress.models.Person'>, <class 'regressiontests.defer_regress.models.RelatedItem'>, <class 'regressiontests.defer_regress.models.RelatedItem_Deferred_item_id'>, <class 'regressiontests.defer_regress.models.ResolveThis'>, <class 'regressiontests.defer_regress.models.ResolveThis_Deferred_num'>]
    146160
     161# Regression for #11890 - Defer/only + annotate is broken
     162>>> from django.db.models import Count, Avg
     163>>> Item.objects.all().delete()
     164>>> RelatedItem.objects.all().delete()
     165>>> i = Item.objects.create(name='Bug #11890', value=1)
     166>>> RelatedItem.objects.create(item=i)
     167<RelatedItem: RelatedItem object>
     168>>> RelatedItem.objects.create(item=i)
     169<RelatedItem: RelatedItem object>
     170>>> counted = Item.objects.only('name').annotate(Count('relateditem'))
     171>>> counted.count()
     1721
     173>>> counted[0].relateditem__count
     1742
     175
     176# Adding up some spice since result row index offset is affected by extra selections
     177>>> counted = Item.objects.extra(select={'past': 'now()'}).annotate(rel_count=Count('relateditem'), avg_id=Avg('id')).extra(select={'sometime': 'now()'})
     178>>> counted.count()
     1791
     180>>> counted[0].rel_count
     1812
     182
     183# Rather interestingly, all those select_related and defer are required to
     184# trigger some edge case behaviour
     185>>> from django.db.models import Sum;
     186>>> Person.objects.all().delete()
     187>>> Candy.objects.all().delete()
     188>>> p = Person.objects.create(first_name='Mr', last_name='Egotistic')
     189>>> p.best_friend = p
     190>>> p.id = 1            # For determinism
     191>>> p.save()
     192>>> creations = [Candy(pk=n, owner_id=p.pk, qty=42).save() for n in xrange(10)]
     193>>> Candy.objects.aggregate(Sum('qty'))['qty__sum']
     194378
     195>>> Person.objects.annotate(Sum('candies__qty')).select_related('best_friend').defer('first_name','best_friend__nick_name').get(pk=p.pk).candies__qty__sum
     196378
    147197"""
    148198}
    149199
Back to Top