diff --git a/pyFBIG/BR_names/BR_female_names.json b/pyFBIG/BR_names/BR_female_names.json new file mode 100644 index 0000000..e1cb0c8 --- /dev/null +++ b/pyFBIG/BR_names/BR_female_names.json @@ -0,0 +1,99 @@ +{ + "names": [ + "Maria", + "Ana", + "Juliana", + "Amanda", + "Carla", + "Fernanda", + "Isabela", + "Larissa", + "Camila", + "Patrícia", + "Gabriela", + "Letícia", + "Beatriz", + "Luana", + "Lívia", + "Mariana", + "Débora", + "Raquel", + "Renata", + "Tatiane", + "Vitória", + "Bianca", + "Mirella", + "Thais", + "Cristiane", + "Lorena", + "Clara", + "Alice", + "Eduarda", + "Valentina", + "Giovanna", + "Laura", + "Sophia", + "Manuela", + "Rafaela", + "Natalia", + "Heloisa", + "Aline", + "Bárbara", + "Rosa", + "Cecília", + "Elaine", + "Priscila", + "Jéssica", + "Fátima", + "Renata", + "Kelly", + "Elaine", + "Patricia", + "Silvana", + "Roberta", + "Alessandra", + "Daniela", + "Monique", + "Talita", + "Adriana", + "Flávia", + "Leticia", + "Fernanda", + "Evelyn", + "Cintia", + "Lilian", + "Luciana", + "Sandra", + "Nicole", + "Marcela", + "Júlia", + "Natália", + "Denise", + "Priscila", + "Alessandra", + "Caroline", + "Valéria", + "Márcia", + "Fernanda", + "Vivian", + "Amanda", + "Vera", + "Lara", + "Andressa", + "Talita", + "Izabella", + "Andreia", + "Crislaine", + "Luma", + "Jordana", + "Tainá", + "Luiza", + "Marina", + "Isabelly", + "Nayara", + "Simone", + "Roberta", + "Lucimara" + ] + } + \ No newline at end of file diff --git a/pyFBIG/BR_names/BR_male_names.json b/pyFBIG/BR_names/BR_male_names.json new file mode 100644 index 0000000..a491655 --- /dev/null +++ b/pyFBIG/BR_names/BR_male_names.json @@ -0,0 +1,100 @@ +{ + "names": [ + "João", + "Pedro", + "Lucas", + "Mateus", + "Gabriel", + "Enzo", + "Luiz", + "Miguel", + "Arthur", + "Rafael", + "Heitor", + "Guilherme", + "Samuel", + "Vinícius", + "Eduardo", + "Daniel", + "Gustavo", + "Felipe", + "Luan", + "Matheus", + "Leonardo", + "Henrique", + "Pietro", + "Cauã", + "André", + "Bruno", + "Diego", + "Thiago", + "Carlos", + "Fernando", + "Joaquim", + "Ian", + "Vitor", + "Bryan", + "Alan", + "Raul", + "Erick", + "Caio", + "José", + "Leandro", + "Ricardo", + "Sérgio", + "Alexandre", + "Elias", + "Paulo", + "Antônio", + "Marcelo", + "Roberto", + "Ramon", + "Dieguinho", + "Mário", + "Francisco", + "Júlio", + "Hugo", + "Rodrigo", + "Nathan", + "Renato", + "Davi", + "Thales", + "Igor", + "Otávio", + "Ronaldo", + "Ivan", + "Cristiano", + "Wagner", + "Alberto", + "Joel", + "Valmir", + "Wesley", + "Adriano", + "Fábio", + "Levi", + "Maicon", + "Luciano", + "Vinícius", + "Nícolas", + "Dênis", + "Lorenzo", + "Flávio", + "Waldemar", + "Cláudio", + "Rui", + "Giovanni", + "Emanuel", + "Benício", + "Ariel", + "Éder", + "Hélio", + "Jair", + "Max", + "Ulisses", + "Wander", + "Yago", + "Zé", + "Renê" + ] + } + \ No newline at end of file diff --git a/pyFBIG/BR_names/BR_surnames.json b/pyFBIG/BR_names/BR_surnames.json new file mode 100644 index 0000000..0d7d04f --- /dev/null +++ b/pyFBIG/BR_names/BR_surnames.json @@ -0,0 +1,98 @@ +{ + "surnames": [ + "Silva", + "Santos", + "Oliveira", + "Pereira", + "Costa", + "Rodrigues", + "Martins", + "Gomes", + "Ferreira", + "Almeida", + "Rocha", + "Melo", + "Carvalho", + "Cardoso", + "Ribeiro", + "Lima", + "Araújo", + "Cavalcante", + "Dias", + "Sousa", + "Nascimento", + "Cruz", + "Monteiro", + "Mendes", + "Cunha", + "Moura", + "Castro", + "Campos", + "Farias", + "Fernandes", + "Tavares", + "Dantas", + "Sales", + "Correia", + "Freitas", + "Duarte", + "Moraes", + "Barbosa", + "Teixeira", + "Barros", + "Siqueira", + "Vieira", + "Lopes", + "Machado", + "Moreira", + "Bezerra", + "Andrade", + "Farias", + "Pinto", + "Menezes", + "Lins", + "Lacerda", + "Marques", + "Peixoto", + "Abreu", + "Lemos", + "Coutinho", + "Gonçalves", + "Figueiredo", + "Azevedo", + "Motta", + "Queiroz", + "Pessoa", + "Leal", + "Gusmão", + "Cordeiro", + "Dantas", + "Xavier", + "Brito", + "Braga", + "Diniz", + "Alves", + "Nogueira", + "Lima", + "Amorim", + "Barreto", + "Gentil", + "Fonseca", + "Vasconcelos", + "Morais", + "Gonçalves", + "Caldas", + "Oliveira", + "Prado", + "Pimentel", + "Câmara", + "Furtado", + "Vargas", + "Cavalcanti", + "Medeiros", + "Lacerda", + "Arantes", + "Paiva" + ] + } + \ No newline at end of file diff --git a/pyFBIG/BR_names/name.py b/pyFBIG/BR_names/name.py new file mode 100644 index 0000000..be009a6 --- /dev/null +++ b/pyFBIG/BR_names/name.py @@ -0,0 +1,61 @@ +import json +import os +import pathlib +from random import randrange + +class Name: + def __init__(self): + self.path = pathlib.Path(__file__).parent.resolve() + self.path = str(self.path).replace('\\', '/') + + def json_load(self, name_list): + return json.load(name_list) + + def female_name(self): + female_name = open(self.path + '/BR_female_names.json') + _list = self.json_load(name_list=female_name) + return _list['names'] + + def male_name(self): + male_name = open(self.path + '/BR_male_names.json') + _list = self.json_load(name_list=male_name) + return _list['names'] + + def surname(self): + male_name = open(self.path + '/BR_surnames.json') + _list = self.json_load(name_list=male_name) + return _list['surnames'] + + def gen_name(self, is_complete: bool = False): + rand_list: list = [self.gen_female_name(), self.gen_male_name()] + _index = randrange(0, 2) + _name = rand_list[_index] + if is_complete == False: + return _name + else: + surnames: list = [self.gen_surname()] + while True: + if len(surnames) == 2: + break + rand_surname: str = self.gen_surname() + if surnames[0] != rand_surname: + surnames.append(rand_surname) + return _name + ' '+ surnames[0] + ' ' + surnames[1] + + def gen_female_name(self): + female_name = self.female_name() + return female_name[randrange(0, len(female_name))] + + def gen_male_name(self): + male_name = self.male_name() + return male_name[randrange(0, len(male_name))] + + def gen_surname(self): + surname = self.surname() + return surname[randrange(0, len(surname))] + + +if __name__ == "__main__": + Name().female_name() + Name().male_name() + Name().surname() \ No newline at end of file diff --git a/pyFBIG/__init__.py b/pyFBIG/__init__.py index 65d305e..ac86bd2 100644 --- a/pyFBIG/__init__.py +++ b/pyFBIG/__init__.py @@ -7,4 +7,6 @@ from .rg_generator import RGGenerator from .rg_product import RGProduct from .crm_generator import CRMGenerator -from .crm_product import CRMProduct \ No newline at end of file +from .crm_product import CRMProduct + +from .BR_names.name import Name \ No newline at end of file diff --git a/pyFBIG/cpf_product.py b/pyFBIG/cpf_product.py index c406b32..85db80c 100644 --- a/pyFBIG/cpf_product.py +++ b/pyFBIG/cpf_product.py @@ -2,9 +2,8 @@ class CPFProduct(IGenProduct): def __init__(self): - self.especil_char = True - self.return_list = False - + self.especil_char: bool = True + self.return_list: bool = False def gen(self): cpf: list = [str(self.rand_num()) for i in range(0, 11)] diff --git a/pyFBIG/crm_product.py b/pyFBIG/crm_product.py index dc1906a..fd97a91 100644 --- a/pyFBIG/crm_product.py +++ b/pyFBIG/crm_product.py @@ -2,8 +2,8 @@ class CRMProduct(IGenProduct): def __init__(self): - self.especial_char = True - self.return_list = False + self.especial_char: bool = True + self.return_list: bool = False def gen(self): _br:str = 'BR' diff --git a/pyFBIG/fake_br_id.py b/pyFBIG/fake_br_id.py index 65cd945..24bd4b4 100644 --- a/pyFBIG/fake_br_id.py +++ b/pyFBIG/fake_br_id.py @@ -8,7 +8,7 @@ class FakeID: """ Fake Brazilian ID generator """ - def cpf(self, especial_char: bool = True, return_list: bool = False): + def cpf(self, especial_char: bool = True, return_list: bool = False, is_complete= False): """ CPF (Cadastro de Pessoa Física) generation call function: @@ -26,7 +26,7 @@ def cpf(self, especial_char: bool = True, return_list: bool = False): product_result = cpf_gen.generator() return product_result - def crm(self, especial_char: bool = True, return_list: bool = False): + def crm(self, especial_char: bool = True, return_list: bool = False, is_complete= False): """ CRM (Conselho Regional de Medicina) generation call function: @@ -44,12 +44,13 @@ def crm(self, especial_char: bool = True, return_list: bool = False): product_result = crm_gen.generator() return product_result - def rg(self): + def rg(self, is_complete: bool= False): """ RG (Registro Geral) generation call function: Returns: Returns the generated RG numbers in string format. """ rg_gen: Type[IGenerator] = RGGenerator() + rg_gen.is_complete = is_complete product_result = rg_gen.generator() return product_result \ No newline at end of file diff --git a/pyFBIG/igen_product.py b/pyFBIG/igen_product.py index 7ebdfb3..552d419 100644 --- a/pyFBIG/igen_product.py +++ b/pyFBIG/igen_product.py @@ -2,9 +2,12 @@ from abc import ABC, abstractmethod class IGenProduct(ABC): + def __init__(self): + self.is_complete = False + def rand_num(self) -> int: return randrange(0, 9) - + @abstractmethod def gen(self): pass \ No newline at end of file diff --git a/pyFBIG/igenerator.py b/pyFBIG/igenerator.py index 50574b1..cfc1d3a 100644 --- a/pyFBIG/igenerator.py +++ b/pyFBIG/igenerator.py @@ -6,6 +6,9 @@ class IGenerator(ABC): """ Generator Interface Class """ + def __init__(self): + self.is_complete = False + @abstractmethod def generator_factory(self): pass diff --git a/pyFBIG/requirements.txt b/pyFBIG/requirements.txt index da67725..9494645 100644 --- a/pyFBIG/requirements.txt +++ b/pyFBIG/requirements.txt @@ -1,4 +1,5 @@ bleach==6.0.0 +build==1.0.3 certifi==2023.7.22 charset-normalizer==3.3.2 colorama==0.4.6 @@ -7,7 +8,6 @@ coveralls==3.3.1 docopt==0.6.2 docutils==0.20.1 exceptiongroup==1.1.3 -Faker==18.13.0 idna==3.4 importlib-metadata==6.7.0 importlib-resources==5.12.0 @@ -21,6 +21,7 @@ packaging==23.2 pkginfo==1.9.6 pluggy==1.2.0 Pygments==2.16.1 +pyproject_hooks==1.0.0 pytest==7.4.3 pytest-cov==4.1.0 python-dateutil==2.8.2 diff --git a/pyFBIG/rg_generator.py b/pyFBIG/rg_generator.py index b2ddd93..45f140c 100644 --- a/pyFBIG/rg_generator.py +++ b/pyFBIG/rg_generator.py @@ -1,7 +1,10 @@ +from typing import Type from .igenerator import IGenerator from .igen_product import IGenProduct from .rg_product import RGProduct class RGGenerator(IGenerator): def generator_factory(self) -> IGenProduct: - return RGProduct() \ No newline at end of file + product: Type[IGenProduct] = RGProduct() + product.is_complete = self.is_complete + return product \ No newline at end of file diff --git a/pyFBIG/rg_product.py b/pyFBIG/rg_product.py index 68dfbd3..ee4da44 100644 --- a/pyFBIG/rg_product.py +++ b/pyFBIG/rg_product.py @@ -1,5 +1,8 @@ from random import randrange from .igen_product import IGenProduct +from .BR_names.name import Name + +name = Name() class RGProduct(IGenProduct): def is_from_minas(self): @@ -11,6 +14,51 @@ def is_from_minas(self): def gen(self): rg = [str(self.rand_num()) for i in range(0, 8)] if self.is_from_minas() == False: - return "".join(rg) + rg = "".join(rg) + else: + rg = 'MG'+"".join(rg) + + if self.is_complete == False: + return rg else: - return 'MG'+"".join(rg) \ No newline at end of file + _name = name.gen_name(is_complete=True) + parents = self.parents_creator(_name= _name) + if parents['father'].split(' ')[0] == _name.split(' ')[0]: + _list = _name.split(' ') + _name = _list[0] + ' Junior ' + ' '.join(_list[1:]) + rg_doc: dict = { + 'name':_name, + 'birth': { + 'birthday': '10/12/1991', + 'cite':'Pocos de Caldas', + 'state':'MG' + }, + 'org': { + 'name': 'PC', + 'state': 'MG', + }, + 'affiliation': parents, + 'rg': rg + } + return rg_doc + + def parents_creator(self, _name) -> dict: + _list = _name.split(' ') + mother = name.gen_female_name() + father = name.gen_male_name() + father_midname = name.gen_surname() + while True: + if _list[1] != father_midname and _list[2] != father_midname and mother != _list[0]: + break + elif _list[1] != father_midname and _list[2] != father_midname: + mother = name.gen_female_name() + else: + father_midname = name.gen_surname() + + mother += ' ' + ' '.join(_list[1:]) + father += ' ' + father_midname + ' ' + _list[-1] + + return { + 'mother': mother, + 'father': father + } \ No newline at end of file diff --git a/tests/test_fake_br_id.py b/tests/test_fake_br_id.py index 0e89b11..aede092 100644 --- a/tests/test_fake_br_id.py +++ b/tests/test_fake_br_id.py @@ -13,9 +13,25 @@ def test_crm(self): def test_rg(self): fake = FakeID() - result = fake.rg() + result = fake.rg(is_complete=False) assert type(result) == str assert len(result) == 8 or len(result) == 10 + result = fake.rg(is_complete=True) + assert type(result) == dict + name = result['name'].split(' ') + mother = result['affiliation']['mother'].split(' ') + assert len(mother) == 3 + father = result['affiliation']['father'].split(' ') + assert len(father) == 3 + assert mother[-1] == father[-1] and mother[1] != father[1] + assert mother[0] != name[0] + if name[1] == 'Junior': + assert len(name) == 4 + assert name[2] == mother[1] and name[-1] == father[-1] + else: + assert len(name) == 3 + assert name[1] == mother[1] and name[-1] == father[-1] + if __name__ == "__main__": TestFakeID.test_cpf() diff --git a/tests/test_gen_rg.py b/tests/test_gen_rg.py index d3ed4ea..76e01ac 100644 --- a/tests/test_gen_rg.py +++ b/tests/test_gen_rg.py @@ -6,14 +6,16 @@ def test_factory(self): factory = rg_gen.generator_factory() assert type(factory) == RGProduct - def test_product(self): product = RGProduct() + product.is_complete = False result = product.gen() assert type(result) == str if result[:3] == "MG": assert len(result[3:]) == 8 - + product.is_complete = True + result = product.gen() + assert type(result) == dict if __name__ == "__main__": TestGenRG.test_factory() diff --git a/tests/test_name.py b/tests/test_name.py new file mode 100644 index 0000000..45e98b8 --- /dev/null +++ b/tests/test_name.py @@ -0,0 +1,72 @@ +import os +import json +from random import randrange +from pyFBIG import Name + + +path = Name().path + +class TestName: + def rand(self, _len): + return randrange(0, _len) + + def test_male(self): + _name = Name() + result = _name.male_name() + assert type(result) == list + + with open(path+'/BR_male_names.json') as file: + json_file = json.load(file) + _names = json_file['names'] + assert _names == result + + _index = self.rand(len(_names)) + assert _names[_index] == result[_index] + + def test_female(self): + _name = Name() + result = _name.female_name() + assert type(result) == list + + with open(path+'/BR_female_names.json') as file: + json_file = json.load(file) + _names = json_file['names'] + assert _names == result + + _index = self.rand(len(_names)) + assert _names[_index] == result[_index] + + def test_surname(self): + _name = Name() + result = _name.surname() + assert type(result) == list + + with open(path+'/BR_surnames.json') as file: + json_file = json.load(file) + _surnames = json_file['surnames'] + assert _surnames == result + + _index = self.rand(len(_surnames)) + assert _surnames[_index] == result[_index] + + def test_gen_name(self): + _name = Name() + result = _name.gen_name(is_complete=False) + assert type(result) == str + result = _name.gen_name(is_complete=True) + assert len(result.split(' ')) == 3 + + def test_gen_male_name(self): + _name = Name() + result = _name.gen_male_name() + assert type(result) == str + + def test_gen_female_name(self): + _name = Name() + result = _name.gen_female_name() + assert type(result) == str + + def test_gen_surname(self): + _name = Name() + result = _name.gen_surname() + assert type(result) == str \ No newline at end of file