-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ensure alternate email is saved in user profile
- Loading branch information
1 parent
f2e379b
commit cfc33f4
Showing
12 changed files
with
69 additions
and
59 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
backend/lcfs/db/migrations/versions/2024-12-09-22-33_cd8698fe40e6.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Remove notifications email from user_profile | ||
Revision ID: cd8698fe40e6 | ||
Revises: 26ab15f8ab18 | ||
Create Date: 2024-12-09 22:33:29.554360 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "cd8698fe40e6" | ||
down_revision = "26ab15f8ab18" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# Remove notifications_email column from user_profile table | ||
op.drop_column("user_profile", "notifications_email") | ||
|
||
|
||
def downgrade() -> None: | ||
# Add notifications_email column to user_profile table | ||
op.add_column( | ||
"user_profile", | ||
sa.Column( | ||
"notifications_email", | ||
sa.String(length=255), | ||
nullable=True, | ||
comment="Email address used for notifications", | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
from unittest.mock import AsyncMock, Mock | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
|
||
from lcfs.db.models import UserProfile, UserLoginHistory | ||
from lcfs.web.api.user.repo import UserRepository | ||
from lcfs.tests.user.user_payloads import user_orm_model | ||
from lcfs.web.exception.exceptions import DataNotFoundException | ||
|
||
|
||
@pytest.fixture | ||
|
@@ -50,14 +49,13 @@ async def test_create_login_history(dbsession, user_repo): | |
|
||
|
||
@pytest.mark.anyio | ||
async def test_update_notifications_email_success(dbsession, user_repo): | ||
async def test_update_email_success(dbsession, user_repo): | ||
# Arrange: Create a user in the database | ||
user = UserProfile( | ||
keycloak_user_id="user_id_1", | ||
keycloak_email="[email protected]", | ||
keycloak_username="username1", | ||
email="[email protected]", | ||
notifications_email=None, | ||
title="Developer", | ||
phone="1234567890", | ||
mobile_phone="0987654321", | ||
|
@@ -70,10 +68,10 @@ async def test_update_notifications_email_success(dbsession, user_repo): | |
await dbsession.commit() | ||
await dbsession.refresh(user) | ||
|
||
# Act: Update the notifications email | ||
updated_user = await user_repo.update_notifications_email( | ||
# Act: Update the email | ||
updated_user = await user_repo.update_email( | ||
user_profile_id=1, email="[email protected]" | ||
) | ||
|
||
# Assert: Check if the notifications email was updated | ||
assert updated_user.notifications_email == "[email protected]" | ||
# Assert: Check if the email was updated | ||
assert updated_user.email == "[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -468,19 +468,18 @@ async def test_track_logged_in_success(client: AsyncClient, fastapi_app, set_moc | |
|
||
|
||
@pytest.mark.anyio | ||
async def test_update_notifications_email_success( | ||
async def test_update_email_success( | ||
client: AsyncClient, | ||
fastapi_app, | ||
set_mock_user, | ||
add_models, | ||
): | ||
set_mock_user(fastapi_app, [RoleEnum.GOVERNMENT]) | ||
|
||
# Prepare request data | ||
request_data = {"notifications_email": "[email protected]"} | ||
request_data = {"email": "[email protected]"} | ||
|
||
# Act: Send POST request to the endpoint | ||
url = fastapi_app.url_path_for("update_notifications_email") | ||
url = fastapi_app.url_path_for("update_email") | ||
response = await client.post(url, json=request_data) | ||
|
||
# Assert: Check response status and content | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
keycloak_email="[email protected]", | ||
keycloak_username="username", | ||
email="[email protected]", | ||
notifications_email=None, | ||
title="Developer", | ||
phone="1234567890", | ||
mobile_phone="0987654321", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters