Skip to content

Commit

Permalink
⬆️ New syntax for enum in format strings
Browse files Browse the repository at this point in the history
  • Loading branch information
otytlandsvik committed Oct 15, 2023
1 parent 7488d86 commit c15255f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app/api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def give_existing_user_admin_privileges(request: Request, id: str, token: Access
if member["role"] == Role.admin:
raise HTTPException(400, "User already admin")

results = db.members.find_one_and_update({'id': member["id"]}, {'$set': {'role': f'{Role.admin}'}})
results = db.members.find_one_and_update({'id': member["id"]}, {'$set': {'role': f'{Role.admin.value}'}})

if not results:
raise HTTPException(500)
Expand All @@ -45,8 +45,8 @@ def create_admin_user(request: Request, newAdmin: MemberInput, token: AccessToke
'id': uid,
'email': newAdmin.email.lower(), # Lowercase e-mail
'password': pwd,
'role': f'{Role.admin}',
'status': f'{Status.inactive}',
'role': f'{Role.admin.value}',
'status': f'{Status.inactive.value}',
}

admin = newAdmin.model_dump()
Expand Down
2 changes: 1 addition & 1 deletion app/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def login(request: Request, credentials: Credentials, response: Response):
# activate members on login
db.members.find_one_and_update(
{'id': member.id},
{"$set": {'status': f'{Status.active}'}}
{"$set": {'status': f'{Status.active.value}'}}
)

token = create_token(member, request.app.config)
Expand Down
10 changes: 5 additions & 5 deletions app/api/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def create_new_member(request: Request, newMember: MemberInput):
'id': uid,
'email': newMember.email.lower(), # Lowercase e-mail
'password': pwd,
'role': f'{Role.unconfirmed}',
'status': f'{Status.inactive}',
'role': f'{Role.unconfirmed.value}',
'status': f'{Status.inactive.value}',
'penalty': 0
}

Expand Down Expand Up @@ -102,7 +102,7 @@ def change_status(request: Request, token: AccessTokenPayload = Depends(authoriz

result = db.members.find_one_and_update(
{'id': member.id},
{"$set": {'status': f'{Status.active}'}}
{"$set": {'status': f'{Status.active.value}'}}
)
if not result:
raise HTTPException(500)
Expand All @@ -123,8 +123,8 @@ def confirm_email(request: Request, code: str):
user = db.members.find_one_and_update(
{'id': validated['user_id']},
{"$set":
{'role': f'{Role.member}',
'status': f'{Status.active}'}
{'role': f'{Role.member.value}',
'status': f'{Status.active.value}'}
},
return_document=ReturnDocument.AFTER)
if not user:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_endpoints/test_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_member_activation(client):
# inactive member
client_login(client, second_member["email"], second_member["password"])
# set member to inactive as login activates users
db.members.find_one_and_update({"email": second_member["email"]}, {"$set": {"status": f'{Status.inactive}'}})
db.members.find_one_and_update({"email": second_member["email"]}, {"$set": {"status": f'{Status.inactive.value}'}})
member = db.members.find_one({'email': second_member["email"]})
assert member and member["status"] == Status.inactive

Expand Down

0 comments on commit c15255f

Please sign in to comment.