As in Greenwave now the error messages are in JSON format and not in HTML. Also fixed some errors in the doc.
I guess you could just do: return insert_headers(response)
Can you split the doc changes into separate commit?
One less newline here to conform with pep?
rebased onto 30e174a086c1fbd2464e46051d7f119a533a6816
@gnaponie, there is some odd whitespace here. Can you remove it?
If your editor doesn't show it, you should be able to get at it with sed -i 's/ *$//g' waiverdb/app.py
sed -i 's/ *$//g' waiverdb/app.py
The change looks reasonable to me and the test suite passes as is.
Something like this could help test that the 404 response is really JSON.
diff --git a/tests/test_api_v10.py b/tests/test_api_v10.py index 6fe55e2..0ed1665 100644 --- a/tests/test_api_v10.py +++ b/tests/test_api_v10.py @@ -55,6 +55,11 @@ def test_get_waiver(client, session): def test_404_for_nonexistent_waiver(client, session): r = client.get('/api/v1.0/waivers/foo') assert r.status_code == 404 + res_data = json.loads(r.get_data(as_text=True)) + message = ( + 'The requested URL was not found on the server. If you entered the ' + 'URL manually please check your spelling and try again.') + assert res_data['message'] == message def test_get_waivers(client, session):
Can you add that and then explore trying to add a whole new test that checks for a response with a status code of 500? You'll need to mock the app somehow to force it to raise an exception, which should then be caught by your handler to return a sane JSON response.
1 new commit added
Looks good to me. :+1:
Pull-Request has been merged by gnaponie
Alternatively, you could use pytest.raises which might be nicer.
pytest.raises
https://docs.pytest.org/en/latest/assert.html#assertions-about-expected-exceptions
@mjia but as far as I know I do not have an api returning status code 500... I can always create one, but is that the correct way?
@gnaponie, yeah, my bad as I misread the code. Don't worry, :-)
@mjia thank you anyway for your comment! :) I've learnt something new.
As in Greenwave now the error messages are in JSON format and not in HTML. Also fixed some errors in the doc.