I have written an endpoint in my flask server, that when triggered, with a GET request, and a parameter, the server will parse the parameter, and serve the file (specified in the parameter) to the user to download.
This is the server's code:
@app.route('/getfile', methods=['GET'])
def dl_file():
requestedFile = request.args.get('id')
allFiles = os.listdir('myFiles')
if requestedFile not in allFiles:
return make_response(json.dumps({'error_message': 'item does not exist'}), 400)
else:
return send_file(pathAndFilename, as_attachment=True, attachment_filename = requestedFile)
I am able to trigger this with:
curl -X GET "0000:5000/getfile?id=myFile.txt"
How do i trigger this in pytest?
But i do not know how to pass the parameter in the GET request, and how to grab the server's response.
Not Found
\nThe requested URL was not found on the server`. I don't know why.
– user1584421 Mar 23 '21 at 14:12