0
0
mirror of https://github.com/django/django.git synced 2024-11-30 23:20:50 +01:00

Added a test for force_text()'s DjangoUnicodeDecodeError path.

This commit is contained in:
Tim Graham 2017-02-01 15:48:53 -05:00
parent 8e3f9d3ee2
commit 2f1394c76d

View File

@ -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