September 12, 2018
Testing Rest API Responses
I have been developping a REST API at work using Flask, and wanted to test the response I got.
I started by testing directly the raw response using response.data, which works for small responses. As soon as you want to make it dynamic, it becomes a nightmare. Let’s say we start with the following test
# Bad idea def test_response_string(): response = client.get("/test") assert response.status_code == 200 assert response.data == '{"key1": "value1", "key2": "value2"}' Now, with just this test, adding a value or modifying it would be easy.
Read more