Skip to content

Commit

Permalink
added unit tests for the get_from_address function
Browse files Browse the repository at this point in the history
  • Loading branch information
smcmurtry committed Sep 26, 2023
1 parent 33bcf64 commit 29086a0
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions tests/app/delivery/test_send_to_providers.py
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
Expand Down Expand Up @@ -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)

0 comments on commit 29086a0

Please sign in to comment.