mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
Merge pull request #263 from alphagov/error-handling
Fix bug in error handlers.
This commit is contained in:
@@ -184,15 +184,11 @@ def register_errorhandlers(application):
|
||||
|
||||
@application.errorhandler(HTTPError)
|
||||
def render_http_error(error):
|
||||
error_code = getattr(error, 'code', 500)
|
||||
error_code = error.status_code
|
||||
if error_code not in [401, 404, 403, 500]:
|
||||
error_code = 500
|
||||
return _error_response(error_code)
|
||||
|
||||
@application.errorhandler(400)
|
||||
def handle_bad_request(error):
|
||||
return _error_response(404)
|
||||
|
||||
@application.errorhandler(404)
|
||||
def handle_not_found(error):
|
||||
return _error_response(404)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from flask import (
|
||||
abort,
|
||||
render_template,
|
||||
session,
|
||||
flash
|
||||
@@ -25,7 +24,7 @@ def service_dashboard(service_id):
|
||||
if session.get('invited_user'):
|
||||
session.pop('invited_user', None)
|
||||
service_name = service['data']['name']
|
||||
message = 'You have sucessfully accepted your invitation and been added to {}'.format(service_name)
|
||||
message = 'You have successfully accepted your invitation and been added to {}'.format(service_name)
|
||||
flash(message, 'default_with_tick')
|
||||
|
||||
return render_template(
|
||||
|
||||
10
tests/app/main/test_errorhandlers.py
Normal file
10
tests/app/main/test_errorhandlers.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from flask import url_for
|
||||
|
||||
|
||||
def test_bad_url_returns_page_not_found(app_):
|
||||
with app_.test_client() as client:
|
||||
response = client.get('/bad_url')
|
||||
assert response.status_code == 404
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.h1.string.strip() == 'Page could not be found'
|
||||
@@ -257,4 +257,4 @@ def test_new_invited_user_verifies_and_added_to_service(app_,
|
||||
assert service_link == '/services/{}/dashboard'.format(service_one['id'])
|
||||
|
||||
flash_banner = page.find('div', class_='banner-default-with-tick').string.strip()
|
||||
assert flash_banner == 'You have sucessfully accepted your invitation and been added to Test Service'
|
||||
assert flash_banner == 'You have successfully accepted your invitation and been added to Test Service'
|
||||
|
||||
@@ -19,8 +19,6 @@ def test_sign_out_user(app_,
|
||||
mock_login,
|
||||
mock_get_jobs):
|
||||
with app_.test_request_context():
|
||||
email = 'valid@example.gov.uk'
|
||||
password = 'val1dPassw0rd!'
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
with client.session_transaction() as session:
|
||||
|
||||
Reference in New Issue
Block a user