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.
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.849.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.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 925fc13abaff3ef1045a84a0016ddab452ee8e21e02856523768ee34d5aa8fa3 |
|
MD5 | 0b3a61f06cd8b400908c07a2b7fa9b04 |
|
BLAKE2b-256 | 588c8ede04699f0ef43d3088aefde46d8ac781becb88821deaf47831d799d70b |