def test_set_charset_fails_when_json(): content_type = 'application/json' expected = content_type res = Response(content_type=content_type) res.charset = 'utf-8' assert res.headers['content-type'] == expected res.content_type_params = {'charset': 'utf-8'} assert res.headers['content-type'] == expected
def test_unicode_body(): res = Response() res.charset = 'utf-8' bbody = b'La Pe\xc3\xb1a' # binary string ubody = text_(bbody, 'utf-8') # unicode string res.body = bbody eq_(res.unicode_body, ubody) res.ubody = ubody eq_(res.body, bbody) del res.ubody eq_(res.body, b'')
def test_unicode_body(): res = Response() res.charset = "utf-8" bbody = b"La Pe\xc3\xb1a" # binary string ubody = text_(bbody, "utf-8") # unicode string res.body = bbody assert res.unicode_body == ubody res.ubody = ubody assert res.body == bbody del res.ubody assert res.body == b""
def test_unicode_body(): res = Response() res.charset = "utf-8" bbody = b"La Pe\xc3\xb1a" # binary string ubody = text_(bbody, "utf-8") # unicode string res.body = bbody assert res.unicode_body == ubody res.ubody = ubody assert res.body == bbody del res.ubody assert res.body == b""
def test_unicode_body(): res = Response() res.charset = "utf-8" bbody = b"La Pe\xc3\xb1a" # binary string ubody = text_(bbody, "utf-8") # unicode string res.body = bbody eq_(res.unicode_body, ubody) res.ubody = ubody eq_(res.body, bbody) del res.ubody eq_(res.body, b"")
def test_unicode_body(): res = Response() res.charset = 'utf-8' bbody = b'La Pe\xc3\xb1a' # binary string ubody = text_(bbody, 'utf-8') # unicode string res.body = bbody assert res.unicode_body == ubody res.ubody = ubody assert res.body == bbody del res.ubody assert res.body == b''
def test_unicode_body(): res = Response() res.charset = 'utf-8' bbody = b'La Pe\xc3\xb1a' # binary string ubody = text_(bbody, 'utf-8') # unicode string res.body = bbody eq_(res.unicode_body, ubody) res.ubody = ubody eq_(res.body, bbody) del res.ubody eq_(res.body, b'')
def test_response_ok(self): '''Test case that ensures response object behaves as expected. If this pass it guarantees webob version does not break fantastico functionality.''' response = Response() self.assertEqual(200, response.status_code) self.assertEqual("text/html", response.content_type) response.charset = "utf8" self.assertEqual("utf8", response.charset) response.text = "test content" self.assertEqual(b"test content", response.body) response.body = b"test content" self.assertEqual(b"test content", response.body) response.status = 404 self.assertEqual(404, response.status_code) response.content_type = "application/json" self.assertEqual("application/json", response.content_type)
def test_response_ok(self): '''Test case that ensures response object behaves as expected. If this pass it guarantees webob version does not break fantastico functionality.''' response = Response() self.assertEqual(200, response.status_code) self.assertEqual("text/html", response.content_type) response.charset = "utf8" self.assertEqual("utf8", response.charset) response.text = "test content" self.assertEqual(b"test content", response.body) response.body = b"test content" self.assertEqual(b"test content", response.body) response.status = 404 self.assertEqual(404, response.status_code) response.content_type = "application/json" self.assertEqual("application/json", response.content_type)
def test_charset_set_no_content_type_header(): res = Response() res.headers.pop("Content-Type", None) with pytest.raises(AttributeError): res.charset = "utf-8"
def test_text_set_not_unicode(): res = Response() res.charset = "utf-8" with pytest.raises(TypeError): res.__setattr__("text", b"La Pe\xc3\xb1a")
def test_text_set_no_default_body_encoding(): res = Response() res.charset = None res.default_body_encoding = None with pytest.raises(AttributeError): res.text = text_("abc")
def test_text_set_no_charset(): res = Response() res.charset = None res.text = text_("abc") assert res.text == "abc"
def test_text_get_decode(): res = Response() res.charset = "utf-8" res.body = b"La Pe\xc3\xb1a" assert res.text, text_(b"La Pe\xc3\xb1a")
def test_text_set_not_unicode(): res = Response() res.charset = "utf-8" assert_raises(TypeError, res.__setattr__, "text", b"La Pe\xc3\xb1a")
def test_text_set_not_unicode(): res = Response() res.charset = 'utf-8' assert_raises(TypeError, res.__setattr__, 'text', b'La Pe\xc3\xb1a')
def test_text_set_no_charset(): res = Response() res.charset = None assert_raises(AttributeError, res.__setattr__, 'text', 'abc')
def test_text_get_decode(): res = Response() res.charset = "utf-8" res.body = b"La Pe\xc3\xb1a" assert res.text, text_(b"La Pe\xc3\xb1a")
def test_text_set_no_charset(): res = Response() res.charset = None with pytest.raises(AttributeError): res.__setattr__('text', 'abc')
def test_text_set_no_charset(): res = Response() res.charset = None res.text = text_("abc") assert res.text == "abc"
def test_charset_set_no_content_type_header(): res = Response() res.headers.pop("Content-Type", None) with pytest.raises(AttributeError): res.charset = "utf-8"
def test_text_set_not_unicode(): res = Response() res.charset = "utf-8" with pytest.raises(TypeError): res.__setattr__("text", b"La Pe\xc3\xb1a")
def test_text_set_no_default_body_encoding(): res = Response() res.charset = None res.default_body_encoding = None with pytest.raises(AttributeError): res.text = text_("abc")
def test_text_get_decode(): res = Response() res.charset = 'utf-8' res.body = b'La Pe\xc3\xb1a' assert res.text, text_(b'La Pe\xc3\xb1a' == 'utf-8')
def test_text_set_no_charset(): res = Response() res.charset = None assert_raises(AttributeError, res.__setattr__, 'text', 'abc')
def test_text_set_not_unicode(): res = Response() res.charset = 'utf-8' with pytest.raises(TypeError): res.__setattr__('text', b'La Pe\xc3\xb1a')
def test_text_set_not_unicode(): res = Response() res.charset = 'utf-8' assert_raises(TypeError, res.__setattr__, 'text', b'La Pe\xc3\xb1a')