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

Permitir busca no QD para um grupo de municípios #148

Merged
merged 3 commits into from
Oct 24, 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
23 changes: 23 additions & 0 deletions dag_confs/examples_and_tests/qd_list_territory_id_example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
dag:
id: qd_list_territory_id_example
description: DAG de teste com múltiplos territory_id
schedule: 0 8 * * MON-FRI
search:
header: "Teste com múltiplos territory_id"
territory_id:
- 3300100
- 3300159
- 3300209
- 3305703
sources:
- QD
terms:
- LGPD
- RIO DE JANEIRO
force_rematch: On
ignore_signature_match: On
report:
emails:
- [email protected]
subject: "Teste do Ro-dou"
skip_null: False
2 changes: 1 addition & 1 deletion docs/docs/como_funciona/parametros.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ A página abaixo lista os parâmetros configuráveis nos arquivos YAML:
- **is_exact_search**: Busca somente o termo exato. Valores: True ou False. Default: True.
- **sources**: Fontes de pesquisa dos diários oficiais. Pode ser uma ou uma lista. Opções disponíveis: DOU, QD, INLABS.
- **terms**: Lista de termos a serem buscados. Para o INLABS podem ser utilizados operadores avançados de busca.
- **territory_id**: Identificador do id do município. Necessário para buscar no Querido Diário.
- **territory_id**: Lista de identificadores do id do município. Necessário para buscar no Querido Diário.

## Parâmetros do Relatório (Report)
- **attach_csv**: Anexar no email o resultado da pesquisa em CSV.
Expand Down
16 changes: 14 additions & 2 deletions schemas/ro-dou.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,21 @@
}
},
"territory_id": {
"type": "integer",
"description": "Id do território no Querido Diário - QD"
"oneOf": [
{
"type": "integer",
"description": "Id do território no Querido Diário - QD",
},
{
"type": "array",
"description": "Lista de Id do território no Querido Diário - QD",
"items": {
"type": "integer"
}
}
]
},

"terms": {
"oneOf": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SearchConfig(BaseModel):
description="Lista de fontes de dados para pesquisar (Querido Diário [QD], "
"Diário Oficial da União [DOU], INLABS). Default: DOU.",
)
territory_id: Optional[int] = Field(
territory_id: Optional[Union[int, List[int]]] = Field(
default=None,
description="ID do território no Querido Diário para filtragem "
"baseada em localização",
Expand Down
4 changes: 3 additions & 1 deletion src/searchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ def _search_term(
payload = _build_query_payload(search_term, reference_date)

if territory_id:
payload.append(("territory_ids", territory_id))
if isinstance(territory_id, int): territory_id = [territory_id]
for terr_id in territory_id:
payload.append(("territory_ids", terr_id))

req_result = requests.get(self.API_BASE_URL, params=payload)

Expand Down
47 changes: 47 additions & 0 deletions tests/parsers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,53 @@
},
},
),
(
"qd_list_territory_id_example.yaml",
{
"id": "qd_list_territory_id_example",
"description": "DAG de teste com múltiplos territory_id",
"schedule": '0 8 * * MON-FRI',
"dataset": None,
"doc_md": None,
"tags": {"dou", "generated_dag"},
"owner": [],
"search": [
{
"terms": [
"LGPD",
"RIO DE JANEIRO",
],
"header": "Teste com múltiplos territory_id",
"sources": ["QD"],
"sql": None,
"conn_id": None,
"territory_id": [3300100,3300159,3300209,3305703],
"dou_sections": ["TODOS"],
"search_date": "DIA",
"field": "TUDO",
"is_exact_search": True,
"ignore_signature_match": True,
"force_rematch": True,
"full_text": False,
"use_summary": False,
"department": None,
}
],
"report": {
"emails": ["[email protected]"],
"subject": "Teste do Ro-dou",
"attach_csv": False,
"discord_webhook": None,
"slack_webhook": None,
"skip_null": False,
"hide_filters": False,
"header_text": None,
"footer_text": None,
"no_results_found_text": "Nenhum dos termos pesquisados "
"foi encontrado nesta consulta",
},
},
),
],
)
def test_parse(filepath, result_tuple):
Expand Down
20 changes: 20 additions & 0 deletions tests/qd_searcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,23 @@ def test_build_query_payload(pre_tags: str,
]

assert payload == expected


@pytest.mark.parametrize(
'territory_id, expected_payload',
[
(3300100, [('territory_ids', 3300100)]),
([3300100, 3300159], [('territory_ids', 3300100), ('territory_ids', 3300159)]),
]
)
def test_search_with_multiple_territory_ids(territory_id, expected_payload):
#searcher = QDSearcher()
payload = []

# Simula a lógica que foi alterada para suportar múltiplos IDs de território
if isinstance(territory_id, int):
territory_id = [territory_id]
for terr_id in territory_id:
payload.append(('territory_ids', terr_id))

assert payload == expected_payload
Loading