def test_it_renders_via_the_given_encoding(self): renderer = renderers.Unicode(encoding="utf-8") render = renderers.bind(renderer, to=lambda _: u"שלום") self.assertEqual( render(self.request), Response(u"שלום".encode("utf-8")), )
def test_encoding_errors_by_default(self): renderer = renderers.Unicode(encoding="ascii") render = renderers.bind(renderer, to=lambda _: u"שלום") with self.assertRaises(UnicodeEncodeError): render(self.request)
def test_encoding_ignoring_errors(self): renderer = renderers.Unicode(encoding="ascii", errors="ignore") render = renderers.bind(renderer, to=lambda _: u"שלום") self.assertEqual(render(self.request), Response(b""))