From bc7e288ca9554ac1a0a19941302dea19df1acd21 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Tue, 2 Oct 2018 19:15:20 -0400 Subject: Fixed #29745 -- Based Expression equality on detailed initialization signature. The old implementation considered objects initialized with an equivalent signature different if some arguments were provided positionally instead of as keyword arguments. Refs #11964, #26167. --- tests/expressions/tests.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index c631151448..d3f86fcd92 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -11,8 +11,9 @@ from django.db.models.aggregates import ( Avg, Count, Max, Min, StdDev, Sum, Variance, ) from django.db.models.expressions import ( - Case, Col, Combinable, Exists, ExpressionList, ExpressionWrapper, F, Func, - OrderBy, OuterRef, Random, RawSQL, Ref, Subquery, Value, When, + Case, Col, Combinable, Exists, Expression, ExpressionList, + ExpressionWrapper, F, Func, OrderBy, OuterRef, Random, RawSQL, Ref, + Subquery, Value, When, ) from django.db.models.functions import ( Coalesce, Concat, Length, Lower, Substr, Upper, @@ -822,6 +823,31 @@ class ExpressionsTests(TestCase): ) +class SimpleExpressionTests(SimpleTestCase): + + def test_equal(self): + self.assertEqual(Expression(), Expression()) + self.assertEqual( + Expression(models.IntegerField()), + Expression(output_field=models.IntegerField()) + ) + self.assertNotEqual( + Expression(models.IntegerField()), + Expression(models.CharField()) + ) + + def test_hash(self): + self.assertEqual(hash(Expression()), hash(Expression())) + self.assertEqual( + hash(Expression(models.IntegerField())), + hash(Expression(output_field=models.IntegerField())) + ) + self.assertNotEqual( + hash(Expression(models.IntegerField())), + hash(Expression(models.CharField())), + ) + + class ExpressionsNumericTests(TestCase): def setUp(self): -- cgit v1.3