Test Two Flask Applications Talking To Each Other?
- Derek Gaston
- 2014-07-04 @ 21:53
I see how to test a Flask app using test_client()... but my Flask app is
more than a server. Here's the setup:
client.py <---- JSON ----> MyFlaskApp <---- JSON ----> ThirdPartyService
How do I go about testing this? The client->MyFlaskApp part is pretty
straight forward because requests are only made and data is only sent by
the client (the FlaskApp is just responding) so it works pretty well in the
normal testing framework.
However... how do I test the FlaskApp<-->ThirdPartyService part? The
interaction is pretty complex with JSON signals being sent both ways. My
idea was to create a MockThirdPartyService that is a FlaskApp that responds
like that service.... but then it's not clear to me how to make an instance
of each app during a unittest and then get them to talk to each other...
verifying the responses on both sides.
Has anyone else dealt with this before?