How to send requests with JSONs in unit tests

前端 未结 2 610
挽巷
挽巷 2020-12-04 22:59

I have code within a Flask application that uses JSONs in the request, and I can get the JSON object like so:

Request = request.get_json()

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 23:32

    Changing the post to

    response=self.app.post('/test_function', 
                           data=json.dumps(dict(foo='bar')),
                           content_type='application/json')
    

    fixed it.

    Thanks to user3012759.

提交回复
热议问题