Refs #29641 -- Extracted reusable CheckConstraint logic into a base class.

This commit is contained in:
Simon Charette 2018-08-05 22:12:27 -04:00 committed by Tim Graham
parent 9142bebff2
commit 24dc7d8940
2 changed files with 43 additions and 21 deletions

View file

@ -1,9 +1,18 @@
from django.db import IntegrityError, models
from django.test import TestCase, skipUnlessDBFeature
from django.db.models.constraints import BaseConstraint
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
from .models import Product
class BaseConstraintTests(SimpleTestCase):
def test_constraint_sql(self):
c = BaseConstraint('name')
msg = 'This method must be implemented by a subclass.'
with self.assertRaisesMessage(NotImplementedError, msg):
c.constraint_sql(None, None)
class CheckConstraintTests(TestCase):
def test_repr(self):
check = models.Q(price__gt=models.F('discounted_price'))