diff options
author | Simon Charette <charette.s@gmail.com> | 2022-11-09 21:55:47 -0500 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-11-11 08:46:08 +0100 |
commit | a9d2d8d1c36a4338758a792c475965180629a59f (patch) | |
tree | f9265a79d0a80b83e12dafd6bba39d0c85cab07e /tests/expressions_window | |
parent | 99b4f90ec6b96e8c2a9f22b360d4eb5589763034 (diff) | |
download | django-a9d2d8d1c36a4338758a792c475965180629a59f.tar.gz |
Refs #28477 -- Reduced complexity of aggregation over qualify queries.
Diffstat (limited to 'tests/expressions_window')
-rw-r--r-- | tests/expressions_window/tests.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/tests/expressions_window/tests.py b/tests/expressions_window/tests.py index cac6114904..027fc9c25c 100644 --- a/tests/expressions_window/tests.py +++ b/tests/expressions_window/tests.py @@ -42,6 +42,7 @@ from django.db.models.functions import ( ) from django.db.models.lookups import Exact from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature +from django.test.utils import CaptureQueriesContext from .models import Classification, Detail, Employee, PastEmployeeDepartment @@ -1157,16 +1158,21 @@ class WindowFunctionTests(TestCase): ) def test_filter_count(self): - self.assertEqual( - Employee.objects.annotate( - department_salary_rank=Window( - Rank(), partition_by="department", order_by="-salary" + with CaptureQueriesContext(connection) as ctx: + self.assertEqual( + Employee.objects.annotate( + department_salary_rank=Window( + Rank(), partition_by="department", order_by="-salary" + ) ) + .filter(department_salary_rank=1) + .count(), + 5, ) - .filter(department_salary_rank=1) - .count(), - 5, - ) + self.assertEqual(len(ctx.captured_queries), 1) + sql = ctx.captured_queries[0]["sql"].lower() + self.assertEqual(sql.count("select"), 3) + self.assertNotIn("group by", sql) @skipUnlessDBFeature("supports_frame_range_fixed_distance") def test_range_n_preceding_and_following(self): |