Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
ENT-4496: remove special characters from sender_alias (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
sameenfatima78 authored Jun 11, 2021
1 parent ec1e2ff commit 2c52c2d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ecommerce_worker/email/v1/braze/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,14 @@ def send_message(
"message": "success"
}
"""
# To avoid circular import
from ecommerce_worker.email.v1.utils import remove_special_characters_from_string
if not email_ids or not subject or not body:
raise BrazeClientError('Missing parameters for Braze email')
self.create_braze_alias(email_ids)
user_aliases = []
external_ids = []
sender_alias = remove_special_characters_from_string(sender_alias)
for email_id in email_ids:
external_id = self.get_braze_external_id(email_id)
if external_id:
Expand Down
20 changes: 19 additions & 1 deletion ecommerce_worker/email/v1/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import responses
from mock import patch

from ecommerce_worker.email.v1.utils import did_email_bounce, update_assignment_email_status
from ecommerce_worker.email.v1.utils import (
did_email_bounce,
remove_special_characters_from_string,
update_assignment_email_status,
)
from ecommerce_worker.utils import get_configuration


Expand Down Expand Up @@ -78,3 +82,17 @@ def test_did_email_bounce_routing(self, braze_enabled, braze_enabled_mock, braze
braze_client_mock.return_value.did_email_bounce.return_value = True
bounced = did_email_bounce('email', 'site_code')
assert bounced == braze_enabled

@ddt.data(
('', ''),
('EdX Support Team', 'EdX Support Team'),
('ABC Mills, Inc. on edX', 'ABC Mills Inc on edX'),
('A&B Enterprise, inc.', 'AB Enterprise inc'),
)
@ddt.unpack
def test_remove_special_characters_from_string(self, input_string, expected):
"""
Test that the utility returns string with all special characters removed.
"""
actual_string = remove_special_characters_from_string(input_string)
self.assertEqual(actual_string, expected)
14 changes: 14 additions & 0 deletions ecommerce_worker/email/v1/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Utility functions. """
import string

from requests.exceptions import RequestException

Expand Down Expand Up @@ -43,3 +44,16 @@ def did_email_bounce(user_email, site_code=None) -> bool:
return client.did_email_bounce(user_email)

return False


def remove_special_characters_from_string(input_string): # pylint: disable=invalid-name
"""
Removes all special characters from the string passed as argument.
string.punctuation contains the following characters: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
Args:
input_string (str): Input string from which special characters need to be removed.
"""
if input_string:
return input_string.translate(str.maketrans('', '', string.punctuation))
return ''
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def is_requirement(line):

setup(
name='edx-ecommerce-worker',
version='2.1.0',
version='2.1.1',
description='Celery tasks supporting the operations of edX\'s ecommerce service',
long_description=long_description,
classifiers=[
Expand Down

0 comments on commit 2c52c2d

Please sign in to comment.