コード例 #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
ファイル: test_request.py プロジェクト: PoorHttp/PoorWSGI
 def test_utf_struct(self):
     rval = parse_json_request(b'{"lang":"\xc4\x8de\xc5\xa1tina"}')
     assert rval == {"lang": "čeština"}
コード例 #3
0
ファイル: test_request.py プロジェクト: PoorHttp/PoorWSGI
 def test_utf8(self):
     rval = parse_json_request(b'"\xc4\x8de\xc5\xa1tina"')
     assert rval == "čeština"
コード例 #4
0
ファイル: test_request.py プロジェクト: PoorHttp/PoorWSGI
 def test_unicode_struct(self):
     rval = parse_json_request(b'{"lang":"\\u010de\\u0161tina"}')
     assert rval == {"lang": "čeština"}
コード例 #5
0
ファイル: test_request.py プロジェクト: PoorHttp/PoorWSGI
 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
ファイル: test_request.py プロジェクト: PoorHttp/PoorWSGI
 def test_unicode(self):
     rval = parse_json_request(b'"\\u010de\\u0161tina"')
     assert rval == "čeština"
コード例 #7
0
ファイル: test_request.py プロジェクト: PoorHttp/PoorWSGI
 def test_bool(self):
     assert isinstance(parse_json_request(b"true"), bool)
コード例 #8
0
ファイル: test_request.py プロジェクト: PoorHttp/PoorWSGI
 def test_null(self):
     assert parse_json_request(b"null") is None
コード例 #9
0
ファイル: test_request.py プロジェクト: PoorHttp/PoorWSGI
 def test_float(self):
     assert isinstance(parse_json_request(b"3.14"), float)
コード例 #10
0
ファイル: test_request.py プロジェクト: PoorHttp/PoorWSGI
 def test_int(self):
     assert isinstance(parse_json_request(b"23"), int)
コード例 #11
0
ファイル: test_request.py プロジェクト: PoorHttp/PoorWSGI
 def test_text(self):
     assert isinstance(parse_json_request(b'"text"'), str)
コード例 #12
0
ファイル: test_request.py プロジェクト: PoorHttp/PoorWSGI
 def test_list(self):
     assert isinstance(parse_json_request(b"[]"), JsonList)
コード例 #13
0
ファイル: test_request.py プロジェクト: PoorHttp/PoorWSGI
 def test_str(self):
     assert isinstance(parse_json_request(b"{}"), JsonDict)