diff --git a/tests/test_config.py b/tests/test_config.py index c094f6a21..c089a49a2 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -122,6 +122,9 @@ def test_bool_validation(): assert c.preload_app is False pytest.raises(ValueError, c.set, "preload_app", "zilch") pytest.raises(TypeError, c.set, "preload_app", 4) + pytest.raises(TypeError, c.set, "preload_app", []) + pytest.raises(TypeError, c.set, "preload_app", lambda x: True) + pytest.raises(TypeError, c.set, "preload_app", tuple()) def test_pos_int_validation(): @@ -159,6 +162,17 @@ def test_str_to_list_validation(): pytest.raises(TypeError, c.set, "forwarded_allow_ips", 1) +def test_dict_validation(): + c = config.Config() + c.set("secure_scheme_headers", {"X-FORWARDED_PROTO": "ssl"}) + assert c.secure_scheme_headers + pytest.raises(TypeError, c.set, "secure_scheme_headers", set()) + pytest.raises(TypeError, c.set, "secure_scheme_headers", lambda x: True) + pytest.raises(TypeError, c.set, "secure_scheme_headers", []) + pytest.raises(TypeError, c.set, "secure_scheme_headers", tuple()) + pytest.raises(TypeError, c.set, "secure_scheme_headers", (1,2,3)) + + def test_callable_validation(): c = config.Config() def func(a, b): @@ -167,6 +181,9 @@ def func(a, b): assert c.pre_fork == func pytest.raises(TypeError, c.set, "pre_fork", 1) pytest.raises(TypeError, c.set, "pre_fork", lambda x: True) + pytest.raises(TypeError, c.set, "pre_fork", []) + pytest.raises(TypeError, c.set, "pre_fork", tuple()) + pytest.raises(TypeError, c.set, "pre_fork", (1,2,3)) def test_reload_engine_validation(): @@ -178,6 +195,10 @@ def test_reload_engine_validation(): assert c.reload_engine == 'poll' pytest.raises(ConfigError, c.set, "reload_engine", "invalid") + pytest.raises(ConfigError, c.set, "reload_engine", tuple()) + pytest.raises(ConfigError, c.set, "reload_engine", (1,2,3)) + pytest.raises(ConfigError, c.set, "reload_engine", []) + pytest.raises(ConfigError, c.set, "reload_engine", 0) def test_callable_validation_for_string():