nubela nubela - 1 month ago 12
Python Question

How can I fake request.POST and GET params for unit testing in Flask?

I would like to fake request parameters for unit testing. How can I achieve this in Flask?

Thanks.

Answer

Did you read Flask docs about testing?

You can use following:

self.app.post('/path-to-request', data=dict(var1='data1', var2='data2', ...))
self.app.get('/path-to-request')