Exemplo n.º 1
0
    def validate(self, response):
        valid = True
        for field, component in self.components.items():
            Validator.validate(component, response)
            if not component.is_valid():
                valid = False

        if valid:
            for callback in self.on_success:
                callback()
            return True

        for callback in self.on_error:
            callback()
        return False
Exemplo n.º 2
0
def test_validator():

    # integer
    assert Validator.validate_integer("1", None) == False
    assert Validator.validate_integer(1, None) == True
    assert Validator.validate_integer(None, None) == False

    assert Validator.validate_blank("", None) == True
    assert Validator.validate_blank(None, None) == True
    assert Validator.validate_blank("test", None) == False

    assert Validator.validate_max_length("12345", 3) == False
    assert Validator.validate_max_length("12345", 5) == True

    assert Validator.validate_min_length("12345", 5) == True
    assert Validator.validate_min_length("12345", 6) == False

    assert Validator.validate_range(10, [0, 1]) == False
    assert Validator.validate_range(10, [0, 10]) == True

    assert Validator.validate_equal(10, 10) == True
    assert Validator.validate_equal(10, 20) == False

    assert Validator.validate_not_equal(10, 20) == True
    assert Validator.validate_not_equal(10, 10) == False