Commit e1573211 by Amir Qayyum Khan

Fixed CCX display name issue in enrollment/unenrollment email templates for non EDX members

parent c217d986
...@@ -37,9 +37,7 @@ from opaque_keys.edx.locations import SlashSeparatedCourseKey ...@@ -37,9 +37,7 @@ from opaque_keys.edx.locations import SlashSeparatedCourseKey
from submissions import api as sub_api from submissions import api as sub_api
from student.models import anonymous_id_for_user from student.models import anonymous_id_for_user
from xmodule.modulestore.tests.django_utils import ( from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE
ModuleStoreTestCase, SharedModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE
)
@attr('shard_1') @attr('shard_1')
...@@ -576,23 +574,27 @@ class TestSendBetaRoleEmail(TestCase): ...@@ -576,23 +574,27 @@ class TestSendBetaRoleEmail(TestCase):
@attr('shard_1') @attr('shard_1')
class TestGetEmailParamsCCX(ModuleStoreTestCase): class TestGetEmailParamsCCX(SharedModuleStoreTestCase):
""" """
Test what URLs the function get_email_params for CCX student enrollment. Test what URLs the function get_email_params for CCX student enrollment.
""" """
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
@classmethod
def setUpClass(cls):
super(TestGetEmailParamsCCX, cls).setUpClass()
cls.course = CourseFactory.create()
@patch.dict('django.conf.settings.FEATURES', {'CUSTOM_COURSES_EDX': True}) @patch.dict('django.conf.settings.FEATURES', {'CUSTOM_COURSES_EDX': True})
def setUp(self): def setUp(self):
super(TestGetEmailParamsCCX, self).setUp() super(TestGetEmailParamsCCX, self).setUp()
self.course = CourseFactory.create()
self.coach = AdminFactory.create() self.coach = AdminFactory.create()
role = CourseCcxCoachRole(self.course.id) role = CourseCcxCoachRole(self.course.id)
role.add_users(self.coach) role.add_users(self.coach)
self.ccx = CcxFactory(course_id=self.course.id, coach=self.coach) self.ccx = CcxFactory(course_id=self.course.id, coach=self.coach)
self.course_key = CCXLocator.from_course_locator(self.course.id, self.ccx.id) self.course_key = CCXLocator.from_course_locator(self.course.id, self.ccx.id)
# Explicitly construct what we expect the course URLs to be # Explicitly construct what we expect the course URLs to be
site = settings.SITE_NAME site = settings.SITE_NAME
self.course_url = u'https://{}/courses/{}/'.format( self.course_url = u'https://{}/courses/{}/'.format(
...@@ -600,9 +602,7 @@ class TestGetEmailParamsCCX(ModuleStoreTestCase): ...@@ -600,9 +602,7 @@ class TestGetEmailParamsCCX(ModuleStoreTestCase):
self.course_key self.course_key
) )
self.course_about_url = self.course_url + 'about' self.course_about_url = self.course_url + 'about'
self.registration_url = u'https://{}/register'.format( self.registration_url = u'https://{}/register'.format(site)
site,
)
@patch.dict('django.conf.settings.FEATURES', {'CUSTOM_COURSES_EDX': True}) @patch.dict('django.conf.settings.FEATURES', {'CUSTOM_COURSES_EDX': True})
def test_ccx_enrollment_email_params(self): def test_ccx_enrollment_email_params(self):
...@@ -683,10 +683,14 @@ class TestRenderMessageToString(SharedModuleStoreTestCase): ...@@ -683,10 +683,14 @@ class TestRenderMessageToString(SharedModuleStoreTestCase):
cls.subject_template = 'emails/enroll_email_allowedsubject.txt' cls.subject_template = 'emails/enroll_email_allowedsubject.txt'
cls.message_template = 'emails/enroll_email_allowedmessage.txt' cls.message_template = 'emails/enroll_email_allowedmessage.txt'
@patch.dict('django.conf.settings.FEATURES', {'CUSTOM_COURSES_EDX': True})
def setUp(self): def setUp(self):
super(TestRenderMessageToString, self).setUp() super(TestRenderMessageToString, self).setUp()
self.course_key = None coach = AdminFactory.create()
self.ccx = None role = CourseCcxCoachRole(self.course.id)
role.add_users(coach)
self.ccx = CcxFactory(course_id=self.course.id, coach=coach)
self.course_key = CCXLocator.from_course_locator(self.course.id, self.ccx.id)
def get_email_params(self): def get_email_params(self):
""" """
...@@ -702,12 +706,6 @@ class TestRenderMessageToString(SharedModuleStoreTestCase): ...@@ -702,12 +706,6 @@ class TestRenderMessageToString(SharedModuleStoreTestCase):
""" """
Returns a dictionary of parameters used to render an email for CCX. Returns a dictionary of parameters used to render an email for CCX.
""" """
coach = AdminFactory.create()
role = CourseCcxCoachRole(self.course.id)
role.add_users(coach)
self.ccx = CcxFactory(course_id=self.course.id, coach=coach)
self.course_key = CCXLocator.from_course_locator(self.course.id, self.ccx.id)
email_params = get_email_params( email_params = get_email_params(
self.course, self.course,
True, True,
...@@ -730,12 +728,10 @@ class TestRenderMessageToString(SharedModuleStoreTestCase): ...@@ -730,12 +728,10 @@ class TestRenderMessageToString(SharedModuleStoreTestCase):
language=language language=language
) )
def get_subject_and_message_ccx(self): def get_subject_and_message_ccx(self, subject_template, message_template):
""" """
Returns the subject and message rendered in the specified language for CCX. Returns the subject and message rendered in the specified language for CCX.
""" """
subject_template = 'emails/enroll_email_enrolledsubject.txt'
message_template = 'emails/enroll_email_enrolledmessage.txt'
return render_message_to_string( return render_message_to_string(
subject_template, subject_template,
message_template, message_template,
...@@ -758,11 +754,15 @@ class TestRenderMessageToString(SharedModuleStoreTestCase): ...@@ -758,11 +754,15 @@ class TestRenderMessageToString(SharedModuleStoreTestCase):
self.assertIn("You have been", message) self.assertIn("You have been", message)
@patch.dict('django.conf.settings.FEATURES', {'CUSTOM_COURSES_EDX': True}) @patch.dict('django.conf.settings.FEATURES', {'CUSTOM_COURSES_EDX': True})
def test_render_message_ccx(self): def test_render_enrollment_message_ccx_members(self):
""" """
Test email template renders for CCX. Test enrollment email template renders for CCX.
For EDX members.
""" """
subject, message = self.get_subject_and_message_ccx() subject_template = 'emails/enroll_email_enrolledsubject.txt'
message_template = 'emails/enroll_email_enrolledmessage.txt'
subject, message = self.get_subject_and_message_ccx(subject_template, message_template)
self.assertIn(self.ccx.display_name, subject) self.assertIn(self.ccx.display_name, subject)
self.assertIn(self.ccx.display_name, message) self.assertIn(self.ccx.display_name, message)
site = settings.SITE_NAME site = settings.SITE_NAME
...@@ -771,3 +771,45 @@ class TestRenderMessageToString(SharedModuleStoreTestCase): ...@@ -771,3 +771,45 @@ class TestRenderMessageToString(SharedModuleStoreTestCase):
self.course_key self.course_key
) )
self.assertIn(course_url, message) self.assertIn(course_url, message)
@patch.dict('django.conf.settings.FEATURES', {'CUSTOM_COURSES_EDX': True})
def test_render_unenrollment_message_ccx_members(self):
"""
Test unenrollment email template renders for CCX.
For EDX members.
"""
subject_template = 'emails/unenroll_email_subject.txt'
message_template = 'emails/unenroll_email_enrolledmessage.txt'
subject, message = self.get_subject_and_message_ccx(subject_template, message_template)
self.assertIn(self.ccx.display_name, subject)
self.assertIn(self.ccx.display_name, message)
@patch.dict('django.conf.settings.FEATURES', {'CUSTOM_COURSES_EDX': True})
def test_render_enrollment_message_ccx_non_members(self):
"""
Test enrollment email template renders for CCX.
For non EDX members.
"""
subject_template = 'emails/enroll_email_allowedsubject.txt'
message_template = 'emails/enroll_email_allowedmessage.txt'
subject, message = self.get_subject_and_message_ccx(subject_template, message_template)
self.assertIn(self.ccx.display_name, subject)
self.assertIn(self.ccx.display_name, message)
site = settings.SITE_NAME
registration_url = u'https://{}/register'.format(site)
self.assertIn(registration_url, message)
@patch.dict('django.conf.settings.FEATURES', {'CUSTOM_COURSES_EDX': True})
def test_render_unenrollment_message_ccx_non_members(self):
"""
Test unenrollment email template renders for CCX.
For non EDX members.
"""
subject_template = 'emails/unenroll_email_subject.txt'
message_template = 'emails/unenroll_email_allowedmessage.txt'
subject, message = self.get_subject_and_message_ccx(subject_template, message_template)
self.assertIn(self.ccx.display_name, subject)
self.assertIn(self.ccx.display_name, message)
...@@ -4,7 +4,7 @@ ${_("Dear student,")} ...@@ -4,7 +4,7 @@ ${_("Dear student,")}
${_("You have been invited to join {course_name} at {site_name} by a " ${_("You have been invited to join {course_name} at {site_name} by a "
"member of the course staff.").format( "member of the course staff.").format(
course_name=course.display_name_with_default, course_name=display_name or course.display_name_with_default,
site_name=site_name site_name=site_name
)} )}
% if is_shib_course: % if is_shib_course:
...@@ -26,13 +26,13 @@ ${_("To finish your registration, please visit {registration_url} and fill " ...@@ -26,13 +26,13 @@ ${_("To finish your registration, please visit {registration_url} and fill "
% if auto_enroll: % if auto_enroll:
${_("Once you have registered and activated your account, you will see " ${_("Once you have registered and activated your account, you will see "
"{course_name} listed on your dashboard.").format( "{course_name} listed on your dashboard.").format(
course_name=course.display_name_with_default course_name=display_name or course.display_name_with_default
)} )}
% elif course_about_url is not None: % elif course_about_url is not None:
${_("Once you have registered and activated your account, visit {course_about_url} " ${_("Once you have registered and activated your account, visit {course_about_url} "
"to join the course.").format(course_about_url=course_about_url)} "to join the course.").format(course_about_url=course_about_url)}
% else: % else:
${_("You can then enroll in {course_name}.").format(course_name=course.display_name_with_default)} ${_("You can then enroll in {course_name}.").format(course_name=display_name or course.display_name_with_default)}
% endif % endif
% endif % endif
......
<%! from django.utils.translation import ugettext as _ %> <%! from django.utils.translation import ugettext as _ %>
${_("You have been invited to register for {course_name}").format( ${_("You have been invited to register for {course_name}").format(
course_name=course.display_name_with_default course_name=display_name or course.display_name_with_default
)} )}
\ No newline at end of file
...@@ -4,7 +4,7 @@ ${_("Dear Student,")} ...@@ -4,7 +4,7 @@ ${_("Dear Student,")}
${_("You have been un-enrolled from course {course_name} by a member " ${_("You have been un-enrolled from course {course_name} by a member "
"of the course staff. Please disregard the invitation " "of the course staff. Please disregard the invitation "
"previously sent.").format(course_name=course.display_name_with_default)} "previously sent.").format(course_name=display_name or course.display_name_with_default)}
---- ----
${_("This email was automatically sent from {site_name} " ${_("This email was automatically sent from {site_name} "
......
...@@ -5,7 +5,7 @@ ${_("Dear {full_name}").format(full_name=full_name)} ...@@ -5,7 +5,7 @@ ${_("Dear {full_name}").format(full_name=full_name)}
${_("You have been un-enrolled in {course_name} at {site_name} by a member " ${_("You have been un-enrolled in {course_name} at {site_name} by a member "
"of the course staff. The course will no longer appear on your " "of the course staff. The course will no longer appear on your "
"{site_name} dashboard.").format( "{site_name} dashboard.").format(
course_name=course.display_name_with_default, site_name=site_name course_name=display_name or course.display_name_with_default, site_name=site_name
)} )}
${_("Your other courses have not been affected.")} ${_("Your other courses have not been affected.")}
......
<%! from django.utils.translation import ugettext as _ %> <%! from django.utils.translation import ugettext as _ %>
${_("You have been un-enrolled from {course_name}").format( ${_("You have been un-enrolled from {course_name}").format(
course_name=course.display_name_with_default course_name=display_name or course.display_name_with_default
)} )}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment