Пример #1
0
def validate_cnpj(value):
    # Docassemble only performs validation if the field is filled
    if not value:
        return True
    
    try:
        value = validators_br.cnpj(value)
    except Exception as e:
        validation_error(str(e))

    return True
def validate_cnpj(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.cnpj(value)
    except Exception as e:
        validation_error(str(e))

    return True
Пример #3
0
def is_cnpj(value, **kwargs):
    """Indicate whether value is a brazilian cnpj 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.cnpj(value, **kwargs)
    except SyntaxError as error:
        raise error
    except Exception:
        return False

    return True
Пример #4
0
 def test_cnpj_equal_digit(self):
     with pytest.raises(errors_br.InvalidCnpjEqualError):
         validators_br.cnpj(self.malformed_equal_digit_cnpj)
Пример #5
0
 def test_cnpj_wrong_mask(self):
     with pytest.raises(errors_br.InvalidCnpjMaskError):
         validators_br.cnpj(self.malformed_mask_cnpj)
Пример #6
0
 def test_cnpj_too_long(self):
     with pytest.raises(errors.MaximumLengthError):
         validators_br.cnpj(self.malformed_long_cnpj)
Пример #7
0
 def test_cnpj_too_short(self):
     with pytest.raises(errors.MinimumLengthError):
         validators_br.cnpj(self.malformed_short_cnpj)
Пример #8
0
 def test_cnpj_string_type(self):
     with pytest.raises(errors_br.DataTypeError):
         validators_br.cnpj(self.malformed_numeric_cnpj)
Пример #9
0
 def test_empty_cnpj(self):
     with pytest.raises(errors.EmptyValueError):
         validators_br.cnpj('')
Пример #10
0
 def test_cnpj_formation(self):
     assert self.well_formed_cnpj == validators_br.cnpj(
         self.well_formed_cnpj)