Exemple #1
0
def test_validate_with_validators_ok():
    """Validate should succeed if validators return True"""

    def v1(value):
        return True

    def v2(value):
        return True

    option = Option(validators=[v1, v2])
    assert option._validate() == (True, [])
Exemple #2
0
def test_validate_with_validators_fail():
    """Validate should fail if a validator returns False"""

    def v1(value):
        return True

    def v2(value):
        raise ValidationError("test")

    option = Option(validators=[v1, v2])
    assert option._validate() == (False, [{"v2": "test"}])
Exemple #3
0
class Settings(BaseSettings):
    """Application settings with lazy evaluation. Once they are imported
    for the first time, the evaluation happens. The module that is
    importing this instance must call `is_valid()` to validate the
    settings.
    """

    base_url = Option(
        default=os.getenv("ELMO_BASE_URL"),
        allow_null=False,
        validators=[validators.is_https_url],
    )
    vendor = Option(default=os.getenv("ELMO_VENDOR"), allow_null=False)
Exemple #4
0
def test_validators_not_alist():
    """Should fail if validators are not a list"""

    def fn(value):
        pass

    with pytest.raises(TypeError):
        Option(validators=fn)
Exemple #5
0
def test_validators_list():
    """Should expect validators to be a list"""

    def fn(value):
        pass

    option = Option(validators=[fn])
    assert option.validators == [fn]
Exemple #6
0
def test_default_constructor():
    """Should create a permissive config option"""
    option = Option()
    assert option.value is None
    assert option.default is None
    assert option.validators == []
Exemple #7
0
def test_validate_allow_null_fail():
    """Validate should fail if the field has None value"""
    option = Option(allow_null=False)
    option.value = None
    assert option._validate() == (False, [{"not_null": "The value must not be None"}])
Exemple #8
0
def test_validate_allow_null_ok():
    """Validate should succeed if the field has None value"""
    option = Option(allow_null=True)
    option.value = None
    assert option._validate() == (True, [])
Exemple #9
0
def test_validate_ok():
    """Validate should succeed with permissive defaults"""
    option = Option()
    assert option._validate() == (True, [])
Exemple #10
0
def test_default_change_value():
    """Setting a default should change the value"""
    option = Option(default="test")
    assert option.value == "test"
Exemple #11
0
 class SettingsTest(BaseSettings):
     home = Option()
Exemple #12
0
 class SettingsTest(BaseSettings):
     home = Option()
     url = Option()
     objects = []
Exemple #13
0
 class SettingsTest(BaseSettings):
     option1 = Option()
     option2 = Option()