mercredi 30 septembre 2015

Test file upload in Flask

I have a flask's controller (POST) to upload a file:

f = request.files['external_data']
filename = secure_filename(f.filename)
f.save(filename)

I have tried to test it:

handle = open(filepath, 'rb')
fs = FileStorage(stream=handle, filename=filename, name='external_data')
payload['files'] = fs
url = '/my/upload/url'
test_client.post(url, data=payload)

But in the controller request.files contains:

ImmutableMultiDict: ImmutableMultiDict([('files', <FileStorage: u'myfile.png' ('image/png')>)])

How is it possible to create flask test request that contains request.files('external_data')?

Aucun commentaire:

Enregistrer un commentaire