Log bad page errors
authorKarl O. Pinc <kop@karlpinc.com>
Tue, 1 Dec 2020 23:36:59 +0000 (17:36 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Tue, 1 Dec 2020 23:36:59 +0000 (17:36 -0600)
src/pgwui_common/views/ex_views.py
tests/views/test_ex_views.py

index a7ecfc61ca6e9834f841dc33e4462aa92fb03e5d..83b6d0321e645c26443816654657ee412182a0a8 100644 (file)
 '''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}'
index 030073c571f723dc2003e42867ec4fef60bb3d48..3f689bd812101a6caaa4006bbeba7e4f5e12a9d9 100644 (file)
@@ -20,6 +20,7 @@
 # Karl O. Pinc <kop@karlpinc.com>
 
 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