Ejemplo n.º 1
0
def test_json(req):
    """Test GET / POST json"""
    # numbers are complete list
    data = req.json
    if req.is_chunked_request:
        raw = b''
        # chunk must be read with extra method, uwsgi has own
        chunk = uwsgi.chunked_read() if uwsgi else req.read_chunk()
        while chunk:
            raw += chunk
            chunk = uwsgi.chunked_read() if uwsgi else req.read_chunk()
        data = parse_json_request(raw, req.charset)

    return JSONResponse(status_code=418,
                        message="I'm teapot :-)",
                        numbers=list(range(5)),
                        request=data)
Ejemplo n.º 2
0
 def test_utf_struct(self):
     rval = parse_json_request(b'{"lang":"\xc4\x8de\xc5\xa1tina"}')
     assert rval == {"lang": "čeština"}
Ejemplo n.º 3
0
 def test_utf8(self):
     rval = parse_json_request(b'"\xc4\x8de\xc5\xa1tina"')
     assert rval == "čeština"
Ejemplo n.º 4
0
 def test_unicode_struct(self):
     rval = parse_json_request(b'{"lang":"\\u010de\\u0161tina"}')
     assert rval == {"lang": "čeština"}
Ejemplo n.º 5
0
 def test_error(self):
     with raises(HTTPException) as err:
         parse_json_request(BytesIO(b"abraka"))
     assert err.value.args[0] == 400
     assert 'error' in err.value.args[1]
Ejemplo n.º 6
0
 def test_unicode(self):
     rval = parse_json_request(b'"\\u010de\\u0161tina"')
     assert rval == "čeština"
Ejemplo n.º 7
0
 def test_bool(self):
     assert isinstance(parse_json_request(b"true"), bool)
Ejemplo n.º 8
0
 def test_null(self):
     assert parse_json_request(b"null") is None
Ejemplo n.º 9
0
 def test_float(self):
     assert isinstance(parse_json_request(b"3.14"), float)
Ejemplo n.º 10
0
 def test_int(self):
     assert isinstance(parse_json_request(b"23"), int)
Ejemplo n.º 11
0
 def test_text(self):
     assert isinstance(parse_json_request(b'"text"'), str)
Ejemplo n.º 12
0
 def test_list(self):
     assert isinstance(parse_json_request(b"[]"), JsonList)
Ejemplo n.º 13
0
 def test_str(self):
     assert isinstance(parse_json_request(b"{}"), JsonDict)