Check settings
authorKarl O. Pinc <kop@karlpinc.com>
Sun, 15 Nov 2020 19:27:52 +0000 (13:27 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Sun, 15 Nov 2020 19:28:06 +0000 (13:28 -0600)
setup.py
src/pgwui_logout/check_settings.py [new file with mode: 0644]
tests/test_check_settings.py [new file with mode: 0644]

index cd98fa3a1a2e40eb97ef4524eeacafce2f359ef9..34cef446e83102e73862847481140badc2cd2fb2 100644 (file)
--- 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 (file)
index 0000000..368dba2
--- /dev/null
@@ -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
+# <http://www.gnu.org/licenses/>.
+#
+
+# Karl O. Pinc <kop@karlpinc.com>
+
+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 (file)
index 0000000..4260a70
--- /dev/null
@@ -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
+# <http://www.gnu.org/licenses/>.
+#
+
+# Karl O. Pinc <kop@karlpinc.com>
+
+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()