Source

araldo / test / conf_test.py

import pytest
from araldo.config import Config, ConfigException


@pytest.fixture
def conf1_name():
    return "testfiles/conf1.yaml"


def test_config_exception():
    exception = ConfigException("testmessage")
    assert str(exception) == "testmessage"


def test_valid(conf1_name):
    conf = Config(conf1_name)
    conf_data = conf.settings()
    assert conf_data["global"]["port"] == 54321


def test_get_fails_if_uninitialized():
    with pytest.raises(ConfigException):
        Config.get()


def test_get_succeeds_if_previously_created(conf1_name):
    conf1 = Config.create(conf1_name)
    assert conf1 is not None
    conf2 = Config.get()
    assert conf2 is not None
    assert id(conf1) == id(conf2)


def test_missing_config_section(conf1_name):
    conf1 = Config.create(conf1_name)
    del conf1._conf["routes"]
    with pytest.raises(ConfigException):
        conf1._validate(conf1._conf)


def test_incorrect_type(conf1_name):
    conf1 = Config.create(conf1_name)
    conf1._conf["plugins"]["araldo.endpoints.inbound"][0]["port"] = "a"
    with pytest.raises(ConfigException):
        conf1._validate(conf1._conf)