From f4a52cac49500e101431a88b079633ebb86d38cd Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Sun, 15 Nov 2020 13:27:52 -0600 Subject: [PATCH] Check settings --- setup.py | 6 ++- src/pgwui_logout/check_settings.py | 48 ++++++++++++++++++ tests/test_check_settings.py | 78 ++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 src/pgwui_logout/check_settings.py create mode 100644 tests/test_check_settings.py diff --git a/setup.py b/setup.py index cd98fa3..34cef44 100644 --- a/setup.py +++ b/setup.py @@ -168,5 +168,9 @@ setup( # pip to create the appropriate form of executable for the target platform. # # Setup an entry point to support PGWUI autoconfigure discovery. - entry_points={'pgwui.components': '.pgwui_logout = pgwui_logout'} + entry_points={ + 'pgwui.components': '.pgwui_logout = pgwui_logout', + 'pgwui.check_settings': + '.pgwui_logout = pgwui_logout.check_settings:check_settings' + } ) diff --git a/src/pgwui_logout/check_settings.py b/src/pgwui_logout/check_settings.py new file mode 100644 index 0000000..368dba2 --- /dev/null +++ b/src/pgwui_logout/check_settings.py @@ -0,0 +1,48 @@ +# Copyright (C) 2020 The Meme Factory, Inc. http://www.karlpinc.com/ + +# This file is part of PGWUI_Logout. +# +# 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 +# . +# + +# Karl O. Pinc + +from pgwui_common import checkset + + +PGWUI_COMPONENT = 'pgwui_logout' +LOGOUT_SETTINGS = ['menu_label', + ] +REQUIRED_SETTINGS = [] +BOOLEAN_SETTINGS = [] + + +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, LOGOUT_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)) + + return errors diff --git a/tests/test_check_settings.py b/tests/test_check_settings.py new file mode 100644 index 0000000..4260a70 --- /dev/null +++ b/tests/test_check_settings.py @@ -0,0 +1,78 @@ +# Copyright (C) 2020 The Meme Factory, Inc. http://www.karlpinc.com/ + +# This file is part of Pgwui_Logout. +# +# 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 +# . +# + +# Karl O. Pinc + +import pgwui_logout.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_logout has a pgwui.check_settings entry point + ''' + assert (pgwui_check_settings_entry_point('pgwui_logout.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') + + +# check_settings() + +def test_check_settings(mock_unknown_settings, + mock_require_settings, + mock_boolean_settings): + '''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 + + assert result.sort() == (unknown_retval + + require_retval + + boolean_retval).sort() -- 2.34.1