diff options
| author | Tim Graham <timograham@gmail.com> | 2017-02-01 15:48:53 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-02-03 19:15:50 -0500 |
| commit | 2f1394c76dd586ceab3f86f5b6cb4473382c9af8 (patch) | |
| tree | a798e0aed0958be35d33eb0383cdfabe08d8ceeb /tests/utils_tests/test_encoding.py | |
| parent | 8e3f9d3ee20fdadef6f2a28c71fb7e142b415059 (diff) | |
Added a test for force_text()'s DjangoUnicodeDecodeError path.
Diffstat (limited to 'tests/utils_tests/test_encoding.py')
| -rw-r--r-- | tests/utils_tests/test_encoding.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/tests/utils_tests/test_encoding.py b/tests/utils_tests/test_encoding.py index bd937bf960..b7ffd0afe7 100644 --- a/tests/utils_tests/test_encoding.py +++ b/tests/utils_tests/test_encoding.py @@ -2,14 +2,15 @@ import datetime import unittest from urllib.parse import quote_plus +from django.test import SimpleTestCase from django.utils.encoding import ( - escape_uri_path, filepath_to_uri, force_bytes, force_text, iri_to_uri, - smart_text, uri_to_iri, + DjangoUnicodeDecodeError, escape_uri_path, filepath_to_uri, force_bytes, + force_text, iri_to_uri, smart_text, uri_to_iri, ) from django.utils.functional import SimpleLazyObject -class TestEncodingUtils(unittest.TestCase): +class TestEncodingUtils(SimpleTestCase): def test_force_text_exception(self): """ Broken __str__ actually raises an error. @@ -26,6 +27,14 @@ class TestEncodingUtils(unittest.TestCase): s = SimpleLazyObject(lambda: 'x') self.assertTrue(type(force_text(s)), str) + def test_force_text_DjangoUnicodeDecodeError(self): + msg = ( + "'utf-8' codec can't decode byte 0xff in position 0: invalid " + "start byte. You passed in b'\\xff' (<class 'bytes'>)" + ) + with self.assertRaisesMessage(DjangoUnicodeDecodeError, msg): + force_text(b'\xff') + def test_force_bytes_exception(self): """ force_bytes knows how to convert to bytes an exception |
