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

Retira o campo id da Contribuicao #168

Merged
merged 12 commits into from
Feb 6, 2025
Merged
2 changes: 2 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
## 3.2.5

* Set default access token expiration time to 30 minutes
* Remove "id" field from Contribuicao's Pydantic schema (there is already
an "id_contribuicao" field)


## 3.2.4
Expand Down
16 changes: 14 additions & 2 deletions src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import timedelta
import json
import os
from typing import Annotated, Union
from typing import Annotated, Awaitable, Callable, Union

from fastapi import Depends, FastAPI, HTTPException, status, Header, Request, Response
from fastapi.security import OAuth2PasswordRequestForm
Expand Down Expand Up @@ -64,7 +64,19 @@ async def lifespan(app: FastAPI):


@app.middleware("http")
async def check_user_agent(request: Request, call_next):
async def check_user_agent(
request: Request, call_next: Callable[[Request], Awaitable[Response]]
) -> Response:
"""Verifica se o cabeçalho User-Agent está presente na requisição.

Args:
request (Request): Requisição HTTP.
call_next (Callable[[Request], Awaitable[Response]]): próximo
callable do middelware.

Returns:
Response: Resposta HTTP.
"""
user_agent = request.headers.get("User-Agent", None)

if not user_agent:
Expand Down
2 changes: 1 addition & 1 deletion src/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ async def create_plano_trabalho(
await session.commit()
except IntegrityError as e:
raise HTTPException(
status_code=422, detail="Referência a tabela entrega não encontrada"
status_code=422, detail="Alteração rejeitada por violar regras de integridade"
) from e
await session.refresh(db_plano_trabalho)
return schemas.PlanoTrabalhoSchema.model_validate(db_plano_trabalho)
Expand Down
15 changes: 5 additions & 10 deletions src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ class TipoMeta(str, enum.Enum):
class Entrega(Base):
"Entrega"
__tablename__ = "entrega"
id = Column(Integer, primary_key=True, index=True)
id = Column(
Integer, primary_key=True, index=True, autoincrement=True, nullable=False
)
id_entrega = Column(
String,
index=True,
Expand Down Expand Up @@ -422,15 +424,8 @@ class Contribuicao(Base):
id_contribuicao = Column(
String,
nullable=False,
comment="Identificador único da contribuição.",
comment="Identificador da contribuição.",
)
# cod_unidade_instituidora = Column(
# Integer,
# nullable=False,
# comment="Código da unidade organizacional (UORG) no Sistema Integrado "
# "de Administração de Recursos Humanos (SIAPE) corresponde à Unidade "
# "de Instituição.",
# )
tipo_contribuicao = Column(
Integer,
nullable=False,
Expand Down Expand Up @@ -688,7 +683,7 @@ class Participante(Base):
"enviar `date`**, uma vez que *a hora é ignorada* e não é armazenada. O "
"formato `datetime`é aceito apenas por compatibilidade com versões "
"anteriores da API, que o aceitavam. Em versões futuras essa "
"flexibilidade será retirada."
"flexibilidade será retirada.",
)
data_atualizacao = Column(DateTime)
data_insercao = Column(DateTime, nullable=False)
Expand Down
5 changes: 0 additions & 5 deletions src/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ class ContribuicaoSchema(BaseModel):
__doc__ = Contribuicao.__doc__
model_config = ConfigDict(from_attributes=True)

id: Optional[int] = Field(
default=None,
title="ID da Contribuição",
description=Contribuicao.id.comment,
)
id_contribuicao: str = Field(
title="Identificador único da contribuição",
description=Contribuicao.id_contribuicao.comment,
Expand Down
20 changes: 18 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def example_pt_unidade_3(
input_pt: dict,
header_admin: dict,
):
"""Cria um Plano de Trabalho do Participante como exemplo."""
"""Cria na unidade 3 um Plano de Trabalho do Participante como exemplo."""
input_pt_3 = deepcopy(input_pt)
input_pt_3["cod_unidade_autorizadora"] = 3
client.put(
Expand All @@ -462,7 +462,23 @@ def example_part(client: httpx.Client, input_part: dict, header_admin: dict):


@pytest.fixture()
def example_part_2(client: httpx.Client, input_part: dict, header_admin: dict):
def example_part_autorizadora_2(client: httpx.Client, input_part: dict, header_admin: dict):
"""Cria um exemplo de status de participante com diferente SIAPE e lotação"""
input_part_1 = deepcopy(input_part)
input_part_1["cod_unidade_autorizadora"] = 2
input_part_1["matricula_siape"] = "1234567"
client.put(
f"/organizacao/{input_part_1['origem_unidade']}"
f"/{input_part_1['cod_unidade_autorizadora']}"
f"/{input_part_1['cod_unidade_lotacao']}"
f"/participante/{input_part_1['matricula_siape']}",
json=input_part_1,
headers=header_admin,
)


@pytest.fixture()
def example_part_lotacao_99(client: httpx.Client, input_part: dict, header_admin: dict):
"""Cria um exemplo de status de participante com diferente SIAPE e lotação"""
input_part_1 = deepcopy(input_part)
input_part_1["cod_unidade_lotacao"] = 99
Expand Down
Loading