diff --git a/README.md b/README.md index ff1d2672..e2afed4d 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/README_PT_BR.md b/README_PT_BR.md index 8a7d3945..dd772090 100644 --- a/README_PT_BR.md +++ b/README_PT_BR.md @@ -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 ``` diff --git a/brutils/cnpj.py b/brutils/cnpj.py index b106bff7..69f80df8 100644 --- a/brutils/cnpj.py +++ b/brutils/cnpj.py @@ -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 diff --git a/tests/test_cnpj.py b/tests/test_cnpj.py index 1f2ad920..d6874fce 100644 --- a/tests/test_cnpj.py +++ b/tests/test_cnpj.py @@ -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 @@ -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())