mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 05:59:44 -04:00
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:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user