Skip to content

Commit

Permalink
subscription email language update (#1892)
Browse files Browse the repository at this point in the history
* using Learning resources as content type when there are multiple unique types

* updating unique resources list in loop
  • Loading branch information
shanbady authored Dec 10, 2024
1 parent a1613ab commit c5262d1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
8 changes: 6 additions & 2 deletions learning_resources_search/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,11 @@ def _generate_subscription_digest_subject(
"""
prefix = "" if shortform else "MIT Learn: "
resource_type = unique_resource_types.pop()
if len(unique_resource_types) == 1:
resource_type = unique_resource_types.pop()
else:
resource_type = "Learning Resource"

if sample_course["source_channel_type"] == "saved_search":
if shortform:
return f"New {resource_type}{pluralize(total_count)} from MIT Learn"
Expand Down Expand Up @@ -956,8 +960,8 @@ def attempt_send_digest_email_batch(user_template_items):
continue
user = User.objects.get(id=user_id)

unique_resource_types = set()
for group in template_data:
unique_resource_types = set()
total_count = len(template_data[group])
unique_resource_types.update(
[resource["resource_type"] for resource in template_data[group]]
Expand Down
30 changes: 30 additions & 0 deletions learning_resources_search/tasks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,36 @@ def test_subscription_digest_subject():
assert subject_line == "New courses from management"


def test_subscription_digest_subject_multiple_types():
"""
Test that when there are multiple unique resource types
we use Leaning Resource in the header
"""
resource_types = {"program"}
sample_course = {"source_channel_type": "topic", "resource_title": "robotics"}

subject_line = _generate_subscription_digest_subject(
sample_course,
"electronics",
resource_types,
total_count=1,
shortform=False,
)
assert subject_line == "MIT Learn: New program in electronics: robotics"

sample_course = {"source_channel_type": "podcast", "resource_title": "robotics"}
resource_types = {"program", "video", "podcast"}

subject_line = _generate_subscription_digest_subject(
sample_course,
"xpro",
resource_types,
total_count=9,
shortform=False,
)
assert subject_line == "MIT Learn: New Learning Resources from xpro: robotics"


def test_update_featured_rank(mocker, offeror_featured_lists):
"""The updated_featured_rank task should make the expected calls"""

Expand Down

0 comments on commit c5262d1

Please sign in to comment.