def validate(cls, v): if not isinstance(v, str): raise TypeError("string required") cpf, cnpj = validate_docbr.CPF(), validate_docbr.CNPJ() if not (cpf.validate(v) or cnpj.validate(v)): raise TypeError("Invalid CPF / CNPJ") return "".join(filter(str.isdigit, v))
def validate_type_entity(cls, v, values): if "cpf_cnpj" not in values: return None cpf_cnpj = values["cpf_cnpj"] cpf, cnpj = validate_docbr.CPF(), validate_docbr.CNPJ() if cpf.validate(cpf_cnpj): return EntityTypeEnum.pf if cnpj.validate(cpf_cnpj): return EntityTypeEnum.pj return None
def validate_document_number(document_number: str): document_number = validate_string(min_length=11, max_length=14)(document_number) CPF_validator = validate_docbr.CPF() is_valid_CPF = CPF_validator.validate(document_number) CNPJ_validator = validate_docbr.CNPJ() is_valid_CNPJ = CNPJ_validator.validate(document_number) if is_valid_CPF or is_valid_CNPJ: return document_number raise Exception(CONSTANTS['MESSAGE']['INVALID_DOCUMENT_NUMBER'])
def setUp(self): """Inicia novo objeto em todo os testes.""" self.cpf = docbr.CPF()
def format(self): mascara = validate_docbr.CPF() mascara = mascara.mask(self.cpf) return mascara
def valida(self,documento): validacao = validate_docbr.CPF() validacao = validacao.validate(documento) return (validacao)
def test_incorrect_argument(self): """Test a função quando os argumentos estão incorretos""" with self.assertRaises(TypeError): docbr.validate_docs([('cpf', docbr.CPF().generate())])
import validate_docbr cpf = validate_docbr.CPF() print(cpf.generate()) list_documents = cpf.generate_list(5, True, False) for document in list_documents: print(document)