Testing POST multiple files on Flask, is it confusing?

Hasil gambar untuk http request
Hey guys, it's me again Rafiano. Last week, I was desperately confused about making unittest on POST request, sending multiple buffered files (specifically .csv files) to my upload API. Then, after spending a few days researching about how to do it, I finally found a way to send them.

The .csv mock files have to be written as StringIO objects. But, to send it as POST request, they have to be in BytesIO objects. Then, how exactly?

So, after making them into StringIO object you have to read() and decode() it and pass it as __init__ parameter of BytesIO class.


After making them into BytesIO objects, it has to be saved as a dictionary with this format:



then, the object has to be sent as 'multipart/form-data' content_type. This is how:

So basically that's how. See you on the next occasion!

0 komentar:

Post a Comment