Do not show Currencies: usd in bulk email task history Sent To:

This is a bad course team experience that when they send email to Audit track learners, `send to` includes currency (usd) which is set default. This PR fixes the bug and will not include currency with `audit` or `honor` enrollment tracks.
EDUCATOR-2489
This commit is contained in:
Awais Jibran
2018-03-09 16:42:40 +05:00
parent 89d8e7b539
commit 5eb176039c
2 changed files with 36 additions and 9 deletions

View File

@@ -198,14 +198,12 @@ class CourseModeTarget(Target):
return "{}-{}".format(self.target_type, self.track.mode_slug) # pylint: disable=no-member
def long_display(self):
all_modes = CourseMode.objects.filter(
course_id=self.track.course_id,
mode_slug=self.track.mode_slug, # pylint: disable=no-member
)
return "Course mode: {}, Currencies: {}".format(
self.track.mode_display_name, # pylint: disable=no-member
", ".join([mode.currency for mode in all_modes])
)
course_mode = self.track
long_course_mode_display = 'Course mode: {}'.format(course_mode.mode_display_name)
if course_mode.mode_slug not in CourseMode.AUDIT_MODES:
mode_currency = 'Currency: {}'.format(course_mode.currency)
long_course_mode_display = '{}, {}'.format(long_course_mode_display, mode_currency)
return long_course_mode_display
@classmethod
def ensure_valid_mode(cls, mode_slug, course_id):

View File

@@ -100,7 +100,36 @@ class CourseEmailTest(ModuleStoreTestCase):
target = email.targets.all()[0]
self.assertEqual(target.target_type, SEND_TO_TRACK)
self.assertEqual(target.short_display(), 'track-test')
self.assertEqual(target.long_display(), 'Course mode: Test, Currencies: usd')
self.assertEqual(target.long_display(), 'Course mode: Test, Currency: usd')
@ddt.data(
CourseMode.AUDIT,
CourseMode.HONOR,
)
def test_track_target_with_free_mode(self, free_mode):
"""
Tests that when emails are sent to a free track the track display
should not contain currency.
"""
course = CourseFactory.create()
mode_display_name = free_mode.capitalize
course_id = course.id
sender = UserFactory.create()
to_option = 'track:{}'.format(free_mode)
subject = "dummy subject"
html_message = "<html>dummy message</html>"
CourseMode.objects.create(
mode_slug=free_mode,
mode_display_name=mode_display_name,
course_id=course_id,
)
email = CourseEmail.create(course_id, sender, [to_option], subject, html_message)
self.assertEqual(len(email.targets.all()), 1)
target = email.targets.all()[0]
self.assertEqual(target.target_type, SEND_TO_TRACK)
self.assertEqual(target.short_display(), 'track-{}'.format(free_mode))
self.assertEqual(target.long_display(), 'Course mode: {}'.format(mode_display_name))
def test_cohort_target(self):
course_id = CourseKey.from_string('abc/123/doremi')