Skip to content

Commit

Permalink
feat: add product source to ingestion email subject and summary (#4092)
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 authored Sep 18, 2023
1 parent 0064b85 commit e279ca3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
6 changes: 4 additions & 2 deletions course_discovery/apps/course_metadata/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,15 @@ def send_email_for_comment(comment, course, author):
logger.exception('Failed to send email notifications for comment on course %s', course.uuid)


def send_ingestion_email(partner, subject, to_users, product_type, ingestion_details):
def send_ingestion_email(partner, subject, to_users, product_type, product_source, ingestion_details):
""" Send an overall report of a product's ingestion.
Arguments:
partner (Object): Partner model object
subject (str): subject line for email
to_users (list(str)): a list of email addresses to whom the email should be sent to
product_type (str): the product whose ingestion has been run
product_source (Object): the source of the product
ingestion_details (dict): Stats of ingestion, along with reported errors
"""
products_json = ingestion_details.pop('products_json', None)
Expand All @@ -362,7 +363,8 @@ def send_ingestion_email(partner, subject, to_users, product_type, ingestion_det
'product_type': product_type,
'publisher_url': partner.publisher_url,
'ingestion_contact_email': settings.LOADER_INGESTION_CONTACT_EMAIL,
'marketing_service_name': settings.MARKETING_SERVICE_NAME
'marketing_service_name': settings.MARKETING_SERVICE_NAME,
'product_source': product_source.name,
}
txt_template = 'course_metadata/email/loader_ingestion.txt'
html_template = 'course_metadata/email/loader_ingestion.html'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def handle(self, *args, **options):

if product_type:
logger.info(f"Sending Ingestion stats email for product type {product_type}")
email_subject = f"{product_type.replace('_', ' ').title()} Data Ingestion"
email_subject = f"{source.name}- {product_type.replace('_', ' ').title()} Data Ingestion"
product_mapping = settings.PRODUCT_METADATA_MAPPING[self.PRODUCT_TYPE_SLUG_MAP[product_type]][source.slug]
to_users = product_mapping['EMAIL_NOTIFICATION_LIST']
ingestion_details = {
Expand All @@ -132,5 +132,5 @@ def handle(self, *args, **options):
'products_json': products_json
}
send_ingestion_email(
partner, email_subject, to_users, product_type, ingestion_details,
partner, email_subject, to_users, product_type, source, ingestion_details,
)
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ def handle(self, *args, **options):

if product_type:
logger.info(f"Sending Ingestion stats email for product type {product_type}")
email_subject = f"{product_type.replace('_', ' ').title()} Data Ingestion"
email_subject = f"{source.name}- {product_type.replace('_', ' ').title()} Data Ingestion"
to_users = settings.PRODUCT_METADATA_MAPPING[product_type][source.slug]['EMAIL_NOTIFICATION_LIST']
ingestion_details = {
'ingestion_run_time': ingestion_time,
**loader.get_ingestion_stats()
}
send_ingestion_email(
partner, email_subject, to_users, product_type, ingestion_details,
partner, email_subject, to_users, product_type, source, ingestion_details,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block body %}

<p>
The data ingestion has been run for product type <strong>{{ product_type }}</strong>. See below for the ingestion stats.
The data ingestion has been run for product type <strong>{{ product_type }}</strong> and product source <strong>{{ product_source }}</strong>. See below for the ingestion stats.
</p>
<div>
<table border="2" width="50%" style="padding: 5px;">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The data ingestion has been run for product type <strong>{{ product_type }}</strong>. See below for the ingestion stats.
The data ingestion has been run for product type <strong>{{ product_type }}</strong> and product source <strong>{{ product_source }}</strong>. See below for the ingestion stats.

Ingestion Statistics

Expand Down
21 changes: 12 additions & 9 deletions course_discovery/apps/course_metadata/tests/test_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from course_discovery.apps.course_metadata.models import CourseEditor, CourseRunStatus, CourseType
from course_discovery.apps.course_metadata.tests.constants import MOCK_PRODUCTS_DATA
from course_discovery.apps.course_metadata.tests.factories import (
CourseEditorFactory, CourseFactory, CourseRunFactory, CourseTypeFactory, OrganizationFactory, PartnerFactory
CourseEditorFactory, CourseFactory, CourseRunFactory, CourseTypeFactory, OrganizationFactory, PartnerFactory,
SourceFactory
)
from course_discovery.apps.publisher.choices import InternalUserRole
from course_discovery.apps.publisher.constants import LEGAL_TEAM_GROUP_NAME
Expand Down Expand Up @@ -447,6 +448,7 @@ class TestIngestionEmail(TestCase):
def setUp(self):
super().setUp()
self.partner = PartnerFactory()
self.source = SourceFactory(name='edX')

def _get_base_ingestion_stats(self):
return {
Expand Down Expand Up @@ -482,7 +484,7 @@ def test_product_types(self, product_type, email_subject):
Verify the email content correctly displays the correct product type.
"""
emails.send_ingestion_email(
self.partner, email_subject, self.USER_EMAILS, product_type,
self.partner, email_subject, self.USER_EMAILS, product_type, self.source,
{
**self._get_base_ingestion_stats(),
'total_products_count': 1,
Expand All @@ -496,7 +498,8 @@ def test_product_types(self, product_type, email_subject):
"<tr><th>Successful Ingestion</th><td>1</td></tr>",
"<tr><th>Ingestion with Errors </th><td>0</td></tr>",
"<tr><th>Total data rows</th><td>1</td></tr>",
f"<p>The data ingestion has been run for product type <strong>{product_type}</strong>. "
# pylint: disable=line-too-long
f"<p>The data ingestion has been run for product type <strong>{product_type}</strong> and product source <strong>{self.source.name}</strong>. "
f"See below for the ingestion stats.</p>",
]
)
Expand All @@ -506,7 +509,7 @@ def test_email_with_file_attachment(self):
Verify the email has the file attachment.
"""
emails.send_ingestion_email(
self.partner, self.EMAIL_SUBJECT, self.USER_EMAILS, self.EXEC_ED_PRODUCT,
self.partner, self.EMAIL_SUBJECT, self.USER_EMAILS, self.EXEC_ED_PRODUCT, self.source,
{
**self._get_base_ingestion_stats(),
'total_products_count': 1,
Expand All @@ -528,7 +531,7 @@ def test_email_no_ingestion_failure(self):
Verify the email content for no ingestion failure.
"""
emails.send_ingestion_email(
self.partner, self.EMAIL_SUBJECT, self.USER_EMAILS, self.EXEC_ED_PRODUCT,
self.partner, self.EMAIL_SUBJECT, self.USER_EMAILS, self.EXEC_ED_PRODUCT, self.source,
{
**self._get_base_ingestion_stats(),
'total_products_count': 1,
Expand All @@ -551,7 +554,7 @@ def test_email_new_products(self):
uuid = str(uuid4())
url_slug = 'course-slug-1'
emails.send_ingestion_email(
self.partner, self.EMAIL_SUBJECT, self.USER_EMAILS, self.EXEC_ED_PRODUCT,
self.partner, self.EMAIL_SUBJECT, self.USER_EMAILS, self.EXEC_ED_PRODUCT, self.source,
{
**self._get_base_ingestion_stats(),
'total_products_count': 1,
Expand Down Expand Up @@ -586,7 +589,7 @@ def test_email_new_exec_ed_products(self):
uuid = str(uuid4())
url_slug = 'course-slug-1'
emails.send_ingestion_email(
self.partner, self.EMAIL_SUBJECT, self.USER_EMAILS, self.EXEC_ED_PRODUCT,
self.partner, self.EMAIL_SUBJECT, self.USER_EMAILS, self.EXEC_ED_PRODUCT, self.source,
{
**self._get_base_ingestion_stats(),
'total_products_count': 3,
Expand Down Expand Up @@ -634,7 +637,7 @@ def test_email_ingestion_failures(self):
Verify the email content for the ingestion failures.
"""
emails.send_ingestion_email(
self.partner, self.EMAIL_SUBJECT, self.USER_EMAILS, self.EXEC_ED_PRODUCT,
self.partner, self.EMAIL_SUBJECT, self.USER_EMAILS, self.EXEC_ED_PRODUCT, self.source,
{
**self._get_base_ingestion_stats(),
'total_products_count': 1,
Expand All @@ -661,7 +664,7 @@ def test_email_ingestion_failures(self):

class TestSlugUpdatesEmail(TestCase):
"""
Test suite for send_ingestion_email.
Test suite for slugs_update email
"""
EMAIL_SUBJECT = 'Migrate Course Slugs Summary Report'
USER_EMAILS = ['[email protected]']
Expand Down

0 comments on commit e279ca3

Please sign in to comment.