make sure load_service_before_request handles 404s

if it 404s, because the service id doesn't exist, then it should die
gracefully (showing a 404 error page), rather than what it currently
does, which is die kicking and screaming with a 500
This commit is contained in:
Leo Hemsted
2017-10-30 16:59:24 +00:00
parent 8ec50971eb
commit 3128b5424d
2 changed files with 31 additions and 3 deletions

View File

@@ -1,4 +1,6 @@
from flask import Response
from bs4 import BeautifulSoup
from notifications_python_client.errors import HTTPError
def test_bad_url_returns_page_not_found(client):
@@ -6,3 +8,16 @@ def test_bad_url_returns_page_not_found(client):
assert response.status_code == 404
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page.h1.string.strip() == 'Page could not be found'
def test_load_service_before_request_handles_404(client_request, mocker):
exc = HTTPError(Response(status=404), 'Not found')
get_service = mocker.patch('app.service_api_client.get_service', side_effect=exc)
client_request.get(
'main.service_dashboard',
service_id='00000000-0000-0000-0000-000000000000',
_expected_status=404
)
get_service.assert_called_once_with('00000000-0000-0000-0000-000000000000')