Merge pull request #12934 from open-craft/jill/fix-bulk-email-url-scheme
Use appropriate URL scheme for bulk emails
This commit is contained in:
@@ -100,18 +100,18 @@ def _get_course_email_context(course):
|
||||
course_id = course.id.to_deprecated_string()
|
||||
course_title = course.display_name
|
||||
course_end_date = get_default_time_display(course.end)
|
||||
course_url = 'https://{}{}'.format(
|
||||
settings.SITE_NAME,
|
||||
course_url = '{}{}'.format(
|
||||
settings.LMS_ROOT_URL,
|
||||
reverse('course_root', kwargs={'course_id': course_id})
|
||||
)
|
||||
image_url = u'https://{}{}'.format(settings.SITE_NAME, course_image_url(course))
|
||||
image_url = u'{}{}'.format(settings.LMS_ROOT_URL, course_image_url(course))
|
||||
email_context = {
|
||||
'course_title': course_title,
|
||||
'course_url': course_url,
|
||||
'course_image_url': image_url,
|
||||
'course_end_date': course_end_date,
|
||||
'account_settings_url': 'https://{}{}'.format(settings.SITE_NAME, reverse('account_settings')),
|
||||
'email_settings_url': 'https://{}{}'.format(settings.SITE_NAME, reverse('dashboard')),
|
||||
'account_settings_url': '{}{}'.format(settings.LMS_ROOT_URL, reverse('account_settings')),
|
||||
'email_settings_url': '{}{}'.format(settings.LMS_ROOT_URL, reverse('dashboard')),
|
||||
'platform_name': configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME),
|
||||
}
|
||||
return email_context
|
||||
|
||||
@@ -16,7 +16,7 @@ from django.core.management import call_command
|
||||
from django.test.utils import override_settings
|
||||
|
||||
from bulk_email.models import Optout, BulkEmailFlag
|
||||
from bulk_email.tasks import _get_source_address
|
||||
from bulk_email.tasks import _get_source_address, _get_course_email_context
|
||||
from openedx.core.djangoapps.course_groups.models import CourseCohort
|
||||
from openedx.core.djangoapps.course_groups.cohorts import add_user_to_cohort
|
||||
from courseware.tests.factories import StaffFactory, InstructorFactory
|
||||
@@ -475,3 +475,60 @@ class TestEmailSendFromDashboard(EmailSendFromDashboardTestCase):
|
||||
|
||||
message_body = mail.outbox[0].body
|
||||
self.assertIn(uni_message, message_body)
|
||||
|
||||
|
||||
class TestCourseEmailContext(SharedModuleStoreTestCase):
|
||||
"""
|
||||
Test the course email context hash used to send bulk emails.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
"""
|
||||
Create a course shared by all tests.
|
||||
"""
|
||||
super(TestCourseEmailContext, cls).setUpClass()
|
||||
cls.course_title = u"Финансовое программирование и политика, часть 1: макроэкономические счета и анализ"
|
||||
cls.course_org = 'IMF'
|
||||
cls.course_number = "FPP.1x"
|
||||
cls.course_run = "2016"
|
||||
cls.course = CourseFactory.create(
|
||||
display_name=cls.course_title,
|
||||
org=cls.course_org,
|
||||
number=cls.course_number,
|
||||
run=cls.course_run,
|
||||
)
|
||||
|
||||
def verify_email_context(self, email_context, scheme):
|
||||
"""
|
||||
This test tests that the bulk email context uses http or https urls as appropriate.
|
||||
"""
|
||||
self.assertEquals(email_context['platform_name'], 'edX')
|
||||
self.assertEquals(email_context['course_title'], self.course_title)
|
||||
self.assertEquals(email_context['course_url'],
|
||||
'{}://edx.org/courses/{}/{}/{}/'.format(scheme,
|
||||
self.course_org,
|
||||
self.course_number,
|
||||
self.course_run))
|
||||
self.assertEquals(email_context['course_image_url'],
|
||||
'{}://edx.org/c4x/{}/{}/asset/images_course_image.jpg'.format(scheme,
|
||||
self.course_org,
|
||||
self.course_number))
|
||||
self.assertEquals(email_context['email_settings_url'], '{}://edx.org/dashboard'.format(scheme))
|
||||
self.assertEquals(email_context['account_settings_url'], '{}://edx.org/account/settings'.format(scheme))
|
||||
|
||||
@override_settings(LMS_ROOT_URL="http://edx.org")
|
||||
def test_insecure_email_context(self):
|
||||
"""
|
||||
This test tests that the bulk email context uses http urls
|
||||
"""
|
||||
email_context = _get_course_email_context(self.course)
|
||||
self.verify_email_context(email_context, 'http')
|
||||
|
||||
@override_settings(LMS_ROOT_URL="https://edx.org")
|
||||
def test_secure_email_context(self):
|
||||
"""
|
||||
This test tests that the bulk email context uses https urls
|
||||
"""
|
||||
email_context = _get_course_email_context(self.course)
|
||||
self.verify_email_context(email_context, 'https')
|
||||
|
||||
Reference in New Issue
Block a user