How can I fake request.POST and GET params for unit testing in Flask?
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', query_string=dict(arg1='data1', arg2='data2', ...))
Current development version of Flask also includes support for testing JSON APIs:
from flask import request, jsonify
@app.route('/jsonapi')
def auth():
json_data = request.get_json()
attribute = json_data['attr']
return jsonify(resp=generate_response(attribute))
with app.test_client() as c:
rv = c.post('/jsonapi', json={
'attr': 'value', 'other': 'data'
})
json_data = rv.get_json()
assert generate_response(email, json_data['resp'])
POST:
self.app.post('/endpoint', data=params)
GET:
self.app.get('/endpoint', query_string=params)