37 lines
1021 B
Python
37 lines
1021 B
Python
import os
|
|
|
|
import pytest
|
|
from dynaconf import Validator
|
|
|
|
from pyinfra.config.loader import load_settings
|
|
from pyinfra.config.validators import webserver_validators
|
|
|
|
|
|
@pytest.fixture
|
|
def test_validators():
|
|
return [
|
|
Validator("test.value.int", must_exist=True, is_type_of=int),
|
|
Validator("test.value.str", must_exist=True, is_type_of=str),
|
|
]
|
|
|
|
|
|
class TestConfig:
|
|
def test_config_validation(self):
|
|
os.environ["WEBSERVER__HOST"] = "localhost"
|
|
os.environ["WEBSERVER__PORT"] = "8080"
|
|
|
|
validators = webserver_validators
|
|
|
|
test_settings = load_settings(validators=validators)
|
|
|
|
assert test_settings.webserver.host == "localhost"
|
|
|
|
def test_env_into_correct_type_conversion(self, test_validators):
|
|
os.environ["TEST__VALUE__INT"] = "1"
|
|
os.environ["TEST__VALUE__STR"] = "test"
|
|
|
|
test_settings = load_settings(validators=test_validators)
|
|
|
|
assert test_settings.test.value.int == 1
|
|
assert test_settings.test.value.str == "test"
|