return result
-def dot_to_multiline_setting(errors, settings, key, pgwui_key):
+def dot_to_multiline_setting(settings, key, pgwui_key):
'''Put a multi-line setting into its own dict,
adding to what's already there
'''
multi_setting = settings['pgwui'].setdefault(pgwui_key, dict())
try:
multi_setting.update(dict(parse_assignments(settings[key])))
- except server_ex.MissingEqualError as ex:
- errors.append(server_ex.BadValueError(f'pgwui:{pgwui_key}', ex))
- del settings[key]
+ except server_ex.MissingEqualError:
+ raise
+ finally:
+ del settings[key]
def component_setting_into_dict(
errors, component_checkers, key, settings, component):
'''Put a component's settings in its own dict and validate them
'''
- comp_settings = dot_to_multiline_setting(errors, settings, key, component)
+ try:
+ dot_to_multiline_setting(settings, key, component)
+ except server_ex.MissingEqualError as ex:
+ # Couldn't get the settings because there's no "="
+ errors.append(server_ex.BadValueError(f'pgwui:{component}', ex))
+ return
if component in component_checkers:
errors.extend(
- component_checkers[component](comp_settings))
+ component_checkers[component](settings['pgwui'][component]))
def setting_into_dict(
if new_key in SETTINGS:
dot_to_dict(settings, key, new_key)
elif new_key in MULTI_SETTINGS:
- dot_to_multiline_setting(errors, settings, key, new_key)
+ try:
+ dot_to_multiline_setting(settings, key, new_key)
+ except server_ex.MissingEqualError as ex:
+ errors.append(
+ server_ex.BadValueError(f'pgwui:{new_key}', ex))
else:
errors.append(common_ex.UnknownSettingKeyError(key))
def test_dot_to_multiline_setting_new(mock_parse_assignments):
'''Adds a new dict and puts the settings in it
'''
- errors = []
comp_settings = {'foo': 'foo', 'bar': 'bar'}
component = 'pgwui_component'
key = 'pgwui.' + component
expected = {'pgwui': {component: comp_settings}}
mock_parse_assignments.return_value = comp_settings
- pgwui_server.dot_to_multiline_setting(
- errors, settings, key, component)
+ pgwui_server.dot_to_multiline_setting(settings, key, component)
assert settings == expected
- assert errors == []
def test_dot_to_multiline_setting_old(mock_parse_assignments):
'''Extends an existing dict in the settings
'''
- errors = []
comp_settings = {'foo': 'foo', 'bar': 'bar'}
component = 'pgwui_component'
key = 'pgwui.' + component
{component: {'foo': 'foo', 'bar': 'bar', 'baz': 'baz'}}}
mock_parse_assignments.return_value = comp_settings
- pgwui_server.dot_to_multiline_setting(
- errors, settings, key, component)
+ pgwui_server.dot_to_multiline_setting(settings, key, component)
assert settings == expected
- assert errors == []
def test_dot_to_multiline_setting_bad(mock_parse_assignments):
'''When the value is bad we get the expected error
'''
- errors = []
component = 'pgwui_component'
key = 'pgwui.' + component
settings = {'pgwui': {},
key: 'ignored'}
mock_parse_assignments.side_effect = server_ex.MissingEqualError('text')
- pgwui_server.dot_to_multiline_setting(
- errors, settings, key, component)
+ with pytest.raises(server_ex.MissingEqualError):
+ pgwui_server.dot_to_multiline_setting(settings, key, component)
- assert len(errors) == 1
- assert isinstance(errors[0], server_ex.BadValueError)
+ assert True
mock_dot_to_multiline_setting = testing.make_mock_fixture(
pgwui_server.component_setting_into_dict(
errors, {'pgwui_component': lambda settings: new_errors},
- 'pgwui.pgwui_component', None, 'pgwui_component')
+ 'pgwui.pgwui_component', {'pgwui': {'pgwui_component': {}}},
+ 'pgwui_component')
assert errors == expected
+def test_component_setting_into_dict_nosettings(
+ mock_dot_to_multiline_setting):
+ '''When there's no settings due to a syntax error the right error
+ is appended to the errors
+ '''
+ errors = []
+ mock_dot_to_multiline_setting.side_effect = server_ex.MissingEqualError(0)
+
+ pgwui_server.component_setting_into_dict(
+ errors, {}, 'pgwui.pgwui_component', None, 'pgwui_component')
+
+ assert len(errors) == 1
+ assert isinstance(errors[0], server_ex.BadValueError)
+
+
mock_component_setting_into_dict = testing.make_mock_fixture(
pgwui_server, 'component_setting_into_dict')
assert errors == []
+def test_setting_into_dict_bad_assignment(
+ mock_parse_assignments,
+ mock_component_setting_into_dict,
+ mock_dot_to_dict,
+ mock_dot_to_multiline_setting):
+ '''Delivers an error on a setting that has no "="
+ '''
+ errors = []
+ mock_dot_to_multiline_setting.side_effect = server_ex.MissingEqualError(0)
+
+ pgwui_server.setting_into_dict(
+ errors, [], {}, 'pgwui.home_page', {})
+
+ mock_component_setting_into_dict.assert_not_called()
+ mock_dot_to_dict.assert_not_called()
+ mock_dot_to_multiline_setting.assert_called_once()
+
+ assert len(errors) == 1
+ assert isinstance(errors[0], server_ex.BadValueError)
+
+
mock_setting_into_dict = testing.make_mock_fixture(
pgwui_server, 'setting_into_dict')