Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BigOleHealz committed Oct 28, 2024
1 parent ffd17bb commit 78c8d16
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Uvicorn Server",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/venv/bin/uvicorn", // Adjust path for Windows if needed
"args": [
"main:app",
"--reload",
"--port", "8000"
],
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceFolder}"
},
"cwd": "${workspaceFolder}",
"justMyCode": true
}
]
}
5 changes: 2 additions & 3 deletions services/supabase/users_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, client: Client) -> None:
def check_email_is_valid(self, email: str) -> bool:
"""Check if email is valid"""
if email is None:
return True
return False
if not isinstance(email, str):
return False
if "@" not in email or "." not in email:
Expand Down Expand Up @@ -249,8 +249,7 @@ def user_exists(self, user_id: int) -> bool:
@handle_exceptions(default_return_value=None, raise_on_error=True)
def handle_user_email_update(self, user_id: int, email: str) -> None:
"""Update user email in the users table if email is valid and not None"""
email = email if self.check_email_is_valid(email=email) else None
if email is not None:
if self.check_email_is_valid(email=email):
self.client.table("users").update(
json={"email": email}
).eq("user_id", user_id).execute()
13 changes: 13 additions & 0 deletions tests/services/supabase/test_users_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,19 @@ def test_handle_user_email_update() -> None:
)
assert users_data[1][0]["email"] == EMAIL

# Update the user's email
none_email = None
supabase_manager.handle_user_email_update(user_id=USER_ID, email=none_email)

# Verify the email was updated
users_data, _ = (
supabase_manager.client.table(table_name="users")
.select("email")
.eq(column="user_id", value=USER_ID)
.execute()
)
assert users_data[1][0]["email"] == EMAIL

# Update the user's email
new_email = "new_email@example.com"
supabase_manager.handle_user_email_update(user_id=USER_ID, email=new_email)
Expand Down

0 comments on commit 78c8d16

Please sign in to comment.