Log the url map given to templates
authorKarl O. Pinc <kop@karlpinc.com>
Tue, 8 Dec 2020 05:33:16 +0000 (23:33 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Tue, 8 Dec 2020 19:29:04 +0000 (13:29 -0600)
src/pgwui_common/urls.py
tests/test_urls.py

index c87f88c40f75721cbedeacdcb012d16f50ed822c..63ae9cd5d3164adb70906110fce092e79d52293e 100644 (file)
 '''Expose useful response "variables" to templates
 '''
 
+import logging
 import pyramid.request
 
 from .plugin import find_pgwui_components
 from . import exceptions as ex
 
+# Logging
+log = logging.getLogger(__name__)
+
 
 def route_path(request, page_name, source):
     '''Return the route path of the page's "source"
@@ -113,3 +117,5 @@ def add_urls_setting(config, settings):
     request.registry = config.registry
     set_urls(request, urls)
     settings['pgwui']['urls'] = urls
+    log.debug('Routing map of route names to url paths which is given'
+              f' to the templates: {urls}')
index 9a3c467ab6be8433fb94f855a9970993d4492248..1bc49135853bf7deebd46cb859d02665e291ad70 100644 (file)
@@ -20,6 +20,7 @@
 # Karl O. Pinc <kop@karlpinc.com>
 
 import pytest
+import logging
 import pyramid.request
 from pyramid.threadlocal import get_current_request
 
@@ -286,10 +287,11 @@ mock_set_urls = testing.make_mock_fixture(
 # add_urls_setting()
 
 def test_add_urls_setting(
-        pyramid_request_config, mock_request_blank, mock_set_urls):
+        caplog, pyramid_request_config, mock_request_blank, mock_set_urls):
     '''Request.blank() and set_urls() are called, the urls set
     are put in the pgwui dict in the settings
     '''
+    caplog.set_level(logging.DEBUG)
     expected_urls = {'key1': 'val1', 'key2': 'val2'}
 
     def set_urls(request, urls):
@@ -307,3 +309,7 @@ def test_add_urls_setting(
     mock_request_blank.blank.assert_called_once()
     mock_set_urls.assert_called_once()
     assert settings['pgwui']['urls'] == expected_urls
+
+    logs = caplog.record_tuples
+    assert len(logs) == 1
+    assert logs[0][1] == logging.DEBUG