diff options
| author | can <cansarigol@derinbilgi.com.tr> | 2019-04-30 11:20:41 +0300 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-04-30 13:43:02 +0200 |
| commit | 58391b4d164ac83b8001a2ec70f3b1e4d39e4681 (patch) | |
| tree | 21f48cddd339198f73735d167729e46edc18e0e4 /tests | |
| parent | 54fcdf168ab1f53fbdb7cd63f916bd44845a78d3 (diff) | |
[2.2.x] Fixed #30412 -- Fixed crash when adding check constraints with OR'ed condition on Oracle and SQLite.
Backport of 719b7466203181066d9537d2e3bec687dffc9f41 from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_operations.py | 23 | ||||
| -rw-r--r-- | tests/queries/test_query.py | 15 |
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index 520a2b2204..3b2129a933 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -1899,6 +1899,29 @@ class OperationTests(OperationTestBase): self.assertEqual(Author.objects.get(), author) @skipUnlessDBFeature('supports_table_check_constraints') + def test_add_or_constraint(self): + app_label = 'test_addorconstraint' + constraint_name = 'add_constraint_or' + from_state = self.set_up_test_model(app_label) + check = models.Q(pink__gt=2, weight__gt=2) | models.Q(weight__lt=0) + constraint = models.CheckConstraint(check=check, name=constraint_name) + operation = migrations.AddConstraint('Pony', 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) + Pony = to_state.apps.get_model(app_label, 'Pony') + with self.assertRaises(IntegrityError), transaction.atomic(): + Pony.objects.create(pink=2, weight=3.0) + with self.assertRaises(IntegrityError), transaction.atomic(): + Pony.objects.create(pink=3, weight=1.0) + Pony.objects.bulk_create([ + Pony(pink=3, weight=-1.0), + Pony(pink=1, weight=-1.0), + Pony(pink=3, weight=3.0), + ]) + + @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"), diff --git a/tests/queries/test_query.py b/tests/queries/test_query.py index bef79c992e..c6a659fe97 100644 --- a/tests/queries/test_query.py +++ b/tests/queries/test_query.py @@ -23,6 +23,21 @@ class TestQuery(SimpleTestCase): self.assertEqual(lookup.rhs, 2) self.assertEqual(lookup.lhs.target, Author._meta.get_field('num')) + def test_simplecol_query(self): + query = Query(Author) + where = query.build_where(Q(num__gt=2, name__isnull=False) | Q(num__lt=F('id'))) + + name_isnull_lookup, num_gt_lookup = where.children[0].children + self.assertIsInstance(num_gt_lookup, GreaterThan) + self.assertIsInstance(num_gt_lookup.lhs, SimpleCol) + self.assertIsInstance(name_isnull_lookup, IsNull) + self.assertIsInstance(name_isnull_lookup.lhs, SimpleCol) + + num_lt_lookup = where.children[1] + self.assertIsInstance(num_lt_lookup, LessThan) + self.assertIsInstance(num_lt_lookup.rhs, SimpleCol) + self.assertIsInstance(num_lt_lookup.lhs, SimpleCol) + def test_complex_query(self): query = Query(Author) where = query.build_where(Q(num__gt=2) | Q(num__lt=0)) |
