From f63a85d0038cb7925a4d2f071dc52f482953dee2 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Fri, 11 Mar 2016 10:16:06 +0000 Subject: [PATCH 1/2] Fix bug in error handlers. Correct spelling error --- app/__init__.py | 6 +----- app/main/views/dashboard.py | 3 +-- tests/app/main/test_errorhandlers.py | 21 +++++++++++++++++++++ tests/app/main/views/test_accept_invite.py | 2 +- tests/app/main/views/test_sign_out.py | 2 -- 5 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 tests/app/main/test_errorhandlers.py diff --git a/app/__init__.py b/app/__init__.py index 67e53be0a..d0ce1d245 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -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) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index e43f66b15..b3e9c6810 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -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( diff --git a/tests/app/main/test_errorhandlers.py b/tests/app/main/test_errorhandlers.py new file mode 100644 index 000000000..cb84e65a1 --- /dev/null +++ b/tests/app/main/test_errorhandlers.py @@ -0,0 +1,21 @@ +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' + + +def test_bad_input_returns_something(app_, api_user_active, mock_login): + with app_.test_request_context(): + with app_.test_client() as client: + client.login(api_user_active) + response = client.get(url_for('main.service_dashboard', service_id=1)) + response.status == 404 + print(response.get_data(as_text=True)) + page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') + assert page.h1.string.strip() == 'Page could not be found' diff --git a/tests/app/main/views/test_accept_invite.py b/tests/app/main/views/test_accept_invite.py index eaa796198..9614030bc 100644 --- a/tests/app/main/views/test_accept_invite.py +++ b/tests/app/main/views/test_accept_invite.py @@ -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' diff --git a/tests/app/main/views/test_sign_out.py b/tests/app/main/views/test_sign_out.py index f4d7019a8..a6b8e5fcb 100644 --- a/tests/app/main/views/test_sign_out.py +++ b/tests/app/main/views/test_sign_out.py @@ -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: From ccaa5410b355364ddad9873dc233488fd4d726d5 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Fri, 11 Mar 2016 10:47:16 +0000 Subject: [PATCH 2/2] Removed test as it was not testing the right thing --- tests/app/main/test_errorhandlers.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/app/main/test_errorhandlers.py b/tests/app/main/test_errorhandlers.py index cb84e65a1..f4853632f 100644 --- a/tests/app/main/test_errorhandlers.py +++ b/tests/app/main/test_errorhandlers.py @@ -8,14 +8,3 @@ def test_bad_url_returns_page_not_found(app_): 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_bad_input_returns_something(app_, api_user_active, mock_login): - with app_.test_request_context(): - with app_.test_client() as client: - client.login(api_user_active) - response = client.get(url_for('main.service_dashboard', service_id=1)) - response.status == 404 - print(response.get_data(as_text=True)) - page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') - assert page.h1.string.strip() == 'Page could not be found'