Пример #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')