-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit tests for the get_from_address function
- Loading branch information
Showing
1 changed file
with
46 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import uuid | ||
from collections import namedtuple | ||
from datetime import datetime | ||
from unittest import TestCase | ||
from unittest.mock import ANY, MagicMock, call | ||
|
||
import pytest | ||
|
@@ -1223,15 +1224,55 @@ def test_check_service_over_bounce_rate_normal(self, mocker: MockFixture, notify | |
mock_logger.assert_not_called() | ||
|
||
|
||
@pytest.mark.parametrize("encoded_text, charset, encoding, expected", | ||
@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 | ||
result = send_to_providers.mime_encoded_word_syntax(encoded_text=encoded_text, charset=charset, encoding=encoding) | ||
assert result == expected | ||
|
||
|
||
class TestGetFromAddress(TestCase): | ||
def test_get_from_address_ascii(self): | ||
# Arrange | ||
friendly_from = "John Doe" | ||
email_from = "johndoe" | ||
sending_domain = "example.com" | ||
|
||
# Act | ||
result = send_to_providers.get_from_address(friendly_from, email_from, sending_domain) | ||
|
||
# Assert | ||
expected_result = '"=?utf-8?B?Sm9obiBEb2U=?=" <[email protected]>' | ||
self.assertEqual(result, expected_result) | ||
|
||
def test_get_from_address_non_ascii(self): | ||
# Arrange | ||
friendly_from = "Jöhn Döe" | ||
email_from = "johndoe" | ||
sending_domain = "example.com" | ||
|
||
# Act | ||
result = send_to_providers.get_from_address(friendly_from, email_from, sending_domain) | ||
|
||
# Assert | ||
expected_result = '"=?utf-8?B?SsO2aG4gRMO2ZQ==?=" <[email protected]>' | ||
self.assertEqual(result, expected_result) | ||
|
||
def test_get_from_address_empty_friendly_from(self): | ||
# Arrange | ||
friendly_from = "" | ||
email_from = "johndoe" | ||
sending_domain = "example.com" | ||
|
||
# Act | ||
result = send_to_providers.get_from_address(friendly_from, email_from, sending_domain) | ||
|
||
# Assert | ||
expected_result = '"=?utf-8?B??=" <[email protected]>' | ||
self.assertEqual(result, expected_result) |