summaryrefslogtreecommitdiff
path: root/tests/expressions
diff options
context:
space:
mode:
authorMatthew Wilkes <git@matthewwilkes.name>2017-06-18 16:53:40 +0100
committerTim Graham <timograham@gmail.com>2018-02-10 19:08:55 -0500
commit2162f0983de0dfe2178531638ce7ea56f54dd4e7 (patch)
treebb1e859159200fa7ebeeaa02ec3908e1cf5d2655 /tests/expressions
parentbf26f66029bca94b007a2452679ac004598364a6 (diff)
Fixed #24747 -- Allowed transforms in QuerySet.order_by() and distinct(*fields).
Diffstat (limited to 'tests/expressions')
-rw-r--r--tests/expressions/tests.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
index c2e3fb391a..2980d750c8 100644
--- a/tests/expressions/tests.py
+++ b/tests/expressions/tests.py
@@ -1363,6 +1363,40 @@ class ValueTests(TestCase):
ExpressionList()
+class FieldTransformTests(TestCase):
+
+ @classmethod
+ def setUpTestData(cls):
+ cls.sday = sday = datetime.date(2010, 6, 25)
+ cls.stime = stime = datetime.datetime(2010, 6, 25, 12, 15, 30, 747000)
+ cls.ex1 = Experiment.objects.create(
+ name='Experiment 1',
+ assigned=sday,
+ completed=sday + datetime.timedelta(2),
+ estimated_time=datetime.timedelta(2),
+ start=stime,
+ end=stime + datetime.timedelta(2),
+ )
+
+ def test_month_aggregation(self):
+ self.assertEqual(
+ Experiment.objects.aggregate(month_count=Count('assigned__month')),
+ {'month_count': 1}
+ )
+
+ def test_transform_in_values(self):
+ self.assertQuerysetEqual(
+ Experiment.objects.values('assigned__month'),
+ ["{'assigned__month': 6}"]
+ )
+
+ def test_multiple_transforms_in_values(self):
+ self.assertQuerysetEqual(
+ Experiment.objects.values('end__date__month'),
+ ["{'end__date__month': 6}"]
+ )
+
+
class ReprTests(TestCase):
def test_expressions(self):