Skip to content

Commit

Permalink
Update participante instead of deleting and re-inserting it
Browse files Browse the repository at this point in the history
Co-Authored-By: Eduardo Lauer <edulauer@hotmail.com>
  • Loading branch information
augusto-herrmann and edulauer committed Aug 7, 2024
1 parent 39569a9 commit c3d586d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,9 @@ async def update_participante(
.filter_by(matricula_siape=participante.matricula_siape)
)
db_participante = result.unique().scalar_one()
data_insercao = db_participante.data_insercao
await session.delete(db_participante)
await session.commit()
# create a new
db_participante = models.Participante(**participante.model_dump())
db_participante.data_insercao = data_insercao
for field, value in participante.model_dump().items():
setattr(db_participante, field, value)
db_participante.data_atualizacao = datetime.now()
session.add(db_participante)
await session.commit()
await session.refresh(db_participante)
return schemas.ParticipanteSchema.model_validate(db_participante)
Expand Down
22 changes: 22 additions & 0 deletions tests/participantes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,28 @@ def test_put_duplicate_participante(
assert_equal_participante(response.json(), input_part)


def test_update_participante_with_existing_pt(
truncate_participantes, # pylint: disable=unused-argument
example_part, # pylint: disable=unused-argument
example_pt, # pylint: disable=unused-argument
input_part: dict,
header_usr_1: dict,
client: Client,
):
"""Atualiza um participante existente, sendo que o participante já
possui um Plano de Trabalho a ele associado.
"""
response = client.put(
f"/organizacao/{input_part['origem_unidade']}"
f"/{input_part['cod_unidade_autorizadora']}"
f"/{input_part['cod_unidade_lotacao']}"
f"/participante/{input_part['matricula_siape']}",
json=input_part,
headers=header_usr_1,
)
assert response.status_code == status.HTTP_200_OK


def test_create_participante_inconsistent(
truncate_participantes, # pylint: disable=unused-argument
input_part: dict,
Expand Down

0 comments on commit c3d586d

Please sign in to comment.