Esempio n. 1
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"
    }])
Esempio n. 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"}])
Esempio n. 3
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, [])
Esempio n. 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)
Esempio n. 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]
Esempio n. 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 == []
Esempio n. 7
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, [])
Esempio n. 8
0
def test_validate_ok():
    """Validate should succeed with permissive defaults"""
    option = Option()
    assert option._validate() == (True, [])
Esempio n. 9
0
def test_default_change_value():
    """Setting a default should change the value"""
    option = Option(default="test")
    assert option.value == "test"
Esempio n. 10
0
 class SettingsTest(BaseSettings):
     home = Option()
Esempio n. 11
0
 class SettingsTest(BaseSettings):
     home = Option()
     url = Option()
     objects = []
Esempio n. 12
0
 class SettingsTest(BaseSettings):
     option1 = Option()
     option2 = Option()