summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2017-07-17 21:12:27 +0200
committerGitHub <noreply@github.com>2017-07-17 21:12:27 +0200
commit776cee974933677730aef177eb5b5bdec3749c80 (patch)
treee6435cf6aeabe6b436a87ab8fb1ef702608e8a74 /tests
parentfeeafdad02e2874e2e2f879a825d3527f6b193ad (diff)
Fixed #28391 -- Fixed Cast() with CharField and max_length on MySQL.
Thanks Tim Graham for the review.
Diffstat (limited to 'tests')
-rw-r--r--tests/db_functions/test_cast.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/tests/db_functions/test_cast.py b/tests/db_functions/test_cast.py
index 70de20e5eb..bd4541bf06 100644
--- a/tests/db_functions/test_cast.py
+++ b/tests/db_functions/test_cast.py
@@ -1,7 +1,7 @@
from django.db import models
from django.db.models.expressions import Value
from django.db.models.functions import Cast
-from django.test import TestCase
+from django.test import TestCase, ignore_warnings, skipUnlessDBFeature
from .models import Author
@@ -19,6 +19,13 @@ class CastTests(TestCase):
numbers = Author.objects.annotate(cast_string=Cast('age', models.CharField(max_length=255)),)
self.assertEqual(numbers.get().cast_string, '1')
+ # Silence "Truncated incorrect CHAR(1) value: 'Bob'".
+ @ignore_warnings(module='django.db.backends.mysql.base')
+ @skipUnlessDBFeature('supports_cast_with_precision')
+ def test_cast_to_char_field_with_max_length(self):
+ names = Author.objects.annotate(cast_string=Cast('name', models.CharField(max_length=1)))
+ self.assertEqual(names.get().cast_string, 'B')
+
def test_cast_to_integer(self):
for field_class in (
models.IntegerField,