# Karl O. Pinc <kop@karlpinc.com>
-'''Provide a way to configure PGWUI.
-'''
-
-DEFAULT_HOME_ROUTE = '/'
-
-
-def base_view(wrapped):
- '''Decorator for any view which includes base.mk.
- '''
- def wrapper(request):
- '''Add variables missing but needed by base.mk to the response.
- '''
- response = wrapped(request)
- pgwui = response.get('pgwui', {})
- 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
- return wrapper
-
-
-def auth_base_view(wrapped):
- '''Decorator for any view which includes auth_base.mk.
- '''
- def wrapper(request):
- '''Add variables needed by auth_base.mk to the response.
- '''
- response = base_view(wrapped)(request)
- pgwui = response['pgwui']
- try:
- logout_route = request.route_url('pgwui_logout')
- except KeyError:
- pass # A logout route is not required
- else:
- pgwui['route'].setdefault('pgwui_logout', logout_route)
- return response
- return wrapper
-
-
-def includeme(config):
- '''Pyramid configuration for PGWUI_Common
- '''
- config.include('pyramid_mako')
- config.include('pyramid_beaker')
- config.add_static_view(
- 'static',
- 'pgwui_common:static/',
- cache_max_age=3600)
- config.add_route('home', DEFAULT_HOME_ROUTE)
+from .pgwui_common import includeme # noqa: F401
--- /dev/null
+# Copyright (C) 2018, 2020 The Meme Factory, Inc. http://www.karlpinc.com/
+
+# This file is part of PGWUI_Common.
+#
+# This program is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with this program. If not, see
+# <http://www.gnu.org/licenses/>.
+#
+
+# Karl O. Pinc <kop@karlpinc.com>
+
+'''Provide a way to configure PGWUI.
+'''
+
+DEFAULT_HOME_ROUTE = '/'
+
+
+def base_view(wrapped):
+ '''Decorator for any view which includes base.mk.
+ '''
+ def wrapper(request):
+ '''Add variables missing but needed by base.mk to the response.
+ '''
+ response = wrapped(request)
+ pgwui = response.get('pgwui', {})
+ 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
+ return wrapper
+
+
+def auth_base_view(wrapped):
+ '''Decorator for any view which includes auth_base.mk.
+ '''
+ def wrapper(request):
+ '''Add variables needed by auth_base.mk to the response.
+ '''
+ response = base_view(wrapped)(request)
+ pgwui = response['pgwui']
+ try:
+ logout_route = request.route_url('pgwui_logout')
+ except KeyError:
+ pass # A logout route is not required
+ else:
+ pgwui['route'].setdefault('pgwui_logout', logout_route)
+ return response
+ return wrapper
+
+
+def includeme(config):
+ '''Pyramid configuration for PGWUI_Common
+ '''
+ config.include('pyramid_mako')
+ config.include('pyramid_beaker')
+ config.add_static_view(
+ 'static',
+ 'pgwui_common:static/',
+ cache_max_age=3600)
+ config.add_route('home', DEFAULT_HOME_ROUTE)
+++ /dev/null
-# Copyright (C) 2018, 2020 The Meme Factory, Inc. http://www.karlpinc.com/
-
-# This file is part of PGWUI_Common.
-#
-# This program is free software: you can redistribute it and/or
-# modify it under the terms of the GNU Affero General Public License
-# as published by the Free Software Foundation, either version 3 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public
-# License along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
-#
-
-# Karl O. Pinc <kop@karlpinc.com>
-
-import pyramid.config
-from pyramid.threadlocal import get_current_request
-import pgwui_common.__init__ as pgwui_common_init
-
-# Activiate our pytest plugin
-pytest_plugins = ("pgwui",)
-
-
-# Helper functions and constants
-
-CSS_URL = 'foo://bar/'
-
-
-def mock_view(request):
- return {'pgwui': {'url': {'css': CSS_URL}}}
-
-
-def check_base_view_results(request, pgwui):
- assert pgwui['url']['css'] == CSS_URL
- url = (request.application_url
- + pgwui_common_init.DEFAULT_HOME_ROUTE)
- assert pgwui['route']['home'] == url
-
-
-# Unit tests
-
-# base_view()
-def test_base_view_add(pyramid_request_config):
- '''The response adds all expected variables'''
- def mock_view(request):
- return {}
-
- 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'
-
-
-def test_base_view_default(pyramid_request_config):
- '''The response retains the mock view's variables'''
- pgwui_common_init.includeme(pyramid_request_config)
- wrapper = pgwui_common_init.base_view(mock_view)
- request = get_current_request()
- response = wrapper(request)
- pgwui = response['pgwui']
- check_base_view_results(request, pgwui)
-
-
-# auth_base_view()
-
-def test_auth_base_view_logout(pyramid_request_config):
- '''The response contains base_view and auth_base_view variables
- when there is a logout route
- '''
- pgwui_common_init.includeme(pyramid_request_config)
-
- logout_route = '/logout'
- pyramid_request_config.add_route('pgwui_logout', logout_route)
- wrapper = pgwui_common_init.auth_base_view(mock_view)
- request = get_current_request()
-
- response = wrapper(request)
- pgwui = response['pgwui']
- check_base_view_results(request, pgwui)
- assert pgwui['route']['pgwui_logout'] == (request.application_url
- + logout_route)
-
-
-def test_auth_base_view_nologout(pyramid_request_config):
- '''The response contains base_view and auth_base_view variables
- when there is no logout route
- '''
- pgwui_common_init.includeme(pyramid_request_config)
-
- wrapper = pgwui_common_init.auth_base_view(mock_view)
- request = get_current_request()
-
- response = wrapper(request)
- pgwui = response['pgwui']
- check_base_view_results(request, pgwui)
-
-
-# includeme()
-
-def test_includeme_configurecalled():
- '''Pyramid Configure() methods are called'''
- class MockConfig():
- def __init__(self):
- self.include_called = False
- self.add_static_view_called = False
- self.home_route = None
-
- def include(self, *args):
- self.include_called = True
-
- def add_static_view(self, *args, **kwargs):
- self.add_static_view_called = True
-
- def add_route(self, name, route):
- if name == 'home':
- self.home_route = route
-
- config = MockConfig()
- pgwui_common_init.includeme(config)
- assert config.include_called
- assert config.add_static_view_called
- assert config.home_route == '/'
-
-
-# Integration tests
-
-def test_includeme():
- config = pyramid.config.Configurator()
- pgwui_common_init.includeme(config)
--- /dev/null
+# Copyright (C) 2018, 2020 The Meme Factory, Inc. http://www.karlpinc.com/
+
+# This file is part of PGWUI_Common.
+#
+# This program is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with this program. If not, see
+# <http://www.gnu.org/licenses/>.
+#
+
+# Karl O. Pinc <kop@karlpinc.com>
+
+import pyramid.config
+from pyramid.threadlocal import get_current_request
+import pgwui_common.pgwui_common as pgwui_common
+
+# Activiate our pytest plugin
+pytest_plugins = ("pgwui",)
+
+
+# Helper functions and constants
+
+CSS_URL = 'foo://bar/'
+
+
+def mock_view(request):
+ return {'pgwui': {'url': {'css': CSS_URL}}}
+
+
+def check_base_view_results(request, pgwui):
+ assert pgwui['url']['css'] == CSS_URL
+ url = (request.application_url
+ + pgwui_common.DEFAULT_HOME_ROUTE)
+ assert pgwui['route']['home'] == url
+
+
+# Unit tests
+
+# base_view()
+def test_base_view_add(pyramid_request_config):
+ '''The response adds all expected variables'''
+ def mock_view(request):
+ return {}
+
+ pgwui_common.includeme(pyramid_request_config)
+ wrapper = pgwui_common.base_view(mock_view)
+ response = wrapper(get_current_request())
+ assert response['pgwui']['url']['css'][0:4] == 'http'
+
+
+def test_base_view_default(pyramid_request_config):
+ '''The response retains the mock view's variables'''
+ pgwui_common.includeme(pyramid_request_config)
+ wrapper = pgwui_common.base_view(mock_view)
+ request = get_current_request()
+ response = wrapper(request)
+ pgwui = response['pgwui']
+ check_base_view_results(request, pgwui)
+
+
+# auth_base_view()
+
+def test_auth_base_view_logout(pyramid_request_config):
+ '''The response contains base_view and auth_base_view variables
+ when there is a logout route
+ '''
+ pgwui_common.includeme(pyramid_request_config)
+
+ logout_route = '/logout'
+ pyramid_request_config.add_route('pgwui_logout', logout_route)
+ wrapper = pgwui_common.auth_base_view(mock_view)
+ request = get_current_request()
+
+ response = wrapper(request)
+ pgwui = response['pgwui']
+ check_base_view_results(request, pgwui)
+ assert pgwui['route']['pgwui_logout'] == (request.application_url
+ + logout_route)
+
+
+def test_auth_base_view_nologout(pyramid_request_config):
+ '''The response contains base_view and auth_base_view variables
+ when there is no logout route
+ '''
+ pgwui_common.includeme(pyramid_request_config)
+
+ wrapper = pgwui_common.auth_base_view(mock_view)
+ request = get_current_request()
+
+ response = wrapper(request)
+ pgwui = response['pgwui']
+ check_base_view_results(request, pgwui)
+
+
+# includeme()
+
+def test_includeme_configurecalled():
+ '''Pyramid Configure() methods are called'''
+ class MockConfig():
+ def __init__(self):
+ self.include_called = False
+ self.add_static_view_called = False
+ self.home_route = None
+
+ def include(self, *args):
+ self.include_called = True
+
+ def add_static_view(self, *args, **kwargs):
+ self.add_static_view_called = True
+
+ def add_route(self, name, route):
+ if name == 'home':
+ self.home_route = route
+
+ config = MockConfig()
+ pgwui_common.includeme(config)
+ assert config.include_called
+ assert config.add_static_view_called
+ assert config.home_route == '/'
+
+
+# Integration tests
+
+def test_includeme():
+ config = pyramid.config.Configurator()
+ pgwui_common.includeme(config)