From ef186aa5b9089f558149b9a81d0f873da59f9ab0 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Tue, 1 Dec 2020 17:36:59 -0600 Subject: [PATCH] Log bad page errors --- src/pgwui_common/views/ex_views.py | 5 +++++ tests/views/test_ex_views.py | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/pgwui_common/views/ex_views.py b/src/pgwui_common/views/ex_views.py index a7ecfc6..83b6d03 100644 --- a/src/pgwui_common/views/ex_views.py +++ b/src/pgwui_common/views/ex_views.py @@ -22,15 +22,20 @@ '''Views for exceptions that are raised ''' +import logging from pyramid.view import exception_view_config from pgwui_common import exceptions as ex NOT_FOUND = '404 Not Found' +# Logging +log = logging.getLogger(__name__) + @exception_view_config(ex.BadPageError, renderer='string') def bad_config_view(ex, request): request.response.status_code = 404 request.response.status = NOT_FOUND + log.error(f'{ex}:{ex.ex}') return f'PGWUI Configuration Error:\n{ex}:\n{ex.ex}' diff --git a/tests/views/test_ex_views.py b/tests/views/test_ex_views.py index 030073c..3f689bd 100644 --- a/tests/views/test_ex_views.py +++ b/tests/views/test_ex_views.py @@ -20,6 +20,7 @@ # Karl O. Pinc import pytest +import logging from pyramid.threadlocal import get_current_request import pgwui_common.views.ex_views as ex_views @@ -40,8 +41,10 @@ mock_exception_view_config = testing.make_mock_fixture( # bad_config_view() @pytest.mark.unittest -def test_bad_config_view(pyramid_request_config, mock_exception_view_config): - '''Modifies the request, returns an expected response +def test_bad_config_view( + caplog, pyramid_request_config, mock_exception_view_config): + '''Modifies the request, returns an expected response, and logs + an error ''' request = get_current_request() result = ex_views.bad_config_view( @@ -50,3 +53,7 @@ def test_bad_config_view(pyramid_request_config, mock_exception_view_config): assert isinstance(result, str) assert request.response.status_code == 404 assert request.response.status == ex_views.NOT_FOUND + + logs = caplog.record_tuples + assert len(logs) == 1 + assert logs[0][1] == logging.ERROR -- 2.34.1