Skip to content

Commit

Permalink
Merge pull request #13 from alvarofpp/issue-8
Browse files Browse the repository at this point in the history
Issue 8
  • Loading branch information
alvarofpp authored Sep 8, 2019
2 parents f29ce81 + 100df86 commit af4e8d7
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 74 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
venv/*
dist/*
build/*
validate_docbr/__pycache__/*
*/__pycache__/*
site/*
tests/*
# Egg metadata
*.egg-info
7 changes: 0 additions & 7 deletions commands.sh

This file was deleted.

21 changes: 21 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import unittest

import tests.test_cpf
import tests.test_cns
import tests.test_cnpj


def suite():
loader = unittest.TestLoader()
suite = unittest.TestSuite()

suite.addTests(loader.loadTestsFromModule(tests.test_cpf))
suite.addTests(loader.loadTestsFromModule(tests.test_cns))
suite.addTests(loader.loadTestsFromModule(tests.test_cnpj))

return suite


if __name__ == '__main__':
runner = unittest.TextTestRunner()
runner.run(suite())
31 changes: 31 additions & 0 deletions tests/test_cnpj.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import unittest
import validate_docbr as docbr


class TestCnpj(unittest.TestCase):
def setUp(self):
""" Inicia novo objeto em todo os testes """
self.cnpj = docbr.CNPJ()

def test_generate(self):
""" Verifica se o método generate """
# generate, generate(mask=True)
cnpjs = [self.cnpj.generate() for i in range(10000)]\
+ [self.cnpj.generate(mask=True) for i in range(10000)]
self.assertIsInstance(cnpjs, list)
self.assertTrue(len(cnpjs) == 20000)

def test_generate_list(self):
""" Verifica se o método generate_list """
# generate_list
cnpjs = self.cnpj.generate_list(10000)\
+ self.cnpj.generate_list(10000, True)\
+ self.cnpj.generate_list(10000, True, True)
self.assertIsInstance(cnpjs, list)
self.assertTrue(len(cnpjs) == 30000)

def test_validate(self):
""" Verifica se o método validate """
# validate
for cnpj in self.cnpj.generate_list(10000):
self.assertTrue(self.cnpj.validate(cnpj))
31 changes: 31 additions & 0 deletions tests/test_cns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import unittest
import validate_docbr as docbr


class TestCns(unittest.TestCase):
def setUp(self):
""" Inicia novo objeto em todo os testes """
self.cns = docbr.CNS()

def test_generate(self):
""" Verifica se o método generate """
# generate, generate(mask=True)
cnss = [self.cns.generate() for i in range(10000)]\
+ [self.cns.generate(mask=True) for i in range(10000)]
self.assertIsInstance(cnss, list)
self.assertTrue(len(cnss) == 20000)

def test_generate_list(self):
""" Verifica se o método generate_list """
# generate_list
cnss = self.cns.generate_list(10000)\
+ self.cns.generate_list(10000, True)\
+ self.cns.generate_list(10000, True, True)
self.assertIsInstance(cnss, list)
self.assertTrue(len(cnss) == 30000)

def test_validate(self):
""" Verifica se o método validate """
# validate
for cns in self.cns.generate_list(10000):
self.assertTrue(self.cns.validate(cns))
53 changes: 53 additions & 0 deletions tests/test_cpf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import unittest
import validate_docbr as docbr


class TestCpf(unittest.TestCase):
def setUp(self):
""" Inicia novo objeto em todo os testes """
self.cpf = docbr.CPF()

def test_generate(self):
""" Verifica se o método generate """
# generate, generate(mask=True)
cpfs = [self.cpf.generate() for i in range(10000)]\
+ [self.cpf.generate(mask=True) for i in range(10000)]
self.assertIsInstance(cpfs, list)
self.assertTrue(len(cpfs) == 20000)

def test_generate_list(self):
""" Verifica se o método generate_list """
# generate_list
cpfs = self.cpf.generate_list(10000)\
+ self.cpf.generate_list(10000, True)\
+ self.cpf.generate_list(10000, True, True)
self.assertIsInstance(cpfs, list)
self.assertTrue(len(cpfs) == 30000)

def test_validate(self):
""" Verifica se o método validate """
# validate
for cpf in self.cpf.generate_list(10000):
self.assertTrue(self.cpf.validate(cpf))

def test_special_case(self):
""" Verifica os casos especiais de CPF """
cpfs_repeated_digits = [
'000.000.000-00',
'111.111.111-11',
'222.222.222-22',
'333.333.333-33',
'444.444.444-44',
'555.555.555-55',
'666.666.666-66',
'777.777.777-77',
'888.888.888-88',
'999.999.999-99',
]
# Entrada consideradas invalidas
for cpf in cpfs_repeated_digits:
self.assertFalse(self.cpf.validate(cpf))
# Entrada consideradas validas
self.cpf.repeated_digits = True
for cpf in cpfs_repeated_digits:
self.assertTrue(self.cpf.validate(cpf))
13 changes: 0 additions & 13 deletions validate_docbr/test/t_CNPJ.py

This file was deleted.

13 changes: 0 additions & 13 deletions validate_docbr/test/t_CNS.py

This file was deleted.

32 changes: 0 additions & 32 deletions validate_docbr/test/t_CPF.py

This file was deleted.

7 changes: 0 additions & 7 deletions validate_docbr/test/t_all.py

This file was deleted.

0 comments on commit af4e8d7

Please sign in to comment.