Skip to content

Instantly share code, notes, and snippets.

@rverton
Created August 2, 2016 15:00
Show Gist options
  • Select an option

  • Save rverton/f1542b2c1d7cf0e67e25f4588586bfcf to your computer and use it in GitHub Desktop.

Select an option

Save rverton/f1542b2c1d7cf0e67e25f4588586bfcf to your computer and use it in GitHub Desktop.
Test file upload with flask (Python3)
from io import BytesIO
def test_file_upload(client):
data = {
'field': 'value',
'file': (BytesIO(b'FILE CONTENT'), 'test.csv')
}
rv = client.post('/upload', buffered=True,
content_type='multipart/form-data',
data=data)
assert rv.status_code == 200
@ghostaccount737
Copy link
Copy Markdown

What should 'field' and 'file' do ?

@rverton
Copy link
Copy Markdown
Author

rverton commented Jun 11, 2019

Those are both POST data fields, one with the name "field" and one with the name "file" as an example.

@ghostaccount737
Copy link
Copy Markdown

Upon POSTing, I'm getting an error DebugFilesKeyError for which I'm using an exception. Any suggestions on fixing it?

@rverton
Copy link
Copy Markdown
Author

rverton commented Jun 11, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment