From 244e0a8cc4c0f31b4da082fc194e5711b363438d Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Fri, 11 Sep 2020 16:14:58 -0500 Subject: [PATCH] Use dicts instead of dots in response's "pgwui" keys --- src/pgwui_common/__init__.py | 14 ++++++++------ src/pgwui_common/plugin.py | 6 ------ src/pgwui_common/templates/auth_base.mak | 10 +++++----- src/pgwui_common/templates/base.mak | 7 ++++--- tests/test___init__.py | 16 ++++++++-------- tests/test_plugin.py | 12 ------------ 6 files changed, 25 insertions(+), 40 deletions(-) diff --git a/src/pgwui_common/__init__.py b/src/pgwui_common/__init__.py index 04d768d..9508b90 100644 --- a/src/pgwui_common/__init__.py +++ b/src/pgwui_common/__init__.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018 The Meme Factory, Inc. http://www.meme.com/ +# Copyright (C) 2018, 2020 The Meme Factory, Inc. http://www.karlpinc.com/ # This file is part of PGWUI_Common. # @@ -17,7 +17,7 @@ # . # -# Karl O. Pinc +# Karl O. Pinc '''Provide a way to configure PGWUI. ''' @@ -33,9 +33,11 @@ def base_view(wrapped): ''' response = wrapped(request) pgwui = response.get('pgwui', {}) - pgwui.setdefault('url.css', - request.static_url('pgwui_common:static/pgwui.css')) - pgwui.setdefault('route.home', + url = pgwui.setdefault('url', dict()) + url.setdefault('css', + request.static_url('pgwui_common:static/pgwui.css')) + route = pgwui.setdefault('route', dict()) + route.setdefault('home', request.route_url('home')) response['pgwui'] = pgwui return response @@ -55,7 +57,7 @@ def auth_base_view(wrapped): except KeyError: pass # A logout route is not required else: - pgwui.setdefault('route.pgwui_logout', logout_route) + pgwui['route'].setdefault('pgwui_logout', logout_route) return response return wrapper diff --git a/src/pgwui_common/plugin.py b/src/pgwui_common/plugin.py index 9a88175..2025be0 100644 --- a/src/pgwui_common/plugin.py +++ b/src/pgwui_common/plugin.py @@ -41,9 +41,3 @@ def find_pgwui_check_settings(): callable = entry_point.resolve() check_settings[callable.__name__] = callable return check_settings - - -def component_to_key(component): - '''Convert the component to a key used in an ini file's declaration - ''' - return 'pgwui.{}'.format(component) diff --git a/src/pgwui_common/templates/auth_base.mak b/src/pgwui_common/templates/auth_base.mak index da5317c..d22ff3a 100644 --- a/src/pgwui_common/templates/auth_base.mak +++ b/src/pgwui_common/templates/auth_base.mak @@ -1,6 +1,6 @@ <%doc> - Copyright (C) 2015 The Meme Factory, Inc. http://www.meme.com/ + Copyright (C) 2015, 2020 The Meme Factory, Inc. http://www.karlpinc.com/ This file is part of PGWUI_Common. @@ -20,7 +20,7 @@ Base template for form that authenticates a user and accesses a db. - Karl O. Pinc + Karl O. Pinc This template uses the following variables in it's context: @@ -46,9 +46,9 @@ <%def name="navbar()"> diff --git a/src/pgwui_common/templates/base.mak b/src/pgwui_common/templates/base.mak index b4b259d..42d042b 100644 --- a/src/pgwui_common/templates/base.mak +++ b/src/pgwui_common/templates/base.mak @@ -1,6 +1,7 @@ <%doc> - Copyright (C) 2014, 2015, 2018 The Meme Factory, Inc. http://www.meme.com/ + Copyright (C) 2014, 2015, 2018, 2020 The Meme Factory, Inc. + http://www.karlpinc.com/ This file is part of PGWUI_Common. @@ -33,7 +34,7 @@ <%def name="navbar()"> @@ -45,7 +46,7 @@ <%block name="meta_keywords" /> <%block name="meta_description" /> - + diff --git a/tests/test___init__.py b/tests/test___init__.py index fcf1c17..e51d3cf 100644 --- a/tests/test___init__.py +++ b/tests/test___init__.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018 The Meme Factory, Inc. http://www.meme.com/ +# Copyright (C) 2018, 2020 The Meme Factory, Inc. http://www.karlpinc.com/ # This file is part of PGWUI_Common. # @@ -17,7 +17,7 @@ # . # -# Karl O. Pinc +# Karl O. Pinc import pyramid.config from pyramid.threadlocal import get_current_request @@ -33,14 +33,14 @@ CSS_URL = 'foo://bar/' def mock_view(request): - return {'pgwui': {'url.css': CSS_URL}} + return {'pgwui': {'url': {'css': CSS_URL}}} def check_base_view_results(request, pgwui): - assert pgwui['url.css'] == CSS_URL + assert pgwui['url']['css'] == CSS_URL url = (request.application_url + pgwui_common_init.DEFAULT_HOME_ROUTE) - assert pgwui['route.home'] == url + assert pgwui['route']['home'] == url # Unit tests @@ -54,7 +54,7 @@ def test_base_view_add(pyramid_request_config): pgwui_common_init.includeme(pyramid_request_config) wrapper = pgwui_common_init.base_view(mock_view) response = wrapper(get_current_request()) - assert response['pgwui']['url.css'][0:4] == 'http' + assert response['pgwui']['url']['css'][0:4] == 'http' def test_base_view_default(pyramid_request_config): @@ -83,8 +83,8 @@ def test_auth_base_view_logout(pyramid_request_config): response = wrapper(request) pgwui = response['pgwui'] check_base_view_results(request, pgwui) - assert pgwui['route.pgwui_logout'] == (request.application_url - + logout_route) + assert pgwui['route']['pgwui_logout'] == (request.application_url + + logout_route) def test_auth_base_view_nologout(pyramid_request_config): diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 077f925..9ecbd9e 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -67,15 +67,3 @@ def test_find_pgwui_check_settings(monkeypatch): assert isinstance(result, dict) assert list(result.keys()).sort() == entry_points.sort() - - -# component_to_key() - -def test_component_to_key(): - '''The return value is as expected - ''' - component = 'pgwui_example' - - result = plugin.component_to_key(component) - - assert result == 'pgwui.' + component -- 2.34.1