diff options
| author | Tim Graham <timograham@gmail.com> | 2019-02-05 09:19:49 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2019-02-06 14:12:06 -0500 |
| commit | d55e88292723764a16f0689c73bc7e739dfa6047 (patch) | |
| tree | b089db0867f0439b7998cf03c7cd0de28f4362f9 /tests | |
| parent | 3bb6a4390c0a57da991fcb1c0642b9b3fccff751 (diff) | |
Refs #27753 -- Deprecated django.utils.encoding.force_text() and smart_text().
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/utils_tests/test_encoding_deprecations.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/utils_tests/test_encoding_deprecations.py b/tests/utils_tests/test_encoding_deprecations.py new file mode 100644 index 0000000000..c775ce5f66 --- /dev/null +++ b/tests/utils_tests/test_encoding_deprecations.py @@ -0,0 +1,24 @@ +from django.test import SimpleTestCase, ignore_warnings +from django.utils.deprecation import RemovedInDjango40Warning +from django.utils.encoding import force_text, smart_text +from django.utils.functional import SimpleLazyObject +from django.utils.translation import gettext_lazy + + +@ignore_warnings(category=RemovedInDjango40Warning) +class TestDeprecatedEncodingUtils(SimpleTestCase): + + def test_force_text(self): + s = SimpleLazyObject(lambda: 'x') + self.assertIs(type(force_text(s)), str) + + def test_smart_text(self): + class Test: + def __str__(self): + return 'ŠĐĆŽćžšđ' + + lazy_func = gettext_lazy('x') + self.assertIs(smart_text(lazy_func), lazy_func) + self.assertEqual(smart_text(Test()), '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111') + self.assertEqual(smart_text(1), '1') + self.assertEqual(smart_text('foo'), 'foo') |
