Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new validator SEI a.k.a Processo SEI #2

Merged
merged 5 commits into from
May 13, 2024
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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ pip install brdocs-validation
| RENAVAM | | Only numbers | Length: _9, 10 & 11_ |
| TE | Título de eleitor | Only numbers | |
| CERT | Certidão de casamento, nascimento e óbito | Only numbers | |
| SEI | Número do Processo SEI | 12345-67890123/4567-89 OR without special chars | |

## Usage

```python
from br_docs import CNPJ, CPF, CNH, NIS, CNS, RENAVAM, TE, CERT
from br_docs import CNPJ, CPF, CNH, NIS, CNS, RENAVAM, TE, CERT, SEI
from pydantic import BaseModel


Expand All @@ -38,4 +40,5 @@ class User(BaseModel):
renavam: RENAVAM
te: TE
cert: CERT
```
sei: SEI
```
2 changes: 2 additions & 0 deletions br_docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from br_docs.validators.nis import NISv
from br_docs.validators.renavam import RENAVAMv
from br_docs.validators.te import TEv
from br_docs.validators.sei import SEIv


CPF = Annotated[str, AfterValidator(CPFv())]
Expand All @@ -19,3 +20,4 @@
RENAVAM = Annotated[str, AfterValidator(RENAVAMv())]
TE = Annotated[str, AfterValidator(TEv())]
CERT = Annotated[str, AfterValidator(CERTv())]
SEI = Annotated[str, AfterValidator(SEIv())]
17 changes: 17 additions & 0 deletions br_docs/validators/sei.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import re

from pydantic_core import PydanticCustomError


class SEIv:
Patterns = re.compile(r'^\d{5}-?\d{8}/?\d{4}-?\d{2}$')

def __call__(self, value: str) -> str:
self.validate(value)
return value

def validate(self, value: str) -> str:
check_format = bool(self.Patterns.match(value))
if check_format is not True:
raise PydanticCustomError('invalid', 'Invalid Value')
return value
58 changes: 34 additions & 24 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,75 +5,85 @@
current_path = Path(__file__).parent


def open_valid_docs(path: str) -> Iterator[str]:
def open_docs(path: str) -> Iterator[str]:
with open(str(current_path.joinpath(path))) as f:
return map(lambda x: x.strip('\n'), f.readlines())


@pytest.fixture
def cnh_list():
"""
1-69 line: https://web.archive.org/web/20240223023315/https://dodf.df.gov.br/index/visualizar-arquivo/?pasta=2023|01_Janeiro|DODF%20022%2031-01-2023|&arquivo=DODF%20022%2031-01-2023%20INTEGRA.pdf
70-100 line: https://web.archive.org/web/20240224034619/https://dodf.df.gov.br/index/visualizar-arquivo/?pasta=2021%7C11_Novembro%7CDODF%20208%2008-11-2021%7C&arquivo=DODF%20208%2008-11-2021%20INTEGRA.pdf
101-125 line: https://web.archive.org/web/20240224035353/https://dodf.df.gov.br/index/visualizar-arquivo/?pasta=2021%7C12_Dezembro%7CDODF%20232%2014-12-2021%7C&arquivo=DODF%20232%2014-12-2021%20INTEGRA.pdf
1-69 line: https://web.archive.org/web/20240223023315/https://dodf.df.gov.br/index/visualizar-arquivo/?pasta=2023|01_Janeiro|DODF%20022%2031-01-2023|&arquivo=DODF%20022%2031-01-2023%20INTEGRA.pdf
70-100 line: https://web.archive.org/web/20240224034619/https://dodf.df.gov.br/index/visualizar-arquivo/?pasta=2021%7C11_Novembro%7CDODF%20208%2008-11-2021%7C&arquivo=DODF%20208%2008-11-2021%20INTEGRA.pdf
101-125 line: https://web.archive.org/web/20240224035353/https://dodf.df.gov.br/index/visualizar-arquivo/?pasta=2021%7C12_Dezembro%7CDODF%20232%2014-12-2021%7C&arquivo=DODF%20232%2014-12-2021%20INTEGRA.pdf
"""
return open_valid_docs('cnhs.txt')
return open_docs('cnhs.txt')


@pytest.fixture
def cpf_list():
"""
1-60 line: https://web.archive.org/web/20240223042316/https://www.detran.ac.gov.br/wp-content/uploads/2022/06/Lista-de-Selecionados-CNH-Social.pdf
61-122 line: https://web.archive.org/web/20240226031446/https://www.detran.ac.gov.br/wp-content/uploads/2022/06/Lista-de-Selecionados-CNH-Social.pdf
1-60 line: https://web.archive.org/web/20240223042316/https://www.detran.ac.gov.br/wp-content/uploads/2022/06/Lista-de-Selecionados-CNH-Social.pdf
61-122 line: https://web.archive.org/web/20240226031446/https://www.detran.ac.gov.br/wp-content/uploads/2022/06/Lista-de-Selecionados-CNH-Social.pdf
"""
return open_valid_docs('cpfs.txt')
return open_docs('cpfs.txt')


@pytest.fixture
def cnpj_list():
"""
1-88 line: https://web.archive.org/web/20240223150643/https://www.detran.df.gov.br/wp-content/uploads/2021/09/Empresas-CNH-Social.pdf
1-88 line: https://web.archive.org/web/20240223150643/https://www.detran.df.gov.br/wp-content/uploads/2021/09/Empresas-CNH-Social.pdf
"""
return open_valid_docs('cnpj.txt')
return open_docs('cnpj.txt')


@pytest.fixture
def nis_list():
"""
1-56 line: https://web.archive.org/web/20240225200956/http://www.varzeagrande.mt.gov.br/storage/Anexos/18cd1d8751995dccb6116b97ab9e0ce7.pdf
57-356 line: http://www.adcon.rn.gov.br/ACERVO/SEARH/DOC/DOC000000000151962.PDF
1-56 line: https://web.archive.org/web/20240225200956/http://www.varzeagrande.mt.gov.br/storage/Anexos/18cd1d8751995dccb6116b97ab9e0ce7.pdf
57-356 line: http://www.adcon.rn.gov.br/ACERVO/SEARH/DOC/DOC000000000151962.PDF
"""
return open_valid_docs('nis.txt')
return open_docs('nis.txt')


@pytest.fixture
def cns_list():
"""
1-61 line: https://web.archive.org/web/20240226014647/https://simaodias.se.gov.br/sites/simaodias.se.gov.br/files/LISTA%20VACINADOS%20D2%20IDOSOS%20-%2010032021%20-%20FORMULARIO.pdf
62-182 line: https://web.archive.org/web/20240226015830/https://altamira.pa.gov.br/wp-content/uploads/2021/07/LISTA-DE-VACINADOS-20-07.pdf
1-61 line: https://web.archive.org/web/20240226014647/https://simaodias.se.gov.br/sites/simaodias.se.gov.br/files/LISTA%20VACINADOS%20D2%20IDOSOS%20-%2010032021%20-%20FORMULARIO.pdf
62-182 line: https://web.archive.org/web/20240226015830/https://altamira.pa.gov.br/wp-content/uploads/2021/07/LISTA-DE-VACINADOS-20-07.pdf
"""
return open_valid_docs('cns.txt')
return open_docs('cns.txt')


@pytest.fixture
def renavam_list():
"""
1-173 line: https://web.archive.org/web/20240226050829/https://www.euamoleilao.com.br/imprimir/0067-leilao-do-detran-de-sao-paulo
174-257 line: https://web.archive.org/web/20240226051016/https://www.euamoleilao.com.br/imprimir/0139-repasse-leilao-ciretran-s-sebastiao
258-687 line: https://web.archive.org/web/20240226051542/https://portal.tjpr.jus.br/pesquisa_athos/publico/carregarAnexo.do;jsessionid=5ff0c586fab5cb74176b49c48765?tjpr.url.crypto=16c74de0ca500657bb7c1cc39118d26e6a12b4f4c9aa9444c033d87933160fa249878bb1b73255ac
1-173 line: https://web.archive.org/web/20240226050829/https://www.euamoleilao.com.br/imprimir/0067-leilao-do-detran-de-sao-paulo
174-257 line: https://web.archive.org/web/20240226051016/https://www.euamoleilao.com.br/imprimir/0139-repasse-leilao-ciretran-s-sebastiao
258-687 line: https://web.archive.org/web/20240226051542/https://portal.tjpr.jus.br/pesquisa_athos/publico/carregarAnexo.do;jsessionid=5ff0c586fab5cb74176b49c48765?tjpr.url.crypto=16c74de0ca500657bb7c1cc39118d26e6a12b4f4c9aa9444c033d87933160fa249878bb1b73255ac
"""
return open_valid_docs('renavam.txt')
return open_docs('renavam.txt')


@pytest.fixture
def te_list():
"""
1-159 line: https://web.archive.org/web/20240226104403/https://issuu.com/psol.df/docs/lista_de_filiados_ao_psol_df___dist
1-159 line: https://web.archive.org/web/20240226104403/https://issuu.com/psol.df/docs/lista_de_filiados_ao_psol_df___dist
"""
return open_valid_docs('te.txt')
return open_docs('te.txt')


@pytest.fixture
def cert_list():
""" google dorks: intext:"DATA DE NASCIMENTO (POR EXTENSO)" AND intext:"CERTIDÃO DE <CASAMENTO|ÓBITO|NASCIMENTO>" AND intext:"matricula" AND ext:pdf """
return open_valid_docs('cert.txt')
"""google dorks: intext:"DATA DE NASCIMENTO (POR EXTENSO)" AND intext:"CERTIDÃO DE <CASAMENTO|ÓBITO|NASCIMENTO>" AND intext:"matricula" AND ext:pdf"""
return open_docs('cert.txt')


@pytest.fixture
def valid_sei_list():
return open_docs('valid_sei.txt')


@pytest.fixture
def invalid_sei_list():
return open_docs('invalid_sei.txt')
50 changes: 50 additions & 0 deletions tests/invalid_sei.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
0000-000000000/2024-050
00000000000002024050
0001-000000003/2025-051
00010000000032025051
0002-000000006/2026-052
00020000000062026052
0003-000000009/2027-053
00030000000092027053
0004-000000012/2028-054
00040000000122028054
0005-000000015/2024-055
00050000000152024055
0006-000000018/2025-056
00060000000182025056
0007-000000021/2026-057
00070000000212026057
0008-000000024/2027-058
00080000000242027058
0009-000000027/2028-059
00090000000272028059
0010-000000030/2024-060
00100000000302024060
0011-000000033/2025-061
00110000000332025061
0012-000000036/2026-062
00120000000362026062
0013-000000039/2027-063
00130000000392027063
0014-000000042/2028-064
00140000000422028064
0015-000000045/2024-065
00150000000452024065
0016-000000048/2025-066
00160000000482025066
0017-000000051/2026-067
00170000000512026067
0018-000000054/2027-068
00180000000542027068
0019-000000057/2028-069
00190000000572028069
0020-000000060/2024-070
00200000000602024070
0021-000000063/2025-071
00210000000632025071
0022-000000066/2026-072
00220000000662026072
0023-000000069/2027-073
00230000000692027073
0024-000000072/2028-074
00240000000722028074
20 changes: 18 additions & 2 deletions tests/test_brdocs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from contextlib import contextmanager

import pytest
from pydantic import create_model
from pydantic_core import ValidationError

from br_docs import CNH, CPF, CNPJ, NIS, CNS, RENAVAM, TE, CERT
from br_docs import CNH, CPF, CNPJ, NIS, CNS, RENAVAM, TE, CERT, SEI


@contextmanager
Expand All @@ -14,7 +15,7 @@ def validate(model_name: str, values, value_type):
m = create_model(model_name, param=(value_type, ...))
m(param=value)
except ValidationError as exc:
assert False, f"{exc}: {value}"
raise exc
yield
finally:
pass
Expand Down Expand Up @@ -58,3 +59,18 @@ def test_te(te_list):
def test_cert(cert_list):
with validate(model_name='TestCERT', values=cert_list, value_type=CERT):
pass


def test_valid_sei(valid_sei_list):
with validate(model_name='TestSEI', values=valid_sei_list, value_type=SEI):
pass


def test_invalid_sei(invalid_sei_list):
with pytest.raises(ValidationError):
with validate(
model_name='TestSEI',
values=invalid_sei_list,
value_type=SEI,
):
pass
50 changes: 50 additions & 0 deletions tests/valid_sei.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
00000-00000000/2024-00
0000000000000202400
00001-00000002/2024-01
0000100000002202401
00002-00000004/2024-02
0000200000004202402
00003-00000006/2024-03
0000300000006202403
00004-00000008/2024-04
0000400000008202404
00005-00000010/2024-05
0000500000010202405
00006-00000012/2024-06
0000600000012202406
00007-00000014/2024-07
0000700000014202407
00008-00000016/2024-08
0000800000016202408
00009-00000018/2024-09
0000900000018202409
00010-00000020/2024-10
0001000000020202410
00011-00000022/2024-11
0001100000022202411
00012-00000024/2024-12
0001200000024202412
00013-00000026/2024-13
0001300000026202413
00014-00000028/2024-14
0001400000028202414
00015-00000030/2024-15
0001500000030202415
00016-00000032/2024-16
0001600000032202416
00017-00000034/2024-17
0001700000034202417
00018-00000036/2024-18
0001800000036202418
00019-00000038/2024-19
0001900000038202419
00020-00000040/2024-20
0002000000040202420
00021-00000042/2024-21
0002100000042202421
00022-00000044/2024-22
0002200000044202422
00023-00000046/2024-23
0002300000046202423
00024-00000048/2024-24
0002400000048202424
Loading