test_middleware.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:falcon-multipart 作者: yohanboniface 项目源码 文件源码
def test_with_binary_file(client):
    here = os.path.dirname(os.path.realpath(__file__))
    filepath = os.path.join(here, 'image.jpg')
    image = open(filepath, 'rb')

    class Resource:

        def on_post(self, req, resp, **kwargs):
            resp.data = req.get_param('afile').file.read()
            resp.content_type = 'image/jpg'

    application.add_route('/route', Resource())

    resp = client.post('/route', data={'simple': 'ok'},
                       files={'afile': image})
    assert resp.status == falcon.HTTP_OK
    image.seek(0)
    assert resp.body == image.read()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号