简体   繁体   中英

In pytesting, how to provide the link/pointer to the file/image for uploading the image in flask

I am using flask with python 3.5 and try to test my code with pytest for uploading the image.I have gone through various answers but sadly couldn't get the point to solve my problem.In link of github, it explains how to use filename, file_field https://gist.github.com/DazWorrall/1779861 I tried in that way also but i wasn't going in right direction. Please help me in solving my problem. Here, post method is used to upload the image, content-part should be multi-part but regarding data, how to send the image data and its path.

test_client.post(
    '/uploadimage',
    content_type='multipart/form-data',
    buffered=True,
    data=dict(
        file='user4.jpg', file_field=io.BytesIO(b"~/Downloads/images/")),
    follow_redirects=True)

In here, while running for pytest it doesn't recognise the file. Dont know why? I will hope to get my answer soon.. Thanks.

res = test_client.post( products_url, content_type='multipart/form-data', buffered=True, data={ 'file': (io.BytesIO(b'~/Downloads/images'), 'user4.jpg'), })

Little bit change the way data is send. It is working fine for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM