Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guffee23 committed Dec 12, 2024
1 parent 7675aac commit af13ec3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/regtech_mail_api/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def send_email(request: Request, confirmation_request: ConfirmationRequest
signer_name=confirmation_request.signer_name,
formatted_date=formatted_date,
confirmation_id=confirmation_request.confirmation_id,
line_break="\n\n"
line_break="\n\n",
)
)

Expand Down
62 changes: 34 additions & 28 deletions tests/test_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi import FastAPI
from fastapi.testclient import TestClient
from pytest_mock import MockerFixture
from unittest.mock import Mock, patch
from unittest.mock import Mock

from regtech_api_commons.models.auth import AuthenticatedUser
from starlette.authentication import AuthCredentials
Expand Down Expand Up @@ -119,6 +119,10 @@ def test_email_dates(
self, mocker: MockerFixture, app_fixture: FastAPI, full_user_mock: Mock
):
client = TestClient(app_fixture)

mock_settings = mocker.patch("regtech_mail_api.internal.settings")
mock_settings.from_addr = "[email protected]"
mock_settings.beta_body_template = "\nCongratulations! This email confirms that Test User submitted a filing on {formatted_date} was successful. The confirmation number for this filing is {confirmation_id}.{line_break}The beta platform is for testing purposes only and user-supplied data may be removed at any time. Email our support staff at [email protected] to share feedback or upload a new file to continue testing.\n"
res = client.post(
"/internal/confirmation/send",
data=json.dumps(
Expand Down Expand Up @@ -179,6 +183,11 @@ def test_confirmation_send(
self, mocker: MockerFixture, app_fixture: FastAPI, full_user_mock: Mock
):
client = TestClient(app_fixture)

mock_settings = mocker.patch("regtech_mail_api.internal.settings")
mock_settings.from_addr = "[email protected]"
mock_settings.beta_body_template = "\nCongratulations! This email confirms that Test User submitted a filing on {formatted_date} was successful. The confirmation number for this filing is {confirmation_id}.{line_break}The beta platform is for testing purposes only and user-supplied data may be removed at any time. Email our support staff at [email protected] to share feedback or upload a new file to continue testing.\n"

res = client.post(
"/internal/confirmation/send",
data=json.dumps(
Expand All @@ -204,32 +213,29 @@ def test_confirmation_send(
assert res.status_code == 200
assert res.json()["email"] == expected_email

mock_settings = mocker.MagicMock()
mock_settings.environment = "PROD"
mock_settings.prod_body_template = "\nCongratulations! This email confirms that Test User submitted a filing on {formatted_date} was successful. The confirmation number for this filing is test.{line_break}If you have any questions or need additional support, email our support staff at [email protected].\n"
expected_email = {
"subject": "Small Business Lending Data Filing Confirmation",
"body": "\nCongratulations! This email confirms that Test User submitted a filing on Nov. 20, 2024 at 1:51 p.m. EST was successful. The confirmation number for this filing is test.\n\nIf you have any questions or need additional support, email our support staff at [email protected].\n",
"from_addr": "[email protected]",
"to": ["[email protected]", "[email protected]"],
"cc": None,
"bcc": None,
}

with patch("regtech_mail_api.internal.settings") as mock_settings:
mock_settings.environment = "PROD"
mock_settings.from_addr = "[email protected]"
expected_email = {
"subject": "Small Business Lending Data Filing Confirmation",
"body": "\nCongratulations! This email confirms that Test User submitted a filing on Nov. 20, 2024 at 1:51 p.m. EST was successful. The confirmation number for this filing is test.\n\nIf you have any questions or need additional support, email our support staff at [email protected].\n",
"from_addr": "[email protected]",
"to": ["[email protected]", "[email protected]"],
"cc": None,
"bcc": None,
}
res = client.post(
"/internal/confirmation/send",
data=json.dumps(
{
"confirmation_id": "test",
"signer_email": "[email protected]",
"signer_name": "Test User",
"contact_email": "[email protected]",
"timestamp": 1732128696,
}
),
)

res = client.post(
"/internal/confirmation/send",
data=json.dumps(
{
"confirmation_id": "test",
"signer_email": "[email protected]",
"signer_name": "Test User",
"contact_email": "[email protected]",
"timestamp": 1732128696,
}
),
)

assert res.status_code == 200
assert res.json()["email"] == expected_email
assert res.status_code == 200
assert res.json()["email"] == expected_email

0 comments on commit af13ec3

Please sign in to comment.