Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamaia committed Jun 7, 2024
1 parent 68b68d8 commit 72d6eea
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 72 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Utilit谩rio `format_pis` [#224](https://github.com/brazilian-utils/brutils-python/pull/224)
- Utilit谩rio `format_legal_process` [#210](https://github.com/brazilian-utils/brutils-python/pull/210)
- Utilit谩rio `generate_license_plate` [#241](https://github.com/brazilian-utils/brutils-python/pull/241)
<<<<<<< HEAD
- Utilit谩rio `generate_phone` [#295](https://github.com/brazilian-utils/brutils-python/pull/295)
- Utilit谩rio `generate_pis` [#218](https://github.com/brazilian-utils/brutils-python/pull/218)
- Utilit谩rio `generate_legal_process` [#208](https://github.com/brazilian-utils/brutils-python/pull/208)
Expand All @@ -44,8 +43,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Utilit谩rio `remove_symbols_phone` [#188](https://github.com/brazilian-utils/brutils-python/pull/188)
- Utilit谩rio `remove_symbols_pis` [#236](https://github.com/brazilian-utils/brutils-python/pull/236)
- Utilit谩rio `remove_symbols_legal_process` [#209](https://github.com/brazilian-utils/brutils-python/pull/209)
=======
>>>>>>> 6e22034d1f9918376b786c463e9974c6d2f4da2b
- Utilit谩rio `generate_titulo_eleitoral` [#220](https://github.com/brazilian-utils/brutils-python/pull/220)

### Removed
Expand Down
29 changes: 2 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,14 @@ False
- [remove_symbols_pis](#remove_symbols_pis)
- [generate_pis](#generate_pis)
- [Processo Jur铆dico](#processo-jur铆dico)
<<<<<<< HEAD
- [is_valid_legal_process](#is_valid_legal_process)
- [format_legal_process](#format_legal_process)
- [remove_symbols_legal_process](#remove_symbols_legal_process)
- [generate_legal_process](#generate_legal_process)

- [T铆tulo Eleitoral](#titulo-eleitoral)
- [is_valid_voter_id](#is_valid_voter_id)
=======
- [format_processo_juridico](#format_processo_juridico)
- [remove\_symbols\_processo\_juridico](#remove_symbols_processo_juridico)
- [generate_processo_juridico](#generate_processo_juridico)
- [is_valid_processo_juridico](#is_valid_processo_juridico)
- [T铆tulo ELeitoral](#t铆tulo-eleitoral)
- [generate_titulo_eleitoral](#generate_titulo_eleitoral)

>>>>>>> 6e22034d1f9918376b786c463e9974c6d2f4da2b
- [generate_voter_id](#generate_voter_id)

## CPF

Expand Down Expand Up @@ -909,7 +900,7 @@ True

### generate_voter_id

Gerar uma string de d铆gitos de T铆tulo de Eleitor v谩lida aleat贸ria a partir de um estado brasileiro informado.
Gera uma string de d铆gitos de T铆tulo de Eleitor v谩lida aleat贸ria a partir de um estado brasileiro informado.

Retorna:
* str: Um T铆tulo de eleitor v谩lido gerado aleatoriamente.
Expand All @@ -925,22 +916,6 @@ Exemplo:
```


<<<<<<< HEAD
=======
## T铆tulo eleitoral

### generate_titulo_eleitoral

Gera um n煤mero de t铆tulo eleitoral v谩lido aleat贸rio dado uma unidade federativa. Por padr茫o o t铆tulo 茅 emitido fora do Brasil, caso a unidade federativa n茫o seja inforamda.

```python
>>> from brutils import generate_titulo_eleitoral
>>> generate_titulo_eleitoral(state='MG')
'744770710280'
```


>>>>>>> 6e22034d1f9918376b786c463e9974c6d2f4da2b
# Novos Utilit谩rios e Reportar Bugs

Caso queira sugerir novas funcionalidades ou reportar bugs, basta criar
Expand Down
29 changes: 1 addition & 28 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,14 @@ False
- [remove_symbols_pis](#remove_symbols_pis)
- [generate_pis](#generate_pis)
- [Legal Process](#legal-process)
<<<<<<< HEAD
- [is_valid_legal_process](#is_valid_legal_process)
- [format_legal_process](#format_legal_process)
- [remove_symbols_legal_process](#remove_symbols_legal_process)
- [generate_legal_process](#generate_legal_process)

- [Voter ID](#voter-id)
- [is_valid_voter_id](#is_valid_voter_id)
=======
- [format_processo_juridico](#format_processo_juridico)
- [remove\_symbols\_processo\_juridico](#remove_symbols_processo_juridico)
- [generate_processo_juridico](#generate_processo_juridico)
- [is_valid_processo_juridico](#is_valid_processo_juridico)
- [T铆tulo ELeitoral](#t铆tulo-eleitoral)
- [generate_titulo_eleitoral](#generate_titulo_eleitoral)
>>>>>>> 6e22034d1f9918376b786c463e9974c6d2f4da2b
- [generate_voter_id](#generate_voter_id)

## CPF

Expand Down Expand Up @@ -886,7 +878,6 @@ Example:
>>> generate_legal_process(year=2024, orgao=4)
"33158248820244017105"
```
<<<<<<< HEAD

## Voter ID

Expand All @@ -898,9 +889,6 @@ It does not verify if the voter id actually exists.
References:
- https://pt.wikipedia.org/wiki/T%C3%ADtulo_de_eleitor,
- http://clubes.obmep.org.br/blog/a-matematica-nos-documentos-titulo-de-eleitor/
=======
## is_valid_processo_juridico
>>>>>>> 6e22034d1f9918376b786c463e9974c6d2f4da2b

Args:
* voter_id(str): string representing the voter id to be verified.
Expand Down Expand Up @@ -938,21 +926,6 @@ Example:
'950125640248'
```



## Voter registration

### generate_titulo_eleitoral

Generate a valid random voter registration number given a federative unit. The argument has default value (foreigner) if the federative unit is not informed.

```python
>>> from brutils import generate_titulo_eleitoral
>>> generate_titulo_eleitoral(state='MG')
'744770710280'
```


# Feature Request and Bug Report

If you want to suggest new features or report bugs, simply create
Expand Down
20 changes: 10 additions & 10 deletions brutils/voter_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def _calculate_vd2(federative_union, vd1): # type: (str, int) -> str
if federative_union in ["01", "02"] and rest == 0:
vd2 = 1

# edge case: rest == 10, declare vd1 as zero
# edge case: rest == 10, declare vd2 as zero
if rest == 10:
vd2 = 0

Expand All @@ -219,10 +219,10 @@ def generate(state="ZZ") -> str:
Generates a random valid Brazilian voter registration.
Args:
Federative unit[str]
federative_union(str): federative union for the voter id that will be generated. The default value "ZZ" is used for voter IDs issued to foreigners.
Returns:
value[str]: Brazilian voter registration.
str: A randomly generated valid voter ID for the given federative union
"""
UFs = {
"SP": "01",
Expand Down Expand Up @@ -255,11 +255,11 @@ def generate(state="ZZ") -> str:
"ZZ": "28",
}

state = state.upper()
if state in (UFs):
federative_union = federative_union.upper()
if federative_union in (UFs):
sequential_number = str(randint(0, 99999999)).zfill(8)
federative_union = UFs[state]
if _is_federative_union_valid(federative_union):
vd1 = _calculate_vd1(sequential_number, federative_union)
vd2 = _calculate_vd2(federative_union, vd1)
return f"{sequential_number}{federative_union}{vd1}{vd2}"
uf_number = UFs[federative_union]
if _is_uf_number_valid(uf_number):
vd1 = _calculate_vd1(sequential_number, uf_number)
vd2 = _calculate_vd2(uf_number, vd1)
return f"{sequential_number}{uf_number}{vd1}{vd2}"
6 changes: 2 additions & 4 deletions tests/test_voter_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def test_calculate_vd1(self):
self.assertIs(_calculate_vd1("73146415", "03"), 0)

def test_calculate_vd2(self):
self.assertIs(_calculate_vd2("02", 7), 2)
# edge case: if rest == 10, declare vd2 as zero
self.assertIs(_calculate_vd2("03", 7), 0)
# edge case: if UF is "01" (for SP) and rest == 0
# declare dv2 as 1 instead
Expand All @@ -91,22 +93,18 @@ def test_calculate_vd2(self):
def test_generate_voter_id(self):
# test if is_valid a voter id from MG
voter_id = generate(state="MG")

self.assertIs(is_valid(voter_id), True)

# test if is_valid a voter id from AC
voter_id = generate(state="AC")

self.assertIs(is_valid(voter_id), True)

# test if is_valid a voter id from foreigner
voter_id = generate()

self.assertIs(is_valid(voter_id), True)

# test if UF is not valid
voter_id = generate(state="XX")

self.assertIs(is_valid(voter_id), False)


Expand Down

0 comments on commit 72d6eea

Please sign in to comment.