librelist archives

« back to archive

Testing uploads question

Testing uploads question

From:
Greg Wade
Date:
2011-11-22 @ 21:31
Hi guys,

Thanks for creating this great framework. I'm new to python (coming from
Java), and wanted a streamlined framework. Flask is perfect. Love it.

Anyhow, I'm creating test cases, and I've bumped into a problem. I'm
allowing avatar uploads, using the flask functionality for uploads. How do
I go about writing a test case for this?

Thus far I've been test-casing my app with GET's (even though the real
client uses POST):

        res = self.app.get("/api/login/?email=greg@place.com
&password=idontthinkso")

This works great. But how do I upload? For that matter, is there a good way
to test with POST instead of GET?

Thanks,

Greg.

Re: [flask] Testing uploads question

From:
Simon Sapin
Date:
2011-11-22 @ 22:43
Le 22/11/2011 22:31, Greg Wade a écrit :
>
> Thus far I've been test-casing my app with GET's (even though the real
> client uses POST):
>
>          res = self.app.get("/api/login/?email=greg@place.com
> <mailto:greg@place.com>&password=idontthinkso")
>
> This works great. But how do I upload? For that matter, is there a good
> way to test with POST instead of GET?
>

Hi,

The test client is from Werkzeug and has the same API as the 
"environment builder":

http://werkzeug.pocoo.org/docs/test/#werkzeug.test.Client
http://werkzeug.pocoo.org/docs/test/#werkzeug.test.EnvironBuilder

In particular, the "data" parameter can take a dict of file-like objects.

Regards,
-- 
Simon Sapin