From 54ea290e5bbd19d87bd8dba807738eeeaf01a362 Mon Sep 17 00:00:00 2001 From: ElizabethU Date: Mon, 2 Sep 2019 19:09:31 -0700 Subject: Fixed #30651 -- Made __eq__() methods return NotImplemented for not implemented comparisons. Changed __eq__ to return NotImplemented instead of False if compared to an object of the same type, as is recommended by the Python data model reference. Now these models can be compared to ANY (or other objects with __eq__ overwritten) without returning False automatically. --- tests/constraints/tests.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/constraints') diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py index 3b28c99e7f..8e2eb11e2a 100644 --- a/tests/constraints/tests.py +++ b/tests/constraints/tests.py @@ -1,3 +1,5 @@ +from unittest import mock + from django.core.exceptions import ValidationError from django.db import IntegrityError, connection, models from django.db.models.constraints import BaseConstraint @@ -39,6 +41,7 @@ class CheckConstraintTests(TestCase): models.CheckConstraint(check=check1, name='price'), models.CheckConstraint(check=check1, name='price'), ) + self.assertEqual(models.CheckConstraint(check=check1, name='price'), mock.ANY) self.assertNotEqual( models.CheckConstraint(check=check1, name='price'), models.CheckConstraint(check=check1, name='price2'), @@ -102,6 +105,10 @@ class UniqueConstraintTests(TestCase): models.UniqueConstraint(fields=['foo', 'bar'], name='unique'), models.UniqueConstraint(fields=['foo', 'bar'], name='unique'), ) + self.assertEqual( + models.UniqueConstraint(fields=['foo', 'bar'], name='unique'), + mock.ANY, + ) self.assertNotEqual( models.UniqueConstraint(fields=['foo', 'bar'], name='unique'), models.UniqueConstraint(fields=['foo', 'bar'], name='unique2'), -- cgit v1.3