summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/aggregation/tests.py15
-rw-r--r--tests/backends/postgresql/tests.py19
2 files changed, 34 insertions, 0 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py
index 54e1e6f13a..c1ae9f0dd5 100644
--- a/tests/aggregation/tests.py
+++ b/tests/aggregation/tests.py
@@ -34,6 +34,7 @@ from django.db.models.functions import (
Cast,
Coalesce,
Greatest,
+ Least,
Lower,
Now,
Pi,
@@ -1614,6 +1615,20 @@ class AggregateTestCase(TestCase):
).annotate(total=Count("*"))
self.assertEqual(dict(has_long_books_breakdown), {True: 2, False: 3})
+ def test_group_by_nested_expression_with_params(self):
+ books_qs = (
+ Book.objects.annotate(greatest_pages=Greatest("pages", Value(600)))
+ .values(
+ "greatest_pages",
+ )
+ .annotate(
+ min_pages=Min("pages"),
+ least=Least("min_pages", "greatest_pages"),
+ )
+ .values_list("least", flat=True)
+ )
+ self.assertCountEqual(books_qs, [300, 946, 1132])
+
@skipUnlessDBFeature("supports_subqueries_in_group_by")
def test_aggregation_subquery_annotation_related_field(self):
publisher = Publisher.objects.create(name=self.a9.name, num_awards=2)
diff --git a/tests/backends/postgresql/tests.py b/tests/backends/postgresql/tests.py
index 7b0e0bfb52..ab66e7ab0e 100644
--- a/tests/backends/postgresql/tests.py
+++ b/tests/backends/postgresql/tests.py
@@ -277,6 +277,25 @@ class Tests(TestCase):
finally:
new_connection.close()
+ @unittest.skipUnless(is_psycopg3, "psycopg3 specific test")
+ def test_connect_server_side_binding(self):
+ """
+ The server-side parameters binding role can be enabled with DATABASES
+ ["OPTIONS"]["server_side_binding"].
+ """
+ from django.db.backends.postgresql.base import ServerBindingCursor
+
+ new_connection = connection.copy()
+ new_connection.settings_dict["OPTIONS"]["server_side_binding"] = True
+ try:
+ new_connection.connect()
+ self.assertEqual(
+ new_connection.connection.cursor_factory,
+ ServerBindingCursor,
+ )
+ finally:
+ new_connection.close()
+
def test_connect_no_is_usable_checks(self):
new_connection = connection.copy()
try: