This package validate and generate CPF and CNPJ for tests
Project description
c2validator
c2validator is used for validate CPF and CNPJ, and create CPF or CNPJ for tests.
INSTALLING
$ python -m pip install c2validator
CLONING THE REPOSITORY
git clone https://github.com/devguilhermecosta/c2validator.git
HOW USE THIS PACKAGE
Validating CPF or CNPJ
>>> import c2validator as c2
>>>
>>> cpf = c2.validate('725.849.240-21')
>>> cpf.is_valid()
True
This is semple.
If CPF or CNPJ is invalid, the return we will False
.
If the value contains letters symbols or punctuation, a private __clean() method will clean the data before validate.
>>> import c2validator as c2
>>>
>>> cpf = c2.validate('725.849abc.240//-21')
>>> cpf.is_valid()
True
Returning a clean value
When the CPF or CNPJ is valid, you can use the formatted() method. This method returns the value without symbols, letters or punctuation. But, if you need a formatted data with punctuation, you can use formatted(punctuation=True).
>>> import c2validator as c2
>>>
>>> cpf = c2.validate('725.849abc.240//-21')
>>> cpf.is_valid()
True
>>> cpf.formatted()
'72584924021'
>>> cpf.formatted(punctuation=True)
'725.849.240-21'
Now, if the CPF or CNPJ is invalid, the formatted() method returns invalid CPF or CNPJ
.
>>> import c2validator as c2
>>>
>>> cpf = c2.validate('111.111.111-11')
>>> cpf.is_valid()
False
>>> cpf.formatted()
'invalid CPF or CNPJ'
Generating CPF and CNPJ
You can use this package for generate CPF and CNPJ to test your code.
Generating and testing CNPJ
>>> import c2validator as c2
>>>
>>> cnpj = c2.create_cnpj()
>>> cnpj
'89979419564354'
>>> c2.validate(cnpj).is_valid()
True
You can return this CNPJ with punctuation
.
>>> import c2validator as c2
>>>
>>> cnpj = c2.create_cnpj(punctuation=True)
>>> cnpj
'55.487.153/6933-80'
>>> c2.validate(cnpj).is_valid()
True
Generating and testing CPF
>>> import c2validator as c2
>>>
>>> cpf = c2.create_cpf()
>>> cpf
'05170816367'
>>> c2.validate(cpf).is_valid()
True
You can return this CPF with punctuation
.
>>> import c2validator as c2
>>>
>>> cpf = c2.create_cpf(punctuation=True)
>>> cpf
'415.684.161-80'
>>> c2.validate(cpf).is_valid()
True
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for c2validator-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e657947a82088c3c56a38aa500c883a86ccb74f6fcade397bfa625ff8fd3fa84 |
|
MD5 | 66b93b0e28ea077f2f9ded9cced895f3 |
|
BLAKE2b-256 | 0792200b99897c4f1f92fca0d7aa3b9102f44cdda852efbe06858d95c3f5d6ca |