diff options
| author | David Smith <smithdc@gmail.com> | 2023-08-18 14:16:57 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-08-31 06:18:07 +0200 |
| commit | 27b399d23531541d091886f683991e321c8fa314 (patch) | |
| tree | 468439e4efdd26e6d78609b61ed872ceabfb1380 /tests | |
| parent | 500e01073adda32d5149624ee9a5cb7aa3d3583f (diff) | |
Fixed #34547 -- Deprecated DatabaseOperations.field_cast_sql().
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/backends/base/test_operations.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/backends/base/test_operations.py b/tests/backends/base/test_operations.py index 9d2828c8ce..d2a3fb6765 100644 --- a/tests/backends/base/test_operations.py +++ b/tests/backends/base/test_operations.py @@ -1,10 +1,12 @@ import decimal +from unittest import mock from django.core.management.color import no_style from django.db import NotSupportedError, connection, transaction from django.db.backends.base.operations import BaseDatabaseOperations from django.db.models import DurationField, Value from django.db.models.expressions import Col +from django.db.models.lookups import Exact from django.test import ( SimpleTestCase, TestCase, @@ -13,6 +15,7 @@ from django.test import ( skipIfDBFeature, ) from django.utils import timezone +from django.utils.deprecation import RemovedInDjango60Warning from ..models import Author, Book @@ -235,3 +238,24 @@ class SqlFlushTests(TransactionTestCase): self.assertEqual(author.pk, 1) book = Book.objects.create(author=author) self.assertEqual(book.pk, 1) + + +class DeprecationTests(TestCase): + def test_field_cast_sql_warning(self): + base_ops = BaseDatabaseOperations(connection=connection) + msg = ( + "DatabaseOperations.field_cast_sql() is deprecated use " + "DatabaseOperations.lookup_cast() instead." + ) + with self.assertRaisesMessage(RemovedInDjango60Warning, msg): + base_ops.field_cast_sql("integer", "IntegerField") + + def test_field_cast_sql_usage_warning(self): + compiler = Author.objects.all().query.get_compiler(connection.alias) + msg = ( + "The usage of DatabaseOperations.field_cast_sql() is deprecated. Implement " + "DatabaseOperations.lookup_cast() instead." + ) + with mock.patch.object(connection.ops.__class__, "field_cast_sql"): + with self.assertRaisesMessage(RemovedInDjango60Warning, msg): + Exact("name", "book__author__name").as_sql(compiler, connection) |
