Skip to content

Commit 0f2a339

Browse files
committed
fix(elections): fix all elections tests
1 parent e95efd9 commit 0f2a339

3 files changed

Lines changed: 7 additions & 21 deletions

File tree

src/registrations/crud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def update_registration(db_session: AsyncSession, initial_application: Nom
6666
& (NomineeApplicationDB.nominee_election == initial_application.nominee_election)
6767
& (NomineeApplicationDB.position == initial_application.position)
6868
)
69-
.values(initial_application.to_update_dict())
69+
.values(initial_application.serialize())
7070
)
7171

7272

src/registrations/tables.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ def serialize(self) -> dict:
2525
"speech": self.speech,
2626
}
2727

28-
def to_update_dict(self) -> dict:
29-
return {
30-
"computing_id": self.computing_id,
31-
"nominee_election": self.nominee_election,
32-
"position": self.position,
33-
"speech": self.speech,
34-
}
35-
3628
def update_from_params(self, params: NomineeApplicationUpdate):
3729
update_data = params.model_dump(exclude_unset=True)
3830
for k, v in update_data.items():

src/registrations/urls.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ async def register_in_election(db_session: database.DBSession, body: NomineeAppl
116116
# allow any election officer running an election to register for it
117117
await registrations.crud.add_registration(
118118
db_session,
119-
NomineeApplication(
119+
NomineeApplicationDB(
120120
computing_id=body.computing_id, nominee_election=slugified_name, position=body.position, speech=None
121121
),
122122
)
@@ -150,7 +150,7 @@ async def update_registration(
150150
computing_id: str,
151151
position: OfficerPositionEnum,
152152
):
153-
if body.position not in [o.value for o in OfficerPositionEnum]:
153+
if body.position and body.position not in [o.value for o in OfficerPositionEnum]:
154154
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=f"invalid position {body.position}")
155155

156156
slugified_name = slugify(election_name)
@@ -160,7 +160,7 @@ async def update_registration(
160160
status_code=status.HTTP_404_NOT_FOUND, detail=f"election with slug {slugified_name} does not exist"
161161
)
162162

163-
# self updates can only be done during nomination period. Officer updates can be done whenever
163+
# self updates can only be done during nomination period. Admin updates can be done whenever
164164
if election.status(datetime.datetime.now()) != ElectionStatusEnum.NOMINATIONS:
165165
raise HTTPException(
166166
status_code=status.HTTP_400_BAD_REQUEST, detail="speeches can only be updated during the nomination period"
@@ -175,16 +175,10 @@ async def update_registration(
175175
registration.update_from_params(body)
176176

177177
await registrations.crud.update_registration(db_session, registration)
178-
await db_session.commit()
179178

180-
registrant = await registrations.crud.get_one_registration_in_election(
181-
db_session, registration.computing_id, slugified_name, registration.position
182-
)
183-
if not registrant:
184-
raise HTTPException(
185-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="failed to find changed registrant"
186-
)
187-
return registrant
179+
await db_session.commit()
180+
await db_session.refresh(registration)
181+
return registration
188182

189183

190184
@router.delete(

0 commit comments

Comments
 (0)