Skip to content

Commit

Permalink
ENT-3589 | Added a new task for sending the code assignment nudge ema…
Browse files Browse the repository at this point in the history
…ils. (#100)
  • Loading branch information
hasnain-naveed authored Oct 22, 2020
1 parent a1d6a7b commit 31fce2e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
35 changes: 32 additions & 3 deletions ecommerce_worker/sailthru/v1/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def send_offer_assignment_email(self, user_email, offer_assignment_id, subject,
'email_body': email_body,
'base_enterprise_url': base_enterprise_url,
},
logger_prefix="Offer Assignment",
logger_prefix='Offer Assignment',
site_code=site_code,
template='enterprise_portal_email'
)
Expand Down Expand Up @@ -460,7 +460,7 @@ def send_offer_update_email(self, user_email, subject, email_body, site_code=Non
'subject': subject,
'email_body': email_body
},
logger_prefix="Offer Assignment",
logger_prefix='Offer Assignment',
site_code=site_code,
template='enterprise_portal_email'
)
Expand Down Expand Up @@ -489,10 +489,39 @@ def send_offer_usage_email(self, emails, subject, email_body, site_code=None):
'subject': subject,
'email_body': email_body
},
logger_prefix="Offer Usage",
logger_prefix='Offer Usage',
site_code=site_code,
template='assignment_email'
)
_, is_eligible_for_retry = notification.send(is_multi_send=True)
if is_eligible_for_retry:
schedule_retry(self, config)


@shared_task(bind=True, ignore_result=True)
def send_code_assignment_nudge_email(self, email, subject, email_body, site_code=None):
"""
Sends the code assignment nudge email.
Args:
self: Ignore.
email (str): Recipient's email address.
subject (str): Email subject.
email_body (str): The body of the email.
site_code (str): Identifier of the site sending the email.
"""
config = get_sailthru_configuration(site_code)
notification = Notification(
config=config,
emails=email,
email_vars={
'subject': subject,
'email_body': email_body
},
logger_prefix='Code Assignment Nudge Email',
site_code=site_code,
template='assignment_email'
)
_, is_eligible_for_retry = notification.send()
if is_eligible_for_retry:
schedule_retry(self, config)
23 changes: 20 additions & 3 deletions ecommerce_worker/sailthru/v1/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@
from six import text_type
from ecommerce_worker.sailthru.v1.exceptions import SailthruError
from ecommerce_worker.sailthru.v1.tasks import (
update_course_enrollment, _update_unenrolled_list, _get_course_content, _get_course_content_from_ecommerce,
send_course_refund_email, send_offer_assignment_email, send_offer_update_email, send_offer_usage_email,
_update_assignment_email_status,

_update_unenrolled_list,
_get_course_content,
_get_course_content_from_ecommerce,
send_code_assignment_nudge_email,
send_course_refund_email,
send_offer_assignment_email,
send_offer_update_email,
send_offer_usage_email,
update_course_enrollment,
)
from ecommerce_worker.utils import get_configuration

Expand Down Expand Up @@ -706,6 +712,12 @@ class SendOfferEmailsTests(BaseSendEmailTests):
'email_body': EMAIL_BODY,
}

NUDGE_TASK_KWARGS = {
'email': USER_EMAIL,
'subject': SUBJECT,
'email_body': EMAIL_BODY,
}

def execute_task(self):
""" Execute the send_offer_assignment_email task. """
send_offer_assignment_email(**self.ASSIGNMENT_TASK_KWARGS)
Expand All @@ -726,6 +738,7 @@ def mock_ecommerce_assignmentemail_api(self, body, status=200):
(send_offer_assignment_email, ASSIGNMENT_TASK_KWARGS, "Offer Assignment"),
(send_offer_update_email, UPDATE_TASK_KWARGS, "Offer Assignment"),
(send_offer_usage_email, USAGE_TASK_KWARGS, "Offer Usage"),
(send_code_assignment_nudge_email, NUDGE_TASK_KWARGS, "Code Assignment Nudge Email"),
)
@ddt.unpack
def test_client_instantiation_error(self, task, task_kwargs, logger_prefix):
Expand All @@ -749,6 +762,7 @@ def test_client_instantiation_error(self, task, task_kwargs, logger_prefix):
(send_offer_assignment_email, ASSIGNMENT_TASK_KWARGS, "send", "Offer Assignment"),
(send_offer_update_email, UPDATE_TASK_KWARGS, "send", "Offer Assignment"),
(send_offer_usage_email, USAGE_TASK_KWARGS, "multi_send", "Offer Usage"),
(send_code_assignment_nudge_email, NUDGE_TASK_KWARGS, "send", "Code Assignment Nudge Email"),
)
@ddt.unpack
def test_api_client_error(self, task, task_kwargs, mock_send, logger_prefix, mock_log):
Expand All @@ -768,6 +782,7 @@ def test_api_client_error(self, task, task_kwargs, mock_send, logger_prefix, moc
(send_offer_assignment_email, ASSIGNMENT_TASK_KWARGS, "Offer Assignment"),
(send_offer_update_email, UPDATE_TASK_KWARGS, "Offer Assignment"),
(send_offer_usage_email, USAGE_TASK_KWARGS, "Offer Usage"),
(send_code_assignment_nudge_email, NUDGE_TASK_KWARGS, "Code Assignment Nudge Email"),
)
@ddt.unpack
def test_api_error_with_retry(self, task, task_kwargs, logger_prefix):
Expand Down Expand Up @@ -809,6 +824,7 @@ def test_api_error_with_retry(self, task, task_kwargs, logger_prefix):
(send_offer_assignment_email, ASSIGNMENT_TASK_KWARGS, "Offer Assignment"),
(send_offer_update_email, UPDATE_TASK_KWARGS, "Offer Assignment"),
(send_offer_usage_email, USAGE_TASK_KWARGS, "Offer Usage"),
(send_code_assignment_nudge_email, NUDGE_TASK_KWARGS, "Code Assignment Nudge Email"),
)
@ddt.unpack
def test_api_error_without_retry(self, task, task_kwargs, logger_prefix):
Expand Down Expand Up @@ -850,6 +866,7 @@ def test_api_error_without_retry(self, task, task_kwargs, logger_prefix):
@ddt.data(
(send_offer_update_email, UPDATE_TASK_KWARGS, "Offer Assignment"),
(send_offer_usage_email, USAGE_TASK_KWARGS, "Offer Usage"),
(send_code_assignment_nudge_email, NUDGE_TASK_KWARGS, "Code Assignment Nudge Email"),
)
@ddt.unpack
def test_api(self, task, task_kwargs, logger_prefix):
Expand Down
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='0.9.0',
version='0.10.0',
description='Celery tasks supporting the operations of edX\'s ecommerce service',
long_description=long_description,
classifiers=[
Expand Down

0 comments on commit 31fce2e

Please sign in to comment.