-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LCFS - Implement Email Notification Triggers in Backend for Subscribed Users #1226 #1402
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
72f6b91
LCFS - Implement Email Notification Triggers in Backend for Subscribe…
8707bae
test fixes
73919d1
Merge branch 'release-0.2.0' into feat/prashanth-email-trigger-1226
prv-proton 0eb8a25
.
9045966
.
4895bb8
.
e490114
clear cache
44c414e
Merge branch 'release-0.2.0' into feat/prashanth-email-trigger-1226
prv-proton 0a13b70
workflow env add
77e6704
.
875937c
Merge branch 'release-0.2.0' into feat/prashanth-email-trigger-1226
prv-proton d7124ab
Merge branch 'release-0.2.0' into feat/prashanth-email-trigger-1226
prv-proton 01bc922
Merge branch 'release-0.2.0' into feat/prashanth-email-trigger-1226
prv-proton 3d40414
email updates
017ff27
Merge branch 'release-0.2.0' into feat/prashanth-email-trigger-1226
prv-proton 9cce713
Merge branch 'release-0.2.0' into feat/prashanth-email-trigger-1226
prv-proton c678c9a
Merge branch 'release-0.2.0' into feat/prashanth-email-trigger-1226
prv-proton a9a68d2
Merge branch 'release-0.2.0' into feat/prashanth-email-trigger-1226
prv-proton 941fdcd
Merge branch 'release-0.2.0' into feat/prashanth-email-trigger-1226
prv-proton c77f4c6
Merge branch 'release-0.2.0' into feat/prashanth-email-trigger-1226
prv-proton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -80,6 +80,12 @@ jobs: | |
LCFS_REDIS_PORT: 6379 | ||
LCFS_REDIS_PASSWORD: development_only | ||
APP_ENVIRONMENT: dev | ||
LCFS_CHES_CLIENT_ID: mock_client_id | ||
LCFS_CHES_CLIENT_SECRET: mock_client_secret | ||
LCFS_CHES_AUTH_URL: http://mock_auth_url | ||
LCFS_CHES_SENDER_EMAIL: [email protected] | ||
LCFS_CHES_SENDER_NAME: Mock Notification System | ||
LCFS_CHES_EMAIL_URL: http://mock_email_url | ||
|
||
- name: Upload pytest results | ||
if: always() | ||
|
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,7 +1,8 @@ | ||
import json | ||
from lcfs.web.api.email.repo import CHESEmailRepository | ||
import pytest | ||
|
||
from unittest.mock import patch | ||
from unittest.mock import patch, AsyncMock | ||
from httpx import AsyncClient | ||
from fastapi import FastAPI | ||
|
||
|
@@ -16,6 +17,20 @@ | |
) | ||
from lcfs.services.s3.client import DocumentService | ||
|
||
@pytest.fixture | ||
def mock_email_repo(): | ||
return AsyncMock(spec=CHESEmailRepository) | ||
|
||
@pytest.fixture | ||
def mock_environment_vars(): | ||
with patch("lcfs.web.api.email.services.settings") as mock_settings: | ||
mock_settings.ches_auth_url = "http://mock_auth_url" | ||
mock_settings.ches_email_url = "http://mock_email_url" | ||
mock_settings.ches_client_id = "mock_client_id" | ||
mock_settings.ches_client_secret = "mock_client_secret" | ||
mock_settings.ches_sender_email = "[email protected]" | ||
mock_settings.ches_sender_name = "Mock Notification System" | ||
yield mock_settings | ||
|
||
# get_compliance_periods | ||
@pytest.mark.anyio | ||
|
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,5 +1,7 @@ | ||
from fastapi import HTTPException | ||
from lcfs.db.models.user.Role import RoleEnum | ||
from lcfs.web.api.compliance_report.update_service import ComplianceReportUpdateService | ||
from lcfs.web.api.notification.services import NotificationService | ||
import pytest | ||
from unittest.mock import AsyncMock, MagicMock, patch | ||
from lcfs.db.models.compliance.ComplianceReport import ComplianceReport | ||
|
@@ -24,6 +26,27 @@ def mock_user_has_roles(): | |
yield mock | ||
|
||
|
||
@pytest.fixture | ||
def mock_notification_service(): | ||
mock_service = AsyncMock(spec=NotificationService) | ||
with patch( | ||
"lcfs.web.api.compliance_report.update_service.Depends", | ||
return_value=mock_service | ||
): | ||
yield mock_service | ||
|
||
|
||
@pytest.fixture | ||
def mock_environment_vars(): | ||
with patch("lcfs.web.api.email.services.settings") as mock_settings: | ||
mock_settings.ches_auth_url = "http://mock_auth_url" | ||
mock_settings.ches_email_url = "http://mock_email_url" | ||
mock_settings.ches_client_id = "mock_client_id" | ||
mock_settings.ches_client_secret = "mock_client_secret" | ||
mock_settings.ches_sender_email = "[email protected]" | ||
mock_settings.ches_sender_name = "Mock Notification System" | ||
yield mock_settings | ||
|
||
# Mock for adjust_balance method within the OrganizationsService | ||
@pytest.fixture | ||
def mock_org_service(): | ||
|
@@ -35,7 +58,7 @@ def mock_org_service(): | |
# update_compliance_report | ||
@pytest.mark.anyio | ||
async def test_update_compliance_report_status_change( | ||
compliance_report_update_service, mock_repo | ||
compliance_report_update_service, mock_repo, mock_notification_service | ||
): | ||
# Mock data | ||
report_id = 1 | ||
|
@@ -55,6 +78,7 @@ async def test_update_compliance_report_status_change( | |
mock_repo.get_compliance_report_by_id.return_value = mock_report | ||
mock_repo.get_compliance_report_status_by_desc.return_value = new_status | ||
compliance_report_update_service.handle_status_change = AsyncMock() | ||
compliance_report_update_service.notfn_service = mock_notification_service | ||
mock_repo.update_compliance_report.return_value = mock_report | ||
|
||
# Call the method | ||
|
@@ -80,6 +104,7 @@ async def test_update_compliance_report_status_change( | |
|
||
assert mock_report.current_status == new_status | ||
assert mock_report.supplemental_note == report_data.supplemental_note | ||
mock_notification_service.send_notification.assert_called_once() | ||
|
||
|
||
@pytest.mark.anyio | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a better place to keep this in the backend? Or is it used in enough places to justify having it in base?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Alex for the review. Since this schema will be used across various services, it causes greenlet spawn error if placed inside the notifications schema, hence it's being placed inside the base.