0
0
mirror of https://github.com/django/django.git synced 2024-12-01 15:42:04 +01:00

Added tests for Check/UniqueConstraint.__eq__().

This commit is contained in:
Paveł Tyślacki 2019-01-12 01:42:47 +03:00 committed by Tim Graham
parent e192223ed9
commit f4c0c0b0aa

View File

@ -32,6 +32,23 @@ class BaseConstraintTests(SimpleTestCase):
class CheckConstraintTests(TestCase):
def test_eq(self):
check1 = models.Q(price__gt=models.F('discounted_price'))
check2 = models.Q(price__lt=models.F('discounted_price'))
self.assertEqual(
models.CheckConstraint(check=check1, name='price'),
models.CheckConstraint(check=check1, name='price'),
)
self.assertNotEqual(
models.CheckConstraint(check=check1, name='price'),
models.CheckConstraint(check=check1, name='price2'),
)
self.assertNotEqual(
models.CheckConstraint(check=check1, name='price'),
models.CheckConstraint(check=check2, name='price'),
)
self.assertNotEqual(models.CheckConstraint(check=check1, name='price'), 1)
def test_repr(self):
check = models.Q(price__gt=models.F('discounted_price'))
name = 'price_gt_discounted_price'
@ -68,6 +85,21 @@ class UniqueConstraintTests(TestCase):
def setUpTestData(cls):
cls.p1 = Product.objects.create(name='p1')
def test_eq(self):
self.assertEqual(
models.UniqueConstraint(fields=['foo', 'bar'], name='unique'),
models.UniqueConstraint(fields=['foo', 'bar'], name='unique'),
)
self.assertNotEqual(
models.UniqueConstraint(fields=['foo', 'bar'], name='unique'),
models.UniqueConstraint(fields=['foo', 'bar'], name='unique2'),
)
self.assertNotEqual(
models.UniqueConstraint(fields=['foo', 'bar'], name='unique'),
models.UniqueConstraint(fields=['foo', 'baz'], name='unique'),
)
self.assertNotEqual(models.UniqueConstraint(fields=['foo', 'bar'], name='unique'), 1)
def test_repr(self):
fields = ['foo', 'bar']
name = 'unique_fields'