diff --git a/canaille/__init__.py b/canaille/__init__.py index 865bf8ec..c8667fb4 100644 --- a/canaille/__init__.py +++ b/canaille/__init__.py @@ -21,7 +21,6 @@ def setup_config(app, config=None, validate=True): import canaille.configuration import canaille.installation - dir_path = os.path.dirname(os.path.realpath(__file__)) app.config.from_mapping( { "SESSION_COOKIE_NAME": "canaille", @@ -33,10 +32,6 @@ def setup_config(app, config=None, validate=True): app.config.from_mapping(config) elif "CONFIG" in os.environ: app.config.from_mapping(toml.load(os.environ.get("CONFIG"))) - elif os.path.exists(os.path.join(dir_path, "conf", "config.toml")): - app.config.from_mapping( - toml.load(os.path.join(dir_path, "conf", "config.toml")) - ) else: raise Exception( "No configuration file found. " diff --git a/tests/test_flaskutils.py b/tests/test_flaskutils.py index 6883ef97..0dcf5973 100644 --- a/tests/test_flaskutils.py +++ b/tests/test_flaskutils.py @@ -1,6 +1,8 @@ import os import ldap +import pytest +import toml from canaille import create_app from canaille.flaskutils import set_parameter_in_url_query from canaille.installation import setup_ldap_tree @@ -26,6 +28,26 @@ def test_set_parameter_in_url_query(): ) +def test_environment_configuration(slapd_server, configuration, tmp_path): + config_path = os.path.join(tmp_path, "config.toml") + with open(config_path, "w") as fd: + toml.dump(configuration, fd) + + os.environ["CONFIG"] = config_path + app = create_app() + assert app.config["LDAP"]["ROOT_DN"] == slapd_server.suffix + + del os.environ["CONFIG"] + os.remove(config_path) + + +def test_no_configuration(): + with pytest.raises(Exception) as exc: + app = create_app() + + assert "No configuration file found." in str(exc) + + def test_logging_to_file(configuration, tmp_path, smtpd, admin, slapd_server): log_path = os.path.join(tmp_path, "canaille.log") logging_configuration = {