--- /dev/null
+# Copyright (C) 2020 The Meme Factory, Inc. http://www.karlpinc.com/
+
+# This file is part of PGWUI_Upload.
+#
+# 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>
+
+from pgwui_common import exceptions as common_ex
+from pgwui_common import checkset
+
+
+PGWUI_COMPONENT = 'pgwui_upload'
+UPLOAD_SETTINGS = ['menu_label',
+ 'literal_column_headings',
+ ]
+REQUIRED_SETTINGS = []
+BOOLEAN_SETTINGS = []
+
+
+class UploadError(common_ex.Error):
+ pass
+
+
+class BadLiteralColumnHeadingsError(UploadError):
+ def __init__(self, value):
+ super().__init__(
+ 'The "pgwui.literal_column_headings" PGWUI setting must be'
+ '"on", "off", "ask", or not present')
+
+
+def validate_literal_column_headings(errors, settings):
+ '''Make sure the values are those allowed
+ '''
+ value = settings.get('literal_column_headings')
+ if value is None:
+ return
+ if value not in ('on', 'off', 'ask'):
+ errors.append(BadLiteralColumnHeadingsError(value))
+
+
+def check_settings(component_config):
+ '''Check that all pgwui_upload specific settings are good.
+ This includes:
+ checking for unknown settings
+ checking for missing required settings
+ checking the boolean settings
+ checking that the values of other settings are valid
+ '''
+ errors = []
+ errors.extend(checkset.unknown_settings(
+ PGWUI_COMPONENT, UPLOAD_SETTINGS, component_config))
+ errors.extend(checkset.require_settings(
+ PGWUI_COMPONENT, REQUIRED_SETTINGS, component_config))
+ errors.extend(checkset.boolean_settings(
+ PGWUI_COMPONENT, BOOLEAN_SETTINGS, component_config))
+ validate_literal_column_headings(errors, component_config)
+
+ return errors
--- /dev/null
+# Copyright (C) 2020 The Meme Factory, Inc. http://www.karlpinc.com/
+
+# This file is part of PGWUI_Upload.
+#
+# 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 pgwui_upload.check_settings as check_settings
+
+from pgwui_common import checkset
+from pgwui_testing import testing
+
+# Activiate our pytest plugin
+pytest_plugins = ("pgwui",)
+
+
+# Module packaging test
+
+def test_check_setting_is_pgwui_check_settings(
+ pgwui_check_settings_entry_point):
+ '''Ensure that pgwui_upload has a pgwui.check_settings entry point
+ '''
+ assert (pgwui_check_settings_entry_point('pgwui_upload.check_settings')
+ is True)
+
+
+# Mocks
+
+mock_unknown_settings = testing.make_mock_fixture(
+ checkset, 'unknown_settings')
+
+mock_require_settings = testing.make_mock_fixture(
+ checkset, 'require_settings')
+
+mock_boolean_settings = testing.make_mock_fixture(
+ checkset, 'boolean_settings')
+
+
+# validate_literal_column_headings()
+
+def test_validate_literal_column_headings_nosetting():
+ '''No error is delivered when there's no setting'''
+ errors = []
+ check_settings.validate_literal_column_headings(errors, {})
+
+ assert errors == []
+
+
+def test_validate_literal_column_headings_on():
+ '''No error is delivered when the setting is "on"'''
+ errors = []
+ check_settings.validate_literal_column_headings(
+ errors, {'literal_column_headings': 'on'})
+
+ assert errors == []
+
+
+def test_validate_literal_column_headings_off():
+ '''No error is delivered when the setting is "off"'''
+ errors = []
+ check_settings.validate_literal_column_headings(
+ errors, {'literal_column_headings': 'off'})
+
+ assert errors == []
+
+
+def test_validate_literal_column_headings_ask():
+ '''No error is delivered when the setting is "ask"'''
+ errors = []
+ check_settings.validate_literal_column_headings(
+ errors, {'literal_column_headings': 'ask'})
+
+ assert errors == []
+
+
+def test_validate_literal_column_headings_bad():
+ '''delivers an error when given a bad value'''
+ errors = []
+ check_settings.validate_literal_column_headings(
+ errors, {'literal_column_headings': 'bad'})
+
+ assert errors
+ assert isinstance(
+ errors[0], check_settings.BadLiteralColumnHeadingsError)
+
+
+literal_err = 'literal column headings error'
+mock_validate_literal_column_headings = testing.make_mock_fixture(
+ check_settings, 'validate_literal_column_headings',
+ wraps=lambda errors, *args: errors.append(literal_err))
+
+
+# check_settings()
+
+def test_check_settings(mock_unknown_settings,
+ mock_require_settings,
+ mock_boolean_settings,
+ mock_validate_literal_column_headings):
+ '''The setting checking functions are called once, the check_settings()
+ call returns all the errors from each mock.
+ '''
+
+ unknown_retval = ['unk err']
+ require_retval = ['req err']
+ boolean_retval = ['bool err']
+
+ mock_unknown_settings.return_value = unknown_retval
+ mock_require_settings.return_value = require_retval
+ mock_boolean_settings.return_value = boolean_retval
+
+ result = check_settings.check_settings({})
+
+ mock_unknown_settings.assert_called_once
+ mock_require_settings.assert_called_once
+ mock_boolean_settings.assert_called_once
+ mock_validate_literal_column_headings.assert_called_once
+
+ assert result.sort() == ([literal_err]
+ + unknown_retval
+ + require_retval
+ + boolean_retval).sort()