On Github blueninj0r / responses-is-great
We are all working in a massive distributed system
We often use HTTP APIs as a channel to share data between computational nodes
It's nice to be able to release changes quickly and with confidence
Write some nice automated unit and integration tests
Dependencies on those other HTTP APIs:
A minimal mocking framework for the Python Requests library
@responses.activate def test_my_api(): responses.add(responses.GET, 'http://twitter.com/api/1/foobar', body='{"error": "not found"}', status=404, content_type='application/json') resp = requests.get('http://twitter.com/api/1/foobar') assert resp.json() == {"error": "not found"} assert len(responses.calls) == 1 assert responses.calls[0].request.url == 'http://twitter.com/api/1/foobar' assert responses.calls[0].response.text == '{"error": "not found"}'
For not much effort we have valuable but less expensive tests
My squad has used this for Real Work™:
Breaking the horrible dependency on the rest of the world existing
There are other tools or practises out there:
I'm Chris McCluskey from Travel Content Platform Squad (#tcp-public)