summaryrefslogtreecommitdiff
path: root/tests/utils_tests/test_functional.py
diff options
context:
space:
mode:
authorMarten Kenbeek <marten.knbk@gmail.com>2015-06-20 14:00:55 +0200
committerTim Graham <timograham@gmail.com>2015-06-23 09:16:17 -0400
commit290ff35e6cc2580861a6fdeaaa3d4aa6d75f9edd (patch)
tree781306423c6d378321f416be5d7f667a2b2010a5 /tests/utils_tests/test_functional.py
parentc45fbd060a3173edd868fc011614f01bc61b78b6 (diff)
Fixed #25000 -- Fixed cast to string for lazy objects.
Implemented __str__() to return the string-representation of the proxied object, not the proxy itself, if the lazy object didn't have a string-like object in its resultclasses.
Diffstat (limited to 'tests/utils_tests/test_functional.py')
-rw-r--r--tests/utils_tests/test_functional.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/utils_tests/test_functional.py b/tests/utils_tests/test_functional.py
index 5f7687edf5..135e8da0ed 100644
--- a/tests/utils_tests/test_functional.py
+++ b/tests/utils_tests/test_functional.py
@@ -1,5 +1,9 @@
+# -*- encoding: utf-8 -*-
+from __future__ import unicode_literals
+
import unittest
+from django.utils import six
from django.utils.functional import cached_property, lazy, lazy_property
@@ -54,6 +58,26 @@ class FunctionalTestCase(unittest.TestCase):
self.assertRaises(NotImplementedError, lambda: A().do)
self.assertEqual(B().do, 'DO IT')
+ def test_lazy_object_to_string(self):
+
+ class Klazz(object):
+ if six.PY3:
+ def __str__(self):
+ return "Î am ā Ǩlâzz."
+
+ def __bytes__(self):
+ return b"\xc3\x8e am \xc4\x81 binary \xc7\xa8l\xc3\xa2zz."
+ else:
+ def __unicode__(self):
+ return "Î am ā Ǩlâzz."
+
+ def __str__(self):
+ return b"\xc3\x8e am \xc4\x81 binary \xc7\xa8l\xc3\xa2zz."
+
+ t = lazy(lambda: Klazz(), Klazz)()
+ self.assertEqual(six.text_type(t), "Î am ā Ǩlâzz.")
+ self.assertEqual(six.binary_type(t), b"\xc3\x8e am \xc4\x81 binary \xc7\xa8l\xc3\xa2zz.")
+
def test_cached_property(self):
"""
Test that cached_property caches its value,