Mark unit and integration tests
authorKarl O. Pinc <kop@karlpinc.com>
Tue, 24 Nov 2020 17:15:45 +0000 (11:15 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Tue, 24 Nov 2020 18:08:00 +0000 (12:08 -0600)
tests/test_checkset.py
tests/test_pgwui_server.py

index fa3509d0c5e844e19e11b7c278ab376498a65cd1..58be20b45ea229de5a8442a13e03e077b5800572 100644 (file)
@@ -20,6 +20,7 @@
 
 # Karl O. Pinc <kop@karlpinc.com>
 
+import pytest
 
 import pgwui_common.exceptions as common_ex
 from pgwui_server import checkset
@@ -30,6 +31,7 @@ from pgwui_testing import testing
 
 # key_to_ini()
 
+@pytest.mark.unittest
 def test_key_to_ini():
     '''The return value is as expected
     '''
@@ -45,6 +47,7 @@ mock_key_to_ini = testing.make_mock_fixture(
 
 # require_setting()
 
+@pytest.mark.unittest
 def test_require_setting_missing():
     '''Deliver exception when a required setting is missing'''
     errors = []
@@ -54,6 +57,7 @@ def test_require_setting_missing():
     assert isinstance(errors[0], common_ex.MissingSettingError)
 
 
+@pytest.mark.unittest
 def test_require_setting_present():
     '''Does nothing when a required setting is present'''
     errors = []
@@ -68,6 +72,7 @@ mock_require_setting = testing.make_mock_fixture(
 
 # boolean_setting()
 
+@pytest.mark.unittest
 def test_boolean_setting_missing():
     '''Does nothing when the setting is not in the settings'''
     errors = []
@@ -76,6 +81,7 @@ def test_boolean_setting_missing():
     assert errors == []
 
 
+@pytest.mark.unittest
 def test_boolean_setting_true():
     '''Does nothing when the setting is "True"'''
     errors = []
@@ -84,6 +90,7 @@ def test_boolean_setting_true():
     assert errors == []
 
 
+@pytest.mark.unittest
 def test_boolean_setting_false():
     '''Does nothing when the setting is "False"'''
     errors = []
@@ -92,6 +99,7 @@ def test_boolean_setting_false():
     assert errors == []
 
 
+@pytest.mark.unittest
 def test_boolean_setting_notboolean():
     '''Deliver an exception when the setting does not evaluate to a boolean'''
     errors = []
@@ -101,6 +109,7 @@ def test_boolean_setting_notboolean():
     assert isinstance(errors[0], common_ex.NotBooleanSettingError)
 
 
+@pytest.mark.unittest
 def test_boolean_setting_notparsable():
     '''Deliver an exception when the setting does not evaluate to a
     boolean because it is not parseable
@@ -118,6 +127,7 @@ mock_boolean_setting = testing.make_mock_fixture(
 
 # validate_setting_values()
 
+@pytest.mark.unittest
 def test_validate_setting_values(mock_require_setting, mock_boolean_setting):
     '''Calls require_setting() and boolean_setting()'''
 
@@ -133,11 +143,13 @@ mock_validate_setting_values = testing.make_mock_fixture(
 
 # do_validate_hmac()
 
+@pytest.mark.unittest
 def test_do_validate_hmac_none():
     '''pgwui.validate_hmac defaults to True'''
     assert checkset.do_validate_hmac({'pgwui': {}}) is True
 
 
+@pytest.mark.unittest
 def test_do_validate_hmac_True():
     '''Require hmac validation when pgwui.validate_hmac is True'''
     result = checkset.do_validate_hmac(
@@ -145,6 +157,7 @@ def test_do_validate_hmac_True():
     assert result is True
 
 
+@pytest.mark.unittest
 def test_do_validate_hmac_False():
     '''No hmac validation when pgwui.validate_hmac is False'''
     result = checkset.do_validate_hmac(
@@ -158,6 +171,7 @@ mock_do_validate_hmac = testing.make_mock_fixture(
 
 # validate_hmac()
 
+@pytest.mark.unittest
 def test_validate_hmac_unvalidated(mock_do_validate_hmac):
     '''No error is returned when hmac validation is off'''
     mock_do_validate_hmac.return_value = False
@@ -167,6 +181,7 @@ def test_validate_hmac_unvalidated(mock_do_validate_hmac):
     assert errors == []
 
 
+@pytest.mark.unittest
 def test_validate_hmac_success(mock_do_validate_hmac):
     '''No error is returned when hmac is validated an the right length'''
     mock_do_validate_hmac.return_value = True
@@ -177,6 +192,7 @@ def test_validate_hmac_success(mock_do_validate_hmac):
     assert errors == []
 
 
+@pytest.mark.unittest
 def test_validate_hmac_missing(mock_do_validate_hmac):
     '''Deliver error when hmac is validated and missing'''
     mock_do_validate_hmac.return_value = True
@@ -187,6 +203,7 @@ def test_validate_hmac_missing(mock_do_validate_hmac):
     assert isinstance(errors[0], server_ex.NoHMACError)
 
 
+@pytest.mark.unittest
 def test_validate_hmac_length(mock_do_validate_hmac):
     '''Deliver error when hmac is validated and the wrong length'''
     mock_do_validate_hmac.return_value = True
index 640202a69d9f3de5f28d85cc391c169aab0bdfe8..eb958ef9b1e82c0828bf22c374468aee4a980872 100644 (file)
@@ -80,6 +80,7 @@ mock_validate_hmac = testing.make_mock_fixture(
 
 # dot_to_component_settings()
 
+@pytest.mark.unittest
 def test_dot_to_component_settings_new():
     '''Adds a new dict and puts the settings in it
     '''
@@ -96,6 +97,7 @@ def test_dot_to_component_settings_new():
     assert settings == expected
 
 
+@pytest.mark.unittest
 def test_dot_to_component_settings_old():
     '''Extends an existing dict in the settings
     '''
@@ -119,6 +121,7 @@ mock_dot_to_component_setting = testing.make_mock_fixture(
 
 # component_setting_into_dict()
 
+@pytest.mark.unittest
 def test_component_setting_into_dict_no_checker(
         mock_dot_to_component_setting):
     '''When there's no checker nothing is done
@@ -131,6 +134,7 @@ def test_component_setting_into_dict_no_checker(
     assert errors == []
 
 
+@pytest.mark.unittest
 def test_component_setting_into_dict_checker(
         mock_dot_to_component_setting):
     '''When there's a checker its result is appended to the errors
@@ -153,6 +157,7 @@ mock_component_setting_into_dict = testing.make_mock_fixture(
 
 # dot_to_dict()
 
+@pytest.mark.unittest
 def test_dot_to_dict():
     '''Removes pgwui.* settings, replaces them with a dict entry
     '''
@@ -176,6 +181,7 @@ mock_dot_to_dict = testing.make_mock_fixture(
 # 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
@@ -200,6 +206,7 @@ mock_parse_multiline_assignments = testing.make_mock_fixture(
 
 # 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
@@ -212,6 +219,7 @@ def test_parse_assignments_str(mock_parse_multiline_assignments):
     mock_parse_multiline_assignments.assert_called_once()
 
 
+@pytest.mark.unittest
 def test_parse_assignments_dict(mock_parse_multiline_assignments):
     '''Returns key value tuples.
     '''
@@ -230,6 +238,7 @@ mock_parse_assignments = testing.make_mock_fixture(
 
 # setting_into_dict()
 
+@pytest.mark.unittest
 def test_setting_into_dict_unknown(
         mock_parse_assignments,
         mock_component_setting_into_dict,
@@ -241,6 +250,7 @@ def test_setting_into_dict_unknown(
     assert errors == []
 
 
+@pytest.mark.unittest
 def test_setting_into_dict_bad(
         mock_parse_assignments,
         mock_component_setting_into_dict,
@@ -255,6 +265,7 @@ def test_setting_into_dict_bad(
     assert isinstance(errors[0], common_ex.UnknownSettingKeyError)
 
 
+@pytest.mark.unittest
 def test_setting_into_dict_good(
         mock_parse_assignments,
         mock_component_setting_into_dict,
@@ -269,6 +280,7 @@ def test_setting_into_dict_good(
     assert errors == []
 
 
+@pytest.mark.unittest
 def test_setting_into_dict_plugin_component(
         mock_parse_assignments,
         mock_component_setting_into_dict,
@@ -295,6 +307,7 @@ mock_setting_into_dict = testing.make_mock_fixture(
 
 # dictify_settings()
 
+@pytest.mark.unittest
 def test_dictify_settings(mock_find_pgwui_check_settings,
                           mock_setting_into_dict,
                           mock_validate_setting_values,
@@ -339,6 +352,7 @@ def assert_exit1():
     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
@@ -358,6 +372,7 @@ def test_exit_reporting_errors_logged(
     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
@@ -382,6 +397,7 @@ mock_exit_reporting_errors = testing.make_mock_fixture(
 
 # exit_on_invalid_settings()
 
+@pytest.mark.unittest
 def test_exit_on_invalid_settings_invalid(monkeypatch,
                                           mock_exit_reporting_errors):
     '''Calls dictify_settings and exit_reporting_errors() when
@@ -398,6 +414,7 @@ def test_exit_on_invalid_settings_invalid(monkeypatch,
     assert mock_exit_reporting_errors.called
 
 
+@pytest.mark.unittest
 def test_exit_on_invalid_settings_valid(mock_dictify_settings):
     '''Returns, without exiting, when all settings are valid
     '''
@@ -412,6 +429,7 @@ mock_exit_on_invalid_settings = testing.make_mock_fixture(
 
 # autoconfigurable_components()
 
+@pytest.mark.unittest
 def test_autoconfiguable_components_no_autoconfig():
     '''When the settings have no pgwui.autoconfigure return an empty list
     '''
@@ -423,6 +441,7 @@ def test_autoconfiguable_components_no_autoconfig():
     assert result == []
 
 
+@pytest.mark.unittest
 def test_autoconfigurable_components_log_info(caplog):
     '''When pyramid.include is in the settings an INFO message is logged
     '''
@@ -441,6 +460,7 @@ def test_autoconfigurable_components_log_info(caplog):
     assert level == logging.INFO
 
 
+@pytest.mark.unittest
 def test_autoconfigurable_components_components_returned():
     '''The suppiled components are returned when autoconfigure is True
     '''
@@ -458,6 +478,7 @@ mock_autoconfigurable_components = testing.make_mock_fixture(
 
 # add_routes()
 
+@pytest.mark.unittest
 def test_add_routes_empty(mock_add_route):
     '''When there is no pgwui.routes setting nothing gets added'''
     with pyramid.testing.testConfig() as config:
@@ -467,6 +488,7 @@ def test_add_routes_empty(mock_add_route):
     assert not mocked_add_route.called
 
 
+@pytest.mark.unittest
 def test_add_routes_notempty(mock_add_route, mock_parse_assignments):
     '''When there is a pgwui.routes setting config.add_route() is called
     for each route'''
@@ -487,6 +509,7 @@ mock_add_routes = testing.make_mock_fixture(
 # apply_component_defaults()
 
 
+@pytest.mark.unittest
 def test_apply_component_defaults(monkeypatch, caplog,
                                   mock_autoconfigurable_components,
                                   mock_add_routes):
@@ -518,6 +541,7 @@ mock_apply_component_defaults = testing.make_mock_fixture(
 
 # pgwui_server_config()
 
+@pytest.mark.unittest
 def test_pgwui_server_config(
         mock_find_pgwui_components,
         mock_apply_component_defaults, mock_exit_on_invalid_settings):
@@ -531,6 +555,7 @@ def test_pgwui_server_config(
 
 
 # main()
+@pytest.mark.unittest
 def test_main(monkeypatch):
     '''Returns a wsgi app'''
     monkeypatch.setattr(pgwui_server, 'pgwui_server_config',
@@ -541,6 +566,7 @@ def test_main(monkeypatch):
 
 
 # Integration tests
+@pytest.mark.integrationtest
 def test_main_integrated():
     '''Does not raise errors or warnings'''
     pgwui_server.main({}, **TEST_SETTINGS)