Skip to content

Commit

Permalink
54 email text in configmap (#61)
Browse files Browse the repository at this point in the history
* Changed prod and beta body texts to be pulled from env vars

* Updated tests

* Fixed test after main merge

* Small change to test to check signer name

* Fixed strings in tests. Moved test vars to project.toml
  • Loading branch information
guffee23 authored Dec 13, 2024
1 parent aa5007a commit 001a094
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 47 deletions.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ env = [
"AUTH_CLIENT=",
"EMAIL_MAILER=mock",
"[email protected]",
"[email protected]"
"[email protected]",
"BETA_BODY_TEMPLATE=Congratulations! This email confirms that {{signer_name}} submitted a filing on {{formatted_date}}. The confirmation number for this filing is {{confirmation_id}}.{{line_break}}You filed in beta.",
"PROD_BODY_TEMPLATE=Congratulations! This email confirms that {{signer_name}} submitted a filing on {{formatted_date}} was successful. The confirmation number for this filing is {{confirmation_id}}.{{line_break}}You filed in PROD."
]
addopts = [
"--cov-report=term-missing",
Expand Down
18 changes: 4 additions & 14 deletions src/regtech_mail_api/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ class ConfirmationRequest(BaseModel):
confirmation_id: str


prod_body_template = """
Congratulations! This email confirms that {signer_name} submitted a filing on {formatted_date}. The confirmation number for this filing is {confirmation_id}.
If you have any questions or need additional support, email our support staff at [email protected].
"""

beta_body_template = """
Congratulations! This email confirms that {signer_name} submitted a filing on {formatted_date}. The confirmation number for this filing is {confirmation_id}.
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 return to the platform to upload a new file and continue testing.
"""


@router.post("/confirmation/send")
async def send_email(request: Request, confirmation_request: ConfirmationRequest):
mailer = create_mailer()
Expand All @@ -61,13 +48,16 @@ async def send_email(request: Request, confirmation_request: ConfirmationRequest
f"{formatted_month} {timestamp_est.strftime("%d, %Y at %-I:%M")} {am_pm} EST"
)
body_template = (
prod_body_template if settings.environment == "PROD" else beta_body_template
settings.prod_body_template
if settings.environment == "PROD"
else settings.beta_body_template
)
body_text = dedent(
body_template.format(
signer_name=confirmation_request.signer_name,
formatted_date=formatted_date,
confirmation_id=confirmation_request.confirmation_id,
line_break="\n\n",
)
)

Expand Down
3 changes: 3 additions & 0 deletions src/regtech_mail_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class EmailApiSettings(BaseSettings):
cc: set[EmailStr] | None = None
bcc: set[EmailStr] | None = None

prod_body_template: str = None
beta_body_template: str = None

@model_validator(mode="after")
def check_smtp(self):
if self.email_mailer == EmailMailerType.SMTP:
Expand Down
64 changes: 32 additions & 32 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 @@ -137,7 +137,7 @@ def test_email_dates(

expected_email = {
"subject": "[BETA] Small Business Lending Data Filing Confirmation",
"body": "\nCongratulations! This email confirms that Test User submitted a filing on March 15, 2024 at 6:10 a.m. EST. The confirmation number for this filing is test.\n\nThe 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 return to the platform to upload a new file and continue testing.\n",
"body": "Congratulations! This email confirms that Test User submitted a filing on March 15, 2024 at 6:10 a.m. EST. The confirmation number for this filing is test.\n\nYou filed in beta.",
"from_addr": "[email protected]",
"to": ["[email protected]"],
"cc": None,
Expand Down Expand Up @@ -165,7 +165,7 @@ def test_email_dates(

expected_email = {
"subject": "[BETA] Small Business Lending Data Filing Confirmation",
"body": "\nCongratulations! This email confirms that Test User submitted a filing on Sept. 15, 2024 at 1:10 p.m. EST. The confirmation number for this filing is test.\n\nThe 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 return to the platform to upload a new file and continue testing.\n",
"body": "Congratulations! This email confirms that Test User submitted a filing on Sept. 15, 2024 at 1:10 p.m. EST. The confirmation number for this filing is test.\n\nYou filed in beta.",
"from_addr": "[email protected]",
"to": ["[email protected]"],
"cc": None,
Expand All @@ -176,7 +176,11 @@ def test_email_dates(
assert res.json()["email"] == expected_email

def test_confirmation_send(
self, mocker: MockerFixture, app_fixture: FastAPI, full_user_mock: Mock
self,
mocker: MockerFixture,
app_fixture: FastAPI,
full_user_mock: Mock,
monkeypatch,
):
client = TestClient(app_fixture)
res = client.post(
Expand All @@ -194,7 +198,7 @@ def test_confirmation_send(

expected_email = {
"subject": "[BETA] 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. The confirmation number for this filing is test.\n\nThe 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 return to the platform to upload a new file and continue testing.\n",
"body": "Congratulations! This email confirms that Test User submitted a filing on Nov. 20, 2024 at 1:51 p.m. EST. The confirmation number for this filing is test.\n\nYou filed in beta.",
"from_addr": "[email protected]",
"to": ["[email protected]"],
"cc": None,
Expand All @@ -204,32 +208,28 @@ def test_confirmation_send(
assert res.status_code == 200
assert res.json()["email"] == expected_email

mock_settings = mocker.MagicMock()
monkeypatch.setattr("regtech_mail_api.internal.settings.environment", "PROD")
expected_email = {
"subject": "Small Business Lending Data Filing Confirmation",
"body": "Congratulations! 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\nYou filed in PROD.",
"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. 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 001a094

Please sign in to comment.