Ticket #28391: 28391.diff

File 28391.diff, 928 bytes (added by Mariusz Felisiak, 7 years ago)
  • tests/db_functions/test_cast.py

    diff --git a/tests/db_functions/test_cast.py b/tests/db_functions/test_cast.py
    index 70de20e5eb..1e0e89521a 100644
    a b  
     1from unittest import mock
     2
    13from django.db import models
    24from django.db.models.expressions import Value
    35from django.db.models.functions import Cast
    class CastTests(TestCase):  
    1921        numbers = Author.objects.annotate(cast_string=Cast('age', models.CharField(max_length=255)),)
    2022        self.assertEqual(numbers.get().cast_string, '1')
    2123
     24    @mock.patch('sys.stderr')
     25    def test_cast_to_char_field_with_max_length(self, mocked_stdout):
     26        names = Author.objects.annotate(cast_string=Cast('name', models.CharField(max_length=1)))
     27        self.assertEqual(names.get().cast_string, 'B')
     28
    2229    def test_cast_to_integer(self):
    2330        for field_class in (
    2431            models.IntegerField,
Back to Top