示例#1
0
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
示例#2
0
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'')
示例#3
0
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""
示例#4
0
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""
示例#5
0
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"")
示例#6
0
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''
示例#7
0
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'')
示例#8
0
    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)
示例#9
0
    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)
示例#10
0
def test_charset_set_no_content_type_header():
    res = Response()
    res.headers.pop("Content-Type", None)
    with pytest.raises(AttributeError):
        res.charset = "utf-8"
示例#11
0
def test_text_set_not_unicode():
    res = Response()
    res.charset = "utf-8"
    with pytest.raises(TypeError):
        res.__setattr__("text", b"La Pe\xc3\xb1a")
示例#12
0
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")
示例#13
0
def test_text_set_no_charset():
    res = Response()
    res.charset = None
    res.text = text_("abc")
    assert res.text == "abc"
示例#14
0
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")
示例#15
0
def test_text_set_not_unicode():
    res = Response()
    res.charset = "utf-8"
    assert_raises(TypeError, res.__setattr__, "text", b"La Pe\xc3\xb1a")
示例#16
0
def test_text_set_not_unicode():
    res = Response()
    res.charset = 'utf-8'
    assert_raises(TypeError, res.__setattr__, 'text', b'La Pe\xc3\xb1a')
示例#17
0
def test_text_set_no_charset():
    res = Response()
    res.charset = None
    assert_raises(AttributeError, res.__setattr__, 'text', 'abc')
示例#18
0
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")
示例#19
0
def test_text_set_no_charset():
    res = Response()
    res.charset = None
    with pytest.raises(AttributeError):
        res.__setattr__('text', 'abc')
示例#20
0
def test_text_set_no_charset():
    res = Response()
    res.charset = None
    res.text = text_("abc")
    assert res.text == "abc"
示例#21
0
def test_charset_set_no_content_type_header():
    res = Response()
    res.headers.pop("Content-Type", None)
    with pytest.raises(AttributeError):
        res.charset = "utf-8"
示例#22
0
def test_text_set_not_unicode():
    res = Response()
    res.charset = "utf-8"
    with pytest.raises(TypeError):
        res.__setattr__("text", b"La Pe\xc3\xb1a")
示例#23
0
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")
示例#24
0
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')
示例#25
0
def test_text_set_no_charset():
    res = Response()
    res.charset = None
    assert_raises(AttributeError, res.__setattr__, 'text', 'abc')
示例#26
0
def test_text_set_not_unicode():
    res = Response()
    res.charset = 'utf-8'
    with pytest.raises(TypeError):
        res.__setattr__('text',
                        b'La Pe\xc3\xb1a')
示例#27
0
def test_text_set_not_unicode():
    res = Response()
    res.charset = 'utf-8'
    assert_raises(TypeError, res.__setattr__, 'text',
                  b'La Pe\xc3\xb1a')