Exemple #1
0
def validate_cpf(value):
    # Docassemble only performs validation if the field is filled
    if not value:
        return True
    
    try:
        value = validators_br.cpf(value)
    except Exception as e:
        validation_error(str(e))
    return True
def validate_cpf(value):
    # ao executar a entrevista o docassemble executa as validações
    # antes do usuario preencher o campo,
    # por isso só deve fazer a validação se o campo estiver preenchido
    if not value:
        return True

    # passando o valor do docassemble para a função de validação
    try:
        value = validators_br.cpf(value)
    except Exception as e:
        validation_error(str(e))
    return True
Exemple #3
0
def is_cpf(value, **kwargs):
    """Indicate whether value is a brazilian cpf number.
    Note:
        param value: The value to evaluate.
        returns: True if value is valid, False if it is not.
        rtype: class:bool <python:bool>
        raises SyntaxError: if kwargs contains duplicate keyword parameters or duplicates
                             keyword parameters passed to the underlying validator
    """
    try:
        value = validators_br.cpf(value, **kwargs)
    except SyntaxError as error:
        raise error
    except Exception:
        return False

    return True
Exemple #4
0
 def test_cpf_equal_digit(self):
     with pytest.raises(errors_br.InvalidCpfEqualError):
         validators_br.cpf(self.malformed_equal_digit_cpf)
Exemple #5
0
 def test_cpf_wrong_mask(self):
     with pytest.raises(errors_br.InvalidCpfMaskError):
         validators_br.cpf(self.malformed_mask_cpf)
Exemple #6
0
 def test_cpf_too_long(self):
     with pytest.raises(errors.MaximumLengthError):
         validators_br.cpf(self.malformed_long_cpf)
Exemple #7
0
 def test_cpf_too_short(self):
     with pytest.raises(errors.MinimumLengthError):
         validators_br.cpf(self.malformed_short_cpf)
Exemple #8
0
 def test_cpf_string_type(self):
     with pytest.raises(errors_br.DataTypeError):
         validators_br.cpf(self.malformed_numeric_cpf)
Exemple #9
0
 def test_empty_cpf(self):
     with pytest.raises(errors.EmptyValueError):
         validators_br.cpf('')
Exemple #10
0
 def test_cpf_formation(self):
     assert self.well_formed_cpf == validators_br.cpf(self.well_formed_cpf)