1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #24836 -- Made force_text() resolve lazy objects.

This commit is contained in:
Tim Graham
2015-05-26 16:46:13 -04:00
parent 10945ebeb8
commit 70be31bba7
4 changed files with 25 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ from django.utils.encoding import (
escape_uri_path, filepath_to_uri, force_bytes, force_text, iri_to_uri,
smart_text, uri_to_iri,
)
from django.utils.functional import SimpleLazyObject
from django.utils.http import urlquote_plus
@@ -28,6 +29,10 @@ class TestEncodingUtils(unittest.TestCase):
exception = TypeError if six.PY3 else UnicodeError
self.assertRaises(exception, force_text, MyString())
def test_force_text_lazy(self):
s = SimpleLazyObject(lambda: 'x')
self.assertTrue(issubclass(type(force_text(s)), six.text_type))
def test_force_bytes_exception(self):
"""
Test that force_bytes knows how to convert to bytes an exception