import pgwui_server.pgwui_server as pgwui_server
-# Constants
-
-TEST_SETTINGS = {
- 'pgwui.validate_hmac': 'False',
- 'pgwui.dry_run': 'False',
-}
+# Mark all tests with "unittest"
+pytestmark = pytest.mark.unittest
# Use contextlib.AbstractContextManager for Python >= 3.6
# dot_to_multiline_setting()
-@pytest.mark.unittest
def test_dot_to_multiline_setting_new(mock_parse_assignments):
'''Adds a new dict and puts the settings in it
'''
assert settings == expected
-@pytest.mark.unittest
def test_dot_to_multiline_setting_old(mock_parse_assignments):
'''Extends an existing dict in the settings
'''
# component_setting_into_dict()
-@pytest.mark.unittest
def test_component_setting_into_dict_no_checker(
mock_dot_to_multiline_setting):
'''When there's no checker nothing is done
assert errors == []
-@pytest.mark.unittest
def test_component_setting_into_dict_checker(
mock_dot_to_multiline_setting):
'''When there's a checker its result is appended to the errors
# dot_to_dict()
-@pytest.mark.unittest
def test_dot_to_dict():
'''Removes pgwui.* settings, replaces them with a dict entry
'''
# parse_multiline_assigments()
-@pytest.mark.unittest
def test_parse_multiline_assignments_str():
'''Appends key/value string tuples and when there's no "=",
and more than just whitespace, a list is the result
# parse_assignments()
-@pytest.mark.unittest
def test_parse_assignments_str(mock_parse_multiline_assignments):
'''Calls parse_multiline_assignments'''
lines = ('key1 = value1\n' # whitespace around = is ignored
mock_parse_multiline_assignments.assert_called_once()
-@pytest.mark.unittest
def test_parse_assignments_dict(mock_parse_multiline_assignments):
'''Returns key value tuples.
'''
# setting_into_dict()
-@pytest.mark.unittest
def test_setting_into_dict_unknown(
mock_component_setting_into_dict,
mock_dot_to_dict,
assert errors == []
-@pytest.mark.unittest
def test_setting_into_dict_bad(
mock_parse_assignments,
mock_component_setting_into_dict,
assert isinstance(errors[0], common_ex.UnknownSettingKeyError)
-@pytest.mark.unittest
def test_setting_into_dict_good(
mock_component_setting_into_dict,
mock_dot_to_dict,
assert errors == []
-@pytest.mark.unittest
def test_setting_into_dict_multiline(
mock_component_setting_into_dict,
mock_dot_to_dict,
assert errors == []
-@pytest.mark.unittest
def test_setting_into_dict_plugin_component(
mock_component_setting_into_dict,
mock_dot_to_dict,
# dictify_settings()
-@pytest.mark.unittest
def test_dictify_settings(mock_find_pgwui_check_settings,
mock_setting_into_dict,
mock_validate_setting_values,
return run
-@pytest.mark.unittest
def test_exit_reporting_errors_logged(
assert_exit1, monkeypatch, caplog, capsys):
'''All errors are logged at ERROR, and a extra one at CRITICAL
assert levels[-1] == logging.CRITICAL
-@pytest.mark.unittest
def test_exit_reporting_errors_printed(
assert_exit1, monkeypatch, capsys):
'''First and last (the extra) errors are printed on stderr
# add_default_settings()
-@pytest.mark.unittest
def test_add_default_settings():
'''The default settings are added
'''
# exit_on_invalid_settings()
-@pytest.mark.unittest
def test_exit_on_invalid_settings_invalid(
monkeypatch,
mock_add_default_settings, mock_dictify_settings,
assert mock_exit_reporting_errors.called
-@pytest.mark.unittest
def test_exit_on_invalid_settings_valid(
mock_add_default_settings, mock_dictify_settings,
mock_exit_reporting_errors):
# autoconfigurable_components()
-@pytest.mark.unittest
def test_autoconfiguable_components_no_autoconfig():
'''When the settings have no pgwui.autoconfigure return an empty list
'''
assert result == []
-@pytest.mark.unittest
def test_autoconfigurable_components_log_info(caplog):
'''When pyramid.include is in the settings an INFO message is logged
'''
assert level == logging.INFO
-@pytest.mark.unittest
def test_autoconfigurable_components_components_returned():
'''The suppiled components are returned when autoconfigure is True
'''
# apply_component_defaults()
-@pytest.mark.unittest
def test_apply_component_defaults(monkeypatch, caplog,
mock_autoconfigurable_components,
mock_add_routes):
# pgwui_server_config()
-@pytest.mark.unittest
def test_pgwui_server_config(
mock_find_pgwui_components,
mock_apply_component_defaults, mock_exit_on_invalid_settings):
# main()
-@pytest.mark.unittest
def test_main(monkeypatch):
'''Returns a wsgi app'''
monkeypatch.setattr(pgwui_server, 'pgwui_server_config',
result = pgwui_server.main({})
assert result == 'wsgi_app'
-
-
-# Integration tests
-@pytest.mark.integrationtest
-def test_main_integrated():
- '''Does not raise errors or warnings'''
- pgwui_server.main({}, **TEST_SETTINGS)
--- /dev/null
+# Copyright (C) 2018, 2019, 2020 The Meme Factory, Inc.
+# http://www.karlpinc.com/
+
+# This file is part of PGWUI_Server.
+#
+# 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 pytest
+
+import pgwui_server.pgwui_server as pgwui_server
+
+
+# Mark all tests as "integrationtest"
+pytestmark = pytest.mark.integrationtest
+
+# Constants
+
+TEST_SETTINGS = {
+ 'pgwui.validate_hmac': 'False',
+ 'pgwui.dry_run': 'False',
+}
+
+
+# Integration tests
+def test_main_integrated():
+ '''Does not raise errors or warnings'''
+ pgwui_server.main({}, **TEST_SETTINGS)