generated from cfpb/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/482_tin_lei_check
- Loading branch information
Showing
5 changed files
with
84 additions
and
4 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import logging | ||
|
||
import httpx | ||
from pydantic import EmailStr | ||
from sbl_filing_api.config import settings | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def send_confirmation_email( | ||
user_full_name: str, | ||
user_email: EmailStr, | ||
contact_info_email: EmailStr, | ||
confirmation_id: str, | ||
timestamp: int, | ||
): | ||
confirmation_request = { | ||
"confirmation_id": confirmation_id, | ||
"signer_email": user_email, | ||
"signer_name": user_full_name, | ||
"contact_email": contact_info_email, | ||
"timestamp": timestamp, | ||
} | ||
try: | ||
res = httpx.post(settings.mail_api_url, json=confirmation_request) | ||
if res.status_code != 200: | ||
logger.error(res.text) | ||
else: | ||
logger.info(res.text) | ||
except Exception: | ||
logger.exception(f"Failed to send confirmation email for {user_full_name}") |
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 |
---|---|---|
|
@@ -1027,6 +1027,9 @@ async def test_good_sign_filing( | |
action_type=UserActionType.SIGN, | ||
) | ||
|
||
send_email_mock = mocker.patch("sbl_filing_api.routers.filing.send_confirmation_email") | ||
send_email_mock.return_value = None | ||
|
||
upsert_mock = mocker.patch("sbl_filing_api.entities.repos.submission_repo.upsert_filing") | ||
updated_filing_obj = deepcopy(get_filing_mock.return_value) | ||
upsert_mock.return_value = updated_filing_obj | ||
|
@@ -1042,6 +1045,9 @@ async def test_good_sign_filing( | |
action_type=UserActionType.SIGN, | ||
), | ||
) | ||
send_email_mock.assert_called_with("Test User", "[email protected]", "[email protected]", ANY, ANY) | ||
assert send_email_mock.call_args.args[3].startswith("1234567890ABCDEFGH00-2024-5-") | ||
assert float(send_email_mock.call_args.args[4]) == pytest.approx(int(dt.now().timestamp()), abs=1.5) | ||
assert upsert_mock.call_args.args[1].confirmation_id.startswith("1234567890ABCDEFGH00-2024-5-") | ||
assert res.status_code == 200 | ||
assert float(upsert_mock.call_args.args[1].confirmation_id.split("-")[3]) == pytest.approx( | ||
|
@@ -1052,6 +1058,8 @@ async def test_errors_sign_filing( | |
self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock, get_filing_mock: Mock | ||
): | ||
sub_mock = mocker.patch("sbl_filing_api.entities.repos.submission_repo.get_latest_submission") | ||
send_email_mock = mocker.patch("sbl_filing_api.services.request_handler.send_confirmation_email") | ||
send_email_mock.return_value = None | ||
sub_mock.return_value = SubmissionDAO( | ||
id=1, | ||
submitter=UserActionDAO( | ||
|
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,31 @@ | ||
from unittest.mock import ANY | ||
from pytest_mock import MockerFixture | ||
from sbl_filing_api.services.request_handler import send_confirmation_email | ||
|
||
|
||
def test_send_confirmation_email(mocker: MockerFixture, caplog): | ||
# No errors | ||
post_mock = mocker.patch("sbl_filing_api.services.request_handler.httpx.post") | ||
post_mock.return_value.status_code = 200 | ||
send_confirmation_email("full_name", "[email protected]", "[email protected]", "confirmation", 12345) | ||
post_mock.assert_called_with( | ||
ANY, | ||
json={ | ||
"confirmation_id": "confirmation", | ||
"contact_email": "[email protected]", | ||
"signer_email": "[email protected]", | ||
"signer_name": "full_name", | ||
"timestamp": 12345, | ||
}, | ||
) | ||
|
||
# With errors | ||
post_mock.side_effect = None | ||
post_mock.return_value.status_code = 400 | ||
post_mock.return_value.text = "Email_response" | ||
send_confirmation_email("full_name", "[email protected]", "[email protected]", "confirmation", 12345) | ||
assert "Email_response" in caplog.messages[0] | ||
|
||
post_mock.side_effect = IOError("test") | ||
send_confirmation_email("full_name", "[email protected]", "[email protected]", "confirmation", 12345) | ||
assert "Failed to send confirmation email for full_name" in caplog.messages[1] |