From 95bab9095bdf1e0fa9ab32612c5a6e36d993a665 Mon Sep 17 00:00:00 2001 From: jmcguffee Date: Fri, 13 Dec 2024 12:15:59 -0500 Subject: [PATCH] Fixed strings in tests. Moved test vars to project.toml --- pyproject.toml | 4 +++- src/regtech_mail_api/settings.py | 4 ++-- tests/test_send.py | 26 ++++++++++---------------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d760aea..bd8db4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,7 +47,9 @@ env = [ "AUTH_CLIENT=", "EMAIL_MAILER=mock", "FROM_ADDR=test@cfpb.gov", - "TO=cases@localhost.localdomain" + "TO=cases@localhost.localdomain", + "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", diff --git a/src/regtech_mail_api/settings.py b/src/regtech_mail_api/settings.py index 4ab35c2..51e72c9 100644 --- a/src/regtech_mail_api/settings.py +++ b/src/regtech_mail_api/settings.py @@ -23,8 +23,8 @@ class EmailApiSettings(BaseSettings): cc: set[EmailStr] | None = None bcc: set[EmailStr] | None = None - prod_body_template: str = "" - beta_body_template: str = "" + prod_body_template: str = None + beta_body_template: str = None @model_validator(mode="after") def check_smtp(self): diff --git a/tests/test_send.py b/tests/test_send.py index 20001ae..e971ec2 100644 --- a/tests/test_send.py +++ b/tests/test_send.py @@ -119,10 +119,6 @@ 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 = "test@cfpb.gov" - mock_settings.beta_body_template = "\nCongratulations! This email confirms that {signer_name} submitted a filing on {formatted_date}. 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 sblhelp@cfpb.gov to share feedback or return to the platform to upload a new file and continue testing.\n" res = client.post( "/internal/confirmation/send", data=json.dumps( @@ -141,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 sblhelp@cfpb.gov 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": "test@cfpb.gov", "to": ["test@cfpb.gov"], "cc": None, @@ -169,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 sblhelp@cfpb.gov 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": "test@cfpb.gov", "to": ["test@cfpb.gov"], "cc": None, @@ -180,14 +176,13 @@ 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) - - mock_settings = mocker.patch("regtech_mail_api.internal.settings") - mock_settings.from_addr = "test@cfpb.gov" - mock_settings.beta_body_template = "\nCongratulations! This email confirms that {signer_name} submitted a filing on {formatted_date}. 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 sblhelp@cfpb.gov to share feedback or return to the platform to upload a new file and continue testing.\n" - res = client.post( "/internal/confirmation/send", data=json.dumps( @@ -203,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 sblhelp@cfpb.gov 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": "test@cfpb.gov", "to": ["test@cfpb.gov"], "cc": None, @@ -213,11 +208,10 @@ def test_confirmation_send( assert res.status_code == 200 assert res.json()["email"] == expected_email - mock_settings.environment = "PROD" - mock_settings.prod_body_template = "\nCongratulations! 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}If you have any questions or need additional support, email our support staff at sblhelp@cfpb.gov.\n" + monkeypatch.setattr("regtech_mail_api.internal.settings.environment", "PROD") 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 sblhelp@cfpb.gov.\n", + "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": "test@cfpb.gov", "to": ["test_contact@cfpb.gov", "test@cfpb.gov"], "cc": None,