canaille-globuzma/tests/app/test_flaskutils.py

37 lines
1,013 B
Python
Raw Normal View History

2022-12-16 21:14:46 +00:00
import os
2022-12-16 21:33:09 +00:00
import toml
2022-12-16 21:14:46 +00:00
from canaille import create_app
2023-04-09 13:52:55 +00:00
from canaille.app.flask import set_parameter_in_url_query
def test_set_parameter_in_url_query():
assert (
set_parameter_in_url_query("https://auth.mydomain.test", foo="bar")
== "https://auth.mydomain.test?foo=bar"
)
assert (
set_parameter_in_url_query("https://auth.mydomain.test?foo=baz", foo="bar")
== "https://auth.mydomain.test?foo=bar"
)
assert (
set_parameter_in_url_query("https://auth.mydomain.test?foo=baz", hello="world")
== "https://auth.mydomain.test?foo=baz&hello=world"
)
2022-12-16 21:14:46 +00:00
def test_environment_configuration(configuration, tmp_path):
2022-12-16 21:33:09 +00:00
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["CANAILLE"]["SMTP"]["FROM_ADDR"] == "admin@mydomain.test"
2022-12-16 21:33:09 +00:00
del os.environ["CONFIG"]
os.remove(config_path)