Skip to content

Commit

Permalink
added a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
smcmurtry committed Sep 26, 2023
1 parent 8ecd5ce commit 33bcf64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/delivery/send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def check_service_over_bounce_rate(service_id: str):
)


def mime_encoded_word_syntax(charset="utf-8", encoding="B", encoded_text="") -> str:
def mime_encoded_word_syntax(encoded_text="", charset="utf-8", encoding="B") -> str:
"""MIME encoded-word syntax is a way to encode non-ASCII characters in email headers.
It is described here:
https://docs.aws.amazon.com/ses/latest/dg/send-email-raw.html#send-email-mime-encoding-headers
Expand All @@ -205,7 +205,7 @@ def get_from_address(friendly_from: str, email_from: str, sending_domain: str) -
name using MIME encoded-word syntax, as described in Sending raw email using the Amazon SES API."
"""
friendly_from_b64 = base64.b64encode(friendly_from.encode()).decode("utf-8")
friendly_from_mime = mime_encoded_word_syntax(charset="utf-8", encoding="B", encoded_text=friendly_from_b64)
friendly_from_mime = mime_encoded_word_syntax(encoded_text=friendly_from_b64, charset="utf-8", encoding="B")
return f'"{friendly_from_mime}" <{unidecode(email_from)}@{unidecode(sending_domain)}>'


Expand Down
14 changes: 14 additions & 0 deletions tests/app/delivery/test_send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,3 +1221,17 @@ def test_check_service_over_bounce_rate_normal(self, mocker: MockFixture, notify
mock_logger = mocker.patch("app.notifications.validators.current_app.logger.warning")
assert send_to_providers.check_service_over_bounce_rate(fake_uuid) is None
mock_logger.assert_not_called()


@pytest.mark.parametrize("encoded_text, charset, encoding, expected",
[
("hello_world", "utf-8", "B", "=?utf-8?B?hello_world?="),
("hello_world", "utf-8", "Q", "=?utf-8?Q?hello_world?="),
("hello_world2", "utf-8", "B", "=?utf-8?B?hello_world2?="),
],
)
def test_mime_encoded_word_syntax_encoding(encoded_text, charset, encoding, expected):
result = send_to_providers.mime_encoded_word_syntax(
encoded_text=encoded_text, charset=charset, encoding=encoding
)
assert result == expected

0 comments on commit 33bcf64

Please sign in to comment.