summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2020-01-23 10:28:36 +0100
committerGitHub <noreply@github.com>2020-01-23 10:28:36 +0100
commitb423873cb7574a8088e32d3e23f4d01a99fefeb2 (patch)
tree6dddb981ce8a774a04270d93c8ad8eef9c31263a
parent971a84d6af9de738be2a7a8344fa8c80671d1729 (diff)
Refs #31197 -- Added tests for combined expressions in CheckConstraint.check.
Thanks Adam Johnson for the report. Fixed in 306b6875209cfedce2536a6679e69adee7c9bc6a.
-rw-r--r--tests/migrations/test_operations.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index 2a57b43ec4..02971d7a9f 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -1817,6 +1817,34 @@ class OperationTests(OperationTestBase):
])
@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=[
models.CheckConstraint(check=models.Q(pink__gt=2), name="test_remove_constraint_pony_pink_gt_2"),