summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2010-11-22 18:02:33 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2010-11-22 18:02:33 +0000
commitc2de746ea5c95c9a0876b941e2de9fdbd97c6221 (patch)
tree2d262421eb33f8be329fcc2fda80d3445dc31e72 /tests
parent56b9e0c45f75338c928806aa59f7f33ff204c948 (diff)
[1.2.X] Fixed #14754 -- corrected using an aggregate in an F expressions when that queryset is later used in a subquery. Thanks to master for the patch. Backport of [14681].
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14682 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/aggregation_regress/models.py6
-rw-r--r--tests/regressiontests/aggregation_regress/tests.py24
2 files changed, 21 insertions, 9 deletions
diff --git a/tests/regressiontests/aggregation_regress/models.py b/tests/regressiontests/aggregation_regress/models.py
index 783c21956a..ccef9a5fc8 100644
--- a/tests/regressiontests/aggregation_regress/models.py
+++ b/tests/regressiontests/aggregation_regress/models.py
@@ -1,8 +1,5 @@
# coding: utf-8
-import pickle
-
-from django.db import connection, models, DEFAULT_DB_ALIAS
-from django.conf import settings
+from django.db import models
class Author(models.Model):
@@ -49,7 +46,6 @@ class Store(models.Model):
def __unicode__(self):
return self.name
-
class Entries(models.Model):
EntryID = models.AutoField(primary_key=True, db_column='Entry ID')
Entry = models.CharField(unique=True, max_length=50)
diff --git a/tests/regressiontests/aggregation_regress/tests.py b/tests/regressiontests/aggregation_regress/tests.py
index 2429ffec94..6c09c10d72 100644
--- a/tests/regressiontests/aggregation_regress/tests.py
+++ b/tests/regressiontests/aggregation_regress/tests.py
@@ -1,13 +1,15 @@
import datetime
+import pickle
from decimal import Decimal
+from operator import attrgetter
-from django.core.exceptions import FieldError
from django.conf import settings
-from django.test import TestCase, Approximate
+from django.core.exceptions import FieldError
from django.db import DEFAULT_DB_ALIAS
from django.db.models import Count, Max, Avg, Sum, StdDev, Variance, F
+from django.test import TestCase, Approximate
-from regressiontests.aggregation_regress.models import *
+from models import Author, Book, Publisher, Clues, Entries, HardbackBook
def run_stddev_tests():
@@ -501,7 +503,7 @@ class AggregationTests(TestCase):
# Regression for #10197 -- Queries with aggregates can be pickled.
# First check that pickling is possible at all. No crash = success
qs = Book.objects.annotate(num_authors=Count('authors'))
- out = pickle.dumps(qs)
+ pickle.dumps(qs)
# Then check that the round trip works.
query = qs.query.get_compiler(qs.db).as_sql()[0]
@@ -659,6 +661,20 @@ class AggregationTests(TestCase):
Author.objects.count()
)
+ def test_f_expression_annotation(self):
+ # Books with less than 200 pages per author.
+ qs = Book.objects.values("name").annotate(
+ n_authors=Count("authors")
+ ).filter(
+ pages__lt=F("n_authors") * 200
+ ).values_list("pk")
+ self.assertQuerysetEqual(
+ Book.objects.filter(pk__in=qs), [
+ "Python Web Development with Django"
+ ],
+ attrgetter("name")
+ )
+
if run_stddev_tests():
def test_stddev(self):
self.assertEqual(