pass
-class AutoconfigureConflict(ServerError):
- def __init__(self):
- super().__init__(
- 'Autoconfigure is True and there is a pyramid.include setting')
+class ServerInfo(exceptions.Info):
+ '''Information exceptions; which don't stop the program
+ '''
+ pass
-class MenuPageInRoutes(ServerError):
+class AutoconfigureConflict(ServerInfo):
def __init__(self):
super().__init__(
- 'The pgwui_menu in the pgwui.routes setting is ignored '
- 'and the pgwui.menu_page setting used instead')
+ 'Autoconfigure is True and there is a pyramid.include setting')
class BadSettingsAbort(ServerError):
from . import exceptions as server_ex
from . import checkset
from pgwui_common import exceptions as common_ex
+from pgwui_common import routes
from pgwui_common import plugin
# Constants
'default_db',
'dry_run',
'route_prefix',
- 'routes',
'validate_hmac',
'autoconfigure',
])
# All the multi-valued settings recognized by PGWUI_Server/Core
MULTI_SETTINGS = set(
- ['home_page',
+ ['routes',
+ 'home_page',
'menu_page',
])
exit_reporting_errors(errors)
-def add_routes(config, settings):
- '''Add routes found in pgwui.routes setting
- '''
- pgwui_settings = settings['pgwui']
- if 'routes' in pgwui_settings:
- menu_page = 'menu_page' in pgwui_settings
- routes = parse_assignments(pgwui_settings['routes'])
- for name, route in routes:
- if menu_page and name == 'pgwui_menu':
- log.info(server_ex.MenuPageInRoutes())
- else:
- config.add_route(name, route)
-
-
def autoconfigurable_components(settings, components):
'''Automatic pgwui component discovery
'''
for component in components_to_config:
log.debug('Autoconfiguring PGWUI component: {}'.format(component))
config.include(component)
- add_routes(config, settings)
+ routes.add_routes(config, settings)
log.debug('Done autoconfiguring PGWUI components')
return config
import pytest
import sys
-import pyramid.testing
-
import pgwui_common.exceptions as common_ex
import pgwui_common.plugin
+import pgwui_common.routes
# Use as a regular module, not a plugin, so lint checks work
from pgwui_testing import testing
pass
-mock_add_route = testing.instance_method_mock_fixture('add_route')
-
mock_find_pgwui_components = testing.make_mock_fixture(
pgwui_common.plugin, 'find_pgwui_components')
mock_find_pgwui_check_settings = testing.make_mock_fixture(
mock_validate_hmac = testing.make_mock_fixture(
pgwui_server.checkset, 'validate_hmac')
+mock_add_routes = testing.make_mock_fixture(
+ pgwui_common.routes, 'add_routes')
+
# Unit tests
pgwui_server, 'autoconfigurable_components')
-# add_routes()
-
-@pytest.mark.unittest
-def test_add_routes_empty(mock_add_route):
- '''When there is no pgwui.routes setting nothing gets added'''
- with pyramid.testing.testConfig() as config:
- mocked_add_route = mock_add_route(config)
- pgwui_server.add_routes(config, {'pgwui': {}})
-
- assert not mocked_add_route.called
-
-
-@pytest.mark.unittest
-def test_add_routes_notempty(mock_add_route, mock_parse_assignments):
- '''When there is a pgwui.routes setting config.add_route() is called
- for each route'''
- test_routes = [('name1', 'route1'),
- ('name2', 'route2')]
- mock_parse_assignments.return_value = test_routes
- with pyramid.testing.testConfig() as config:
- mocked_add_route = mock_add_route(config)
- pgwui_server.add_routes(config, {'pgwui': {'routes': ''}})
-
- assert mocked_add_route.call_count == len(test_routes)
-
-
-@pytest.mark.unittest
-def test_add_routes_menu(mock_add_route, mock_parse_assignments, caplog):
- '''When there is a a route for pgwui_menu, but there is a menu_page
- setting, no route is added and an INFO message is logged
- '''
- caplog.set_level(logging.DEBUG)
-
- test_routes = [('pgwui_menu', 'notused')]
- mock_parse_assignments.return_value = test_routes
- with pyramid.testing.testConfig() as config:
- mocked_add_route = mock_add_route(config)
- pgwui_server.add_routes(config, {'pgwui': {'routes': 'notused',
- 'menu_page': 'anything'}})
-
- mocked_add_route.assert_not_called()
-
- logs = caplog.record_tuples
- assert len(logs) == 1
- assert logs[0][1] == logging.INFO
-
-
-mock_add_routes = testing.make_mock_fixture(
- pgwui_server, 'add_routes')
-
-
# apply_component_defaults()
@pytest.mark.unittest