Python 如何为Rester服务(flask)的上传、下载功能编写单元测试用例?

Python 如何为Rester服务(flask)的上传、下载功能编写单元测试用例?,python,flask,Python,Flask,我是python和单元测试的新手,如何为下面的功能编写单元测试用例。提前谢谢 from flask import request @app.route('/upload', methods=['GET', 'POST']) def upload_file(): if request.method == 'POST': f = request.files['the_file'] f.save('/uploaded_file.txt') 您应该在测试中请求

我是python和单元测试的新手,如何为下面的功能编写单元测试用例。提前谢谢

from flask import request

@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        f = request.files['the_file']
        f.save('/uploaded_file.txt')

您应该在测试中请求一个模拟对象而不是文件。之后,在测试中调用此方法,并验证是否在模拟中使用正确的参数调用了save方法