Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ pip install brutils
```
# numbers only, formatted as strings

>>> from brutils import cnpj
>>> from brutils.cpf import is_valid_cpf
>>> is_valid_cpf('00011122233')
False
>>> cnpj.validate('00111222000133')
>>> from brutils.cnpj import is_valid_cnpj
>>> is_valid_cnpj('00111222000133')
False
```

Expand Down
4 changes: 2 additions & 2 deletions README_PT_BR.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ pip install brutils
```
# somente numeros, em formato string

>>> from brutils import cnpj
>>> from brutils.cpf import is_valid_cpf
>>> is_valid_cpf('00011122233')
False
>>> cnpj.validate('00111222000133')
>>> from brutils.cnpj import is_valid_cnpj
>>> is_valid_cnpj('00111222000133')
False
```

Expand Down
11 changes: 11 additions & 0 deletions brutils/cnpj.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ def validate(cnpj): # type: (str) -> bool
)


def is_valid_cnpj(cnpj): # type: (str) -> bool
"""
Returns whether or not the verifying checksum digits of the
given `cnpj` match it's base number. Input should be a digit
string of proper length.
Using this method name to match with the js library api.
Using the same method to ensure backwards compatibility.
"""
return validate(cnpj)


def generate(branch=1): # type: (int) -> str
"""
Generates a random valid CNPJ digit string. An optional branch
Expand Down
15 changes: 14 additions & 1 deletion tests/test_cnpj.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
path.insert(
1, abspath(join(dirname(abspath(getsourcefile(lambda: 0))), pardir))
)
from brutils.cnpj import sieve, display, hashdigit, checksum, validate, generate
from brutils.cnpj import (
sieve,
display,
hashdigit,
checksum,
validate,
generate,
is_valid_cnpj,
)
from unittest import TestCase, main


Expand Down Expand Up @@ -42,6 +50,11 @@ def test_validate(self):
assert not validate("52599927000100")
assert not validate("00000000000")

def test_is_valid_cnpj(self):
assert is_valid_cnpj("34665388000161")
assert not is_valid_cnpj("52599927000100")
assert not is_valid_cnpj("00000000000")

def test_generate(self):
for i in range(1000):
assert validate(generate())
Expand Down