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()
评论列表
文章目录