unit tests: app configuration paths

This commit is contained in:
Éloi Rivard 2022-12-16 22:33:09 +01:00
parent 6c41c2a196
commit e59ab27837
2 changed files with 22 additions and 5 deletions

View file

@ -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. "

View file

@ -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 = {