Refs #31197 -- Added tests for combined expressions in CheckConstraint.check.

Thanks Adam Johnson for the report.

Fixed in 306b687520.
This commit is contained in:
Mariusz Felisiak 2020-01-23 10:28:36 +01:00 committed by GitHub
parent 971a84d6af
commit b423873cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 0 deletions

View File

@ -1816,6 +1816,34 @@ class OperationTests(OperationTestBase):
Pony(pink=3, weight=3.0),
])
@skipUnlessDBFeature('supports_table_check_constraints')
def test_add_constraint_combinable(self):
app_label = 'test_addconstraint_combinable'
operations = [
CreateModel(
'Book',
fields=[
('id', models.AutoField(primary_key=True)),
('read', models.PositiveIntegerField()),
('unread', models.PositiveIntegerField()),
],
),
]
from_state = self.apply_operations(app_label, ProjectState(), operations)
constraint = models.CheckConstraint(
check=models.Q(read=(100 - models.F('unread'))),
name='test_addconstraint_combinable_sum_100',
)
operation = migrations.AddConstraint('Book', constraint)
to_state = from_state.clone()
operation.state_forwards(app_label, to_state)
with connection.schema_editor() as editor:
operation.database_forwards(app_label, editor, from_state, to_state)
Book = to_state.apps.get_model(app_label, 'Book')
with self.assertRaises(IntegrityError), transaction.atomic():
Book.objects.create(read=70, unread=10)
Book.objects.create(read=70, unread=30)
@skipUnlessDBFeature('supports_table_check_constraints')
def test_remove_constraint(self):
project_state = self.set_up_test_model("test_removeconstraint", constraints=[