mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Added changes of **extra keyword.
This commit is contained in:
parent
40161746c0
commit
6ae26ddde1
@ -856,21 +856,19 @@ class BasicExpressionsTests(TestCase):
|
|||||||
self.assertEqual(qs.get(), self.gmbh)
|
self.assertEqual(qs.get(), self.gmbh)
|
||||||
|
|
||||||
def test_subquery_with_custom_template(self):
|
def test_subquery_with_custom_template(self):
|
||||||
companies = Company.objects.annotate(
|
custom_subquery = Company.objects.filter(
|
||||||
ceo_manager_count=Subquery(
|
ceo__salary__in=Subquery(
|
||||||
Employee.objects.filter(
|
Employee.objects.all().values("salary"),
|
||||||
lastname=OuterRef("ceo__lastname"),
|
salary=20,
|
||||||
).values("manager"),
|
template="(SELECT salary FROM (%(subquery)s) _subquery "
|
||||||
template="(SELECT count(*) FROM (%(subquery)s) _count)",
|
"WHERE salary = %(salary)s)",
|
||||||
|
),
|
||||||
)
|
)
|
||||||
)
|
expected_companies = Company.objects.filter(name="Foobar Ltd.")
|
||||||
expected_results = [
|
self.assertQuerySetEqual(
|
||||||
{"name": "Example Inc.", "ceo_manager_count": 1},
|
custom_subquery.order_by("name"),
|
||||||
{"name": "Foobar Ltd.", "ceo_manager_count": 1},
|
expected_companies.order_by("name"),
|
||||||
{"name": "Test GmbH", "ceo_manager_count": 1},
|
transform=lambda x: x,
|
||||||
]
|
|
||||||
self.assertListEqual(
|
|
||||||
list(companies.values("name", "ceo_manager_count")), expected_results
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_aggregate_subquery_annotation(self):
|
def test_aggregate_subquery_annotation(self):
|
||||||
|
@ -726,16 +726,13 @@ class CaseExpressionTests(TestCase):
|
|||||||
case_expression = Case(
|
case_expression = Case(
|
||||||
When(integer=1, then=Value(10)),
|
When(integer=1, then=Value(10)),
|
||||||
When(integer=2, then=Value(20)),
|
When(integer=2, then=Value(20)),
|
||||||
default=Value(0),
|
custom_default=5,
|
||||||
template="CASE %(cases)s ELSE %(default)s + 5 END",
|
template="CASE %(cases)s ELSE %(custom_default)s END",
|
||||||
)
|
)
|
||||||
self.assertListEqual(
|
self.assertQuerySetEqual(
|
||||||
list(
|
CaseTestModel.objects.annotate(values=case_expression).order_by("pk"),
|
||||||
CaseTestModel.objects.annotate(values=case_expression).values_list(
|
|
||||||
"values", flat=True
|
|
||||||
)
|
|
||||||
),
|
|
||||||
[10, 20, 5, 20, 5, 5, 5],
|
[10, 20, 5, 20, 5, 5, 5],
|
||||||
|
transform=attrgetter("values"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user