-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
for mpp-1813: add new_from_address flag
- Loading branch information
Showing
5 changed files
with
75 additions
and
14 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 |
---|---|---|
|
@@ -25,6 +25,7 @@ SOCKETLABS_SECRET_KEY="dummy-value" | |
SOCKETLABS_API_KEY="dummy-value" | ||
SOCKETLABS_VALIDATION_KEY="dummy-value" | ||
RELAY_FROM_ADDRESS="[email protected]:8000" | ||
NEW_RELAY_FROM_ADDRESS="[email protected]:8000" | ||
SITE_ORIGIN="http://127.0.0.1:8000" | ||
MAX_NUM_FREE_ALIASES=5 | ||
TWILIO_ACCOUNT_SID= | ||
|
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
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,18 +1,22 @@ | ||
from email.utils import parseaddr | ||
|
||
from django.conf import settings | ||
from django.contrib.auth.models import User | ||
from django.test import TestCase, override_settings | ||
from unittest.mock import patch | ||
from model_bakery import baker | ||
from waffle.testutils import override_sample | ||
from waffle.models import Flag | ||
|
||
from emails.models import get_domains_from_settings | ||
from emails.utils import ( | ||
NEW_FROM_ADDRESS_FLAG_NAME, | ||
generate_relay_From, | ||
get_email_domain_from_settings, | ||
remove_trackers, | ||
) | ||
|
||
from .models_tests import make_premium_test_user | ||
from .models_tests import make_free_test_user, make_premium_test_user | ||
|
||
|
||
class FormattingToolsTest(TestCase): | ||
|
@@ -91,6 +95,63 @@ def test_generate_relay_From_with_premium_user(self): | |
) | ||
assert formatted_from_address == expected_formatted_from | ||
|
||
@override_settings(RELAY_FROM_ADDRESS="[email protected]", | ||
NEW_RELAY_FROM_ADDRESS="[email protected]") | ||
def test_generate_relay_From_with_new_from_user(self): | ||
free_user = make_free_test_user() | ||
new_from_flag = Flag.objects.create(name=NEW_FROM_ADDRESS_FLAG_NAME) | ||
new_from_flag.users.add(free_user) | ||
original_from_address = '"foo bar" <[email protected]>' | ||
formatted_from_address = generate_relay_From( | ||
original_from_address, free_user.profile_set.first() | ||
) | ||
expected_encoded_display_name = ( | ||
"=?utf-8?b?IiJmb28gYmFyIiA8Zm9vQGJhci5jb20+IFt2aWEgUmVsYXldIg==?=" | ||
) | ||
expected_formatted_from = "%s <%s>" % ( | ||
expected_encoded_display_name, | ||
"[email protected]", | ||
) | ||
assert formatted_from_address == expected_formatted_from | ||
# WTF? TestCase tearDown doesn't clear out this waffle flag? | ||
new_from_flag.users.remove(free_user) | ||
|
||
@override_settings(RELAY_FROM_ADDRESS="[email protected]", | ||
NEW_RELAY_FROM_ADDRESS="[email protected]") | ||
def test_generate_relay_From_with_non_flagged_user(self): | ||
free_user = make_free_test_user() | ||
Flag.objects.create(name=NEW_FROM_ADDRESS_FLAG_NAME) | ||
original_from_address = '"foo bar" <[email protected]>' | ||
formatted_from_address = generate_relay_From( | ||
original_from_address, free_user.profile_set.first() | ||
) | ||
expected_encoded_display_name = ( | ||
"=?utf-8?b?IiJmb28gYmFyIiA8Zm9vQGJhci5jb20+IFt2aWEgUmVsYXldIg==?=" | ||
) | ||
expected_formatted_from = "%s <%s>" % ( | ||
expected_encoded_display_name, | ||
"[email protected]", | ||
) | ||
assert formatted_from_address == expected_formatted_from | ||
|
||
@override_settings(RELAY_FROM_ADDRESS="[email protected]", | ||
NEW_RELAY_FROM_ADDRESS="[email protected]") | ||
def test_generate_relay_From_with_no_user_profile_somehow(self): | ||
free_user = baker.make(User) | ||
Flag.objects.create(name=NEW_FROM_ADDRESS_FLAG_NAME) | ||
original_from_address = '"foo bar" <[email protected]>' | ||
formatted_from_address = generate_relay_From( | ||
original_from_address, free_user.profile_set.first() | ||
) | ||
expected_encoded_display_name = ( | ||
"=?utf-8?b?IiJmb28gYmFyIiA8Zm9vQGJhci5jb20+IFt2aWEgUmVsYXldIg==?=" | ||
) | ||
expected_formatted_from = "%s <%s>" % ( | ||
expected_encoded_display_name, | ||
"[email protected]", | ||
) | ||
assert formatted_from_address == expected_formatted_from | ||
|
||
@override_settings(ON_HEROKU=True, SITE_ORIGIN="https://test.com") | ||
def test_get_email_domain_from_settings_on_heroku(self): | ||
email_domain = get_email_domain_from_settings() | ||
|
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
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