예제 #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)
예제 #2
0
 def test_utf_struct(self):
     rval = parse_json_request(b'{"lang":"\xc4\x8de\xc5\xa1tina"}')
     assert rval == {"lang": "čeština"}
예제 #3
0
 def test_utf8(self):
     rval = parse_json_request(b'"\xc4\x8de\xc5\xa1tina"')
     assert rval == "čeština"
예제 #4
0
 def test_unicode_struct(self):
     rval = parse_json_request(b'{"lang":"\\u010de\\u0161tina"}')
     assert rval == {"lang": "čeština"}
예제 #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]
예제 #6
0
 def test_unicode(self):
     rval = parse_json_request(b'"\\u010de\\u0161tina"')
     assert rval == "čeština"
예제 #7
0
 def test_bool(self):
     assert isinstance(parse_json_request(b"true"), bool)
예제 #8
0
 def test_null(self):
     assert parse_json_request(b"null") is None
예제 #9
0
 def test_float(self):
     assert isinstance(parse_json_request(b"3.14"), float)
예제 #10
0
 def test_int(self):
     assert isinstance(parse_json_request(b"23"), int)
예제 #11
0
 def test_text(self):
     assert isinstance(parse_json_request(b'"text"'), str)
예제 #12
0
 def test_list(self):
     assert isinstance(parse_json_request(b"[]"), JsonList)
예제 #13
0
 def test_str(self):
     assert isinstance(parse_json_request(b"{}"), JsonDict)