dimanche 28 juin 2015

Flask: Unit Test Ability to Handle Http Errors

I have a Flask app that sends a POST request in response to a POST request (for various reasons, we needed an in-between to handle processing from one service to another). I want to test the response to the second POST request, namely, if this other service returns something bad, making sure my app will return something useful and not fail messily.

I'm using responses to catch the outgoing POST request and mock a response, which is working.

The issue is that I'm using self.app.post to mock the incoming POST request to my app. An example of how I'd like this to run is:

  • incoming POST is mocked and sent to the app
  • processing, then outgoing POST request
  • depending on result of that request, app returns 200 or 400 to the first mocked post request

So self.app.post should return a 200 or a 400 depending on what my app returns, but self.app.post seems to always return a <200 TestResponse>. Is there a way to override this with what is actually getting returned, or another way to send a post request to my app to test it?

Aucun commentaire:

Enregistrer un commentaire