Refs #11964 -- Changed CheckConstraint() signature to use keyword-only arguments.

Also renamed the `constraint` argument to `check` to better represent which
part of the constraint the provided `Q` object represents.
This commit is contained in:
Simon Charette 2018-08-05 22:15:10 -04:00 committed by Tim Graham
parent 0bf7b25f8f
commit 9142bebff2
9 changed files with 34 additions and 34 deletions

View file

@ -9,7 +9,7 @@ class Product(models.Model):
class Meta:
constraints = [
models.CheckConstraint(
models.Q(price__gt=models.F('discounted_price')),
'price_gt_discounted_price'
)
check=models.Q(price__gt=models.F('discounted_price')),
name='price_gt_discounted_price',
),
]

View file

@ -6,22 +6,22 @@ from .models import Product
class CheckConstraintTests(TestCase):
def test_repr(self):
constraint = models.Q(price__gt=models.F('discounted_price'))
check = models.Q(price__gt=models.F('discounted_price'))
name = 'price_gt_discounted_price'
check = models.CheckConstraint(constraint, name)
constraint = models.CheckConstraint(check=check, name=name)
self.assertEqual(
repr(check),
"<CheckConstraint: constraint='{}' name='{}'>".format(constraint, name),
repr(constraint),
"<CheckConstraint: check='{}' name='{}'>".format(check, name),
)
def test_deconstruction(self):
constraint = models.Q(price__gt=models.F('discounted_price'))
check = models.Q(price__gt=models.F('discounted_price'))
name = 'price_gt_discounted_price'
check = models.CheckConstraint(constraint, name)
path, args, kwargs = check.deconstruct()
constraint = models.CheckConstraint(check=check, name=name)
path, args, kwargs = constraint.deconstruct()
self.assertEqual(path, 'django.db.models.CheckConstraint')
self.assertEqual(args, ())
self.assertEqual(kwargs, {'constraint': constraint, 'name': name})
self.assertEqual(kwargs, {'check': check, 'name': name})
@skipUnlessDBFeature('supports_table_check_constraints')
def test_database_constraint(self):