summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2020-08-30 22:18:55 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-08-31 06:40:39 +0200
commit40894f29675b02be9597c3af358ed490d2b96651 (patch)
tree4eddc49440b1d2a545f1fbadd9ac02ca3c5cffcc
parent0be51d2226fce030ac9ca840535a524f41e9832c (diff)
Refs #30446 -- Added tests for resolving output_field of CombinedExpression.
-rw-r--r--tests/expressions/tests.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
index c15204ce33..42b6b828f4 100644
--- a/tests/expressions/tests.py
+++ b/tests/expressions/tests.py
@@ -15,7 +15,9 @@ from django.db.models import (
Min, Model, OrderBy, OuterRef, Q, StdDev, Subquery, Sum, TimeField,
UUIDField, Value, Variance, When,
)
-from django.db.models.expressions import Col, Combinable, Random, RawSQL, Ref
+from django.db.models.expressions import (
+ Col, Combinable, CombinedExpression, Random, RawSQL, Ref,
+)
from django.db.models.functions import (
Coalesce, Concat, Left, Length, Lower, Substr, Upper,
)
@@ -1888,6 +1890,26 @@ class CombinableTests(SimpleTestCase):
object() | Combinable()
+class CombinedExpressionTests(SimpleTestCase):
+ def test_resolve_output_field(self):
+ tests = [
+ (IntegerField, DecimalField, DecimalField),
+ (DecimalField, IntegerField, DecimalField),
+ (IntegerField, FloatField, FloatField),
+ (FloatField, IntegerField, FloatField),
+ ]
+ connectors = [Combinable.ADD, Combinable.SUB, Combinable.MUL, Combinable.DIV]
+ for lhs, rhs, combined in tests:
+ for connector in connectors:
+ with self.subTest(lhs=lhs, connector=connector, rhs=rhs, combined=combined):
+ expr = CombinedExpression(
+ Expression(lhs()),
+ connector,
+ Expression(rhs()),
+ )
+ self.assertIsInstance(expr.output_field, combined)
+
+
class ExpressionWrapperTests(SimpleTestCase):
def test_empty_group_by(self):
expr = ExpressionWrapper(Value(3), output_field=IntegerField())