Files
stacosys/tests/test_config.py
T

49 lines
1.3 KiB
Python
Raw Normal View History

2023-11-26 17:51:51 +01:00
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
2022-11-27 20:43:06 +01:00
import pytest
2021-07-17 11:42:04 +02:00
2024-04-12 21:36:11 +02:00
from stacosys.service.configuration import Config, ConfigParameter
2022-12-02 08:59:55 +01:00
EXPECTED_DB = "sqlite://db.sqlite"
EXPECTED_HTTP_PORT = 8080
2022-02-13 19:01:51 +01:00
EXPECTED_LANG = "fr"
2024-04-12 21:35:15 +02:00
config = Config()
2024-04-12 21:36:11 +02:00
2022-11-27 20:43:06 +01:00
@pytest.fixture
def init_config():
2022-12-02 08:59:55 +01:00
config.put(ConfigParameter.DB, EXPECTED_DB)
config.put(ConfigParameter.HTTP_PORT, EXPECTED_HTTP_PORT)
def test_split_key():
section, param = config._split_key(ConfigParameter.HTTP_PORT)
assert section == "http" and param == "port"
2022-11-27 20:43:06 +01:00
def test_exists(init_config):
2022-12-01 20:35:48 +01:00
assert config.exists(ConfigParameter.DB)
2022-11-27 20:43:06 +01:00
2022-12-02 08:59:55 +01:00
2022-11-27 20:43:06 +01:00
def test_get(init_config):
2022-12-02 08:59:55 +01:00
assert config.get(ConfigParameter.DB) == EXPECTED_DB
2022-11-27 20:43:06 +01:00
assert config.get(ConfigParameter.HTTP_HOST) == ""
assert config.get(ConfigParameter.HTTP_PORT) == str(EXPECTED_HTTP_PORT)
assert config.get_int(ConfigParameter.HTTP_PORT) == EXPECTED_HTTP_PORT
2022-11-29 15:55:33 +01:00
with pytest.raises(AssertionError):
2022-12-01 20:35:48 +01:00
config.get_bool(ConfigParameter.DB)
2022-11-27 20:43:06 +01:00
2022-12-02 08:59:55 +01:00
2022-11-27 20:43:06 +01:00
def test_put(init_config):
assert not config.exists(ConfigParameter.LANG)
config.put(ConfigParameter.LANG, EXPECTED_LANG)
assert config.exists(ConfigParameter.LANG)
assert config.get(ConfigParameter.LANG) == EXPECTED_LANG
2022-12-02 08:59:55 +01:00
def test_check(init_config):
success, error = config.check()
assert not success and error