Fix course urls in enrollment emails (LMS-2217)
This commit is contained in:
@@ -403,14 +403,13 @@ class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
"at edx.org by a member of the course staff. "
|
||||
"The course should now appear on your edx.org dashboard.\n\n"
|
||||
"To start accessing course materials, please visit "
|
||||
"https://edx.org/courses/MITx/999/Robot_Super_Course\n\n----\n"
|
||||
"https://edx.org/courses/MITx/999/Robot_Super_Course/\n\n----\n"
|
||||
"This email was automatically sent from edx.org to NotEnrolled Student"
|
||||
)
|
||||
|
||||
def test_enroll_with_email_not_registered(self):
|
||||
url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id})
|
||||
response = self.client.get(url, {'emails': self.notregistered_email, 'action': 'enroll', 'email_students': True})
|
||||
print "type(self.notregistered_email): {}".format(type(self.notregistered_email))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# Check the outbox
|
||||
@@ -429,6 +428,22 @@ class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
"This email was automatically sent from edx.org to robot-not-an-email-yet@robot.org"
|
||||
)
|
||||
|
||||
def test_enroll_email_not_registered_mktgsite(self):
|
||||
url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id})
|
||||
# Try with marketing site enabled
|
||||
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
|
||||
response = self.client.get(url, {'emails': self.notregistered_email, 'action': 'enroll', 'email_students': True})
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(
|
||||
mail.outbox[0].body,
|
||||
"Dear student,\n\nYou have been invited to join Robot Super Course at edx.org by a member of the course staff.\n\n"
|
||||
"To finish your registration, please visit https://edx.org/register and fill out the registration form "
|
||||
"making sure to use robot-not-an-email-yet@robot.org in the E-mail field.\n"
|
||||
"You can then enroll in Robot Super Course.\n\n----\n"
|
||||
"This email was automatically sent from edx.org to robot-not-an-email-yet@robot.org"
|
||||
)
|
||||
|
||||
def test_enroll_with_email_not_registered_autoenroll(self):
|
||||
url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id})
|
||||
response = self.client.get(url, {'emails': self.notregistered_email, 'action': 'enroll', 'email_students': True, 'auto_enroll': True})
|
||||
@@ -587,12 +602,10 @@ class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
|
||||
@patch('instructor.enrollment.uses_shib')
|
||||
def test_enroll_with_email_not_registered_with_shib(self, mock_uses_shib):
|
||||
|
||||
mock_uses_shib.return_value = True
|
||||
|
||||
url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id})
|
||||
response = self.client.get(url, {'emails': self.notregistered_email, 'action': 'enroll', 'email_students': True})
|
||||
print "type(self.notregistered_email): {}".format(type(self.notregistered_email))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# Check the outbox
|
||||
@@ -601,6 +614,7 @@ class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
mail.outbox[0].subject,
|
||||
'You have been invited to register for Robot Super Course'
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
mail.outbox[0].body,
|
||||
"Dear student,\n\nYou have been invited to join Robot Super Course at edx.org by a member of the course staff.\n\n"
|
||||
@@ -608,6 +622,22 @@ class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
"This email was automatically sent from edx.org to robot-not-an-email-yet@robot.org"
|
||||
)
|
||||
|
||||
@patch('instructor.enrollment.uses_shib')
|
||||
def test_enroll_email_not_registered_shib_mktgsite(self, mock_uses_shib):
|
||||
mock_uses_shib.return_value = True
|
||||
|
||||
url = reverse('students_update_enrollment', kwargs={'course_id': self.course.id})
|
||||
# Try with marketing site enabled
|
||||
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
|
||||
response = self.client.get(url, {'emails': self.notregistered_email, 'action': 'enroll', 'email_students': True})
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(
|
||||
mail.outbox[0].body,
|
||||
"Dear student,\n\nYou have been invited to join Robot Super Course at edx.org by a member of the course staff.\n\n----\n"
|
||||
"This email was automatically sent from edx.org to robot-not-an-email-yet@robot.org"
|
||||
)
|
||||
|
||||
@patch('instructor.enrollment.uses_shib')
|
||||
def test_enroll_with_email_not_registered_with_shib_autoenroll(self, mock_uses_shib):
|
||||
|
||||
@@ -624,10 +654,11 @@ class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
mail.outbox[0].subject,
|
||||
'You have been invited to register for Robot Super Course'
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
mail.outbox[0].body,
|
||||
"Dear student,\n\nYou have been invited to join Robot Super Course at edx.org by a member of the course staff.\n\n"
|
||||
"To access the course visit https://edx.org/courses/MITx/999/Robot_Super_Course and login.\n\n----\n"
|
||||
"To access the course visit https://edx.org/courses/MITx/999/Robot_Super_Course/ and login.\n\n----\n"
|
||||
"This email was automatically sent from edx.org to robot-not-an-email-yet@robot.org"
|
||||
)
|
||||
|
||||
@@ -721,6 +752,7 @@ class TestInstructorAPIBulkBetaEnrollment(ModuleStoreTestCase, LoginEnrollmentTe
|
||||
mail.outbox[0].subject,
|
||||
'You have been invited to a beta test for Robot Super Course'
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
mail.outbox[0].body,
|
||||
u"Dear {0}\n\nYou have been invited to be a beta tester "
|
||||
@@ -733,6 +765,24 @@ class TestInstructorAPIBulkBetaEnrollment(ModuleStoreTestCase, LoginEnrollmentTe
|
||||
)
|
||||
)
|
||||
|
||||
def test_add_notenrolled_email_mktgsite(self):
|
||||
url = reverse('bulk_beta_modify_access', kwargs={'course_id': self.course.id})
|
||||
# Try with marketing site enabled
|
||||
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
|
||||
response = self.client.get(url, {'emails': self.notenrolled_student.email, 'action': 'add', 'email_students': True})
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(
|
||||
mail.outbox[0].body,
|
||||
u"Dear {0}\n\nYou have been invited to be a beta tester "
|
||||
"for Robot Super Course at edx.org by a member of the course staff.\n\n"
|
||||
"Visit edx.org to enroll in the course and begin the beta test.\n\n----\n"
|
||||
"This email was automatically sent from edx.org to {1}".format(
|
||||
self.notenrolled_student.profile.name,
|
||||
self.notenrolled_student.email
|
||||
)
|
||||
)
|
||||
|
||||
def test_enroll_with_email_not_registered(self):
|
||||
# User doesn't exist
|
||||
url = reverse('bulk_beta_modify_access', kwargs={'course_id': self.course.id})
|
||||
|
||||
@@ -3,15 +3,21 @@ Unit tests for instructor.enrollment methods.
|
||||
"""
|
||||
|
||||
import json
|
||||
import mock
|
||||
from abc import ABCMeta
|
||||
from courseware.models import StudentModule
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from student.tests.factories import UserFactory
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
|
||||
|
||||
from student.models import CourseEnrollment, CourseEnrollmentAllowed
|
||||
from instructor.enrollment import (
|
||||
EmailEnrollmentState,
|
||||
enroll_email,
|
||||
get_email_params,
|
||||
reset_student_attempts,
|
||||
send_beta_role_email,
|
||||
unenroll_email
|
||||
@@ -385,3 +391,46 @@ class TestSendBetaRoleEmail(TestCase):
|
||||
error_msg = "Unexpected action received '{}' - expected 'add' or 'remove'".format(bad_action)
|
||||
with self.assertRaisesRegexp(ValueError, error_msg):
|
||||
send_beta_role_email(bad_action, self.user, self.email_params)
|
||||
|
||||
|
||||
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
|
||||
class TestGetEmailParams(TestCase):
|
||||
"""
|
||||
Test what URLs the function get_email_params returns under different
|
||||
production-like conditions.
|
||||
"""
|
||||
def setUp(self):
|
||||
self.course = CourseFactory.create()
|
||||
|
||||
# Explicitly construct what we expect the course URLs to be
|
||||
site = settings.SITE_NAME
|
||||
self.course_url = u'https://{}/courses/{}/'.format(
|
||||
site,
|
||||
self.course.id
|
||||
)
|
||||
self.course_about_url = self.course_url + 'about'
|
||||
self.registration_url = u'https://{}/register'.format(
|
||||
site,
|
||||
)
|
||||
|
||||
def test_normal_params(self):
|
||||
# For a normal site, what do we expect to get for the URLs?
|
||||
# Also make sure `auto_enroll` is properly passed through.
|
||||
result = get_email_params(self.course, False)
|
||||
|
||||
self.assertEqual(result['auto_enroll'], False)
|
||||
self.assertEqual(result['course_about_url'], self.course_about_url)
|
||||
self.assertEqual(result['registration_url'], self.registration_url)
|
||||
self.assertEqual(result['course_url'], self.course_url)
|
||||
|
||||
def test_marketing_params(self):
|
||||
# For a site with a marketing front end, what do we expect to get for the URLs?
|
||||
# Also make sure `auto_enroll` is properly passed through.
|
||||
with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
|
||||
result = get_email_params(self.course, True)
|
||||
|
||||
self.assertEqual(result['auto_enroll'], True)
|
||||
# We should *not* get a course about url (LMS doesn't know what the marketing site URLs are)
|
||||
self.assertEqual(result['course_about_url'], None)
|
||||
self.assertEqual(result['registration_url'], self.registration_url)
|
||||
self.assertEqual(result['course_url'], self.course_url)
|
||||
|
||||
@@ -221,7 +221,7 @@ class TestInstructorEnrollsStudent(ModuleStoreTestCase, LoginEnrollmentTestCase)
|
||||
"at edx.org by a member of the course staff. "
|
||||
"The course should now appear on your edx.org dashboard.\n\n"
|
||||
"To start accessing course materials, please visit "
|
||||
"https://edx.org/courses/MITx/999/Robot_Super_Course\n\n"
|
||||
"https://edx.org/courses/MITx/999/Robot_Super_Course/\n\n"
|
||||
"----\nThis email was automatically sent from edx.org to Autoenrolled Test"
|
||||
)
|
||||
|
||||
@@ -322,7 +322,7 @@ class TestInstructorEnrollsStudent(ModuleStoreTestCase, LoginEnrollmentTestCase)
|
||||
"at edx.org by a member of the course staff. "
|
||||
"The course should now appear on your edx.org dashboard.\n\n"
|
||||
"To start accessing course materials, please visit "
|
||||
"https://edx.org/courses/MITx/999/Robot_Super_Course\n\n"
|
||||
"https://edx.org/courses/MITx/999/Robot_Super_Course/\n\n"
|
||||
"----\nThis email was automatically sent from edx.org to ShibTest Enrolled"
|
||||
)
|
||||
|
||||
@@ -335,7 +335,7 @@ class TestInstructorEnrollsStudent(ModuleStoreTestCase, LoginEnrollmentTestCase)
|
||||
"Dear student,\n\nYou have been invited to join "
|
||||
"Robot Super Course at edx.org by a member of the "
|
||||
"course staff.\n\n"
|
||||
"To access the course visit https://edx.org/courses/MITx/999/Robot_Super_Course and login.\n\n"
|
||||
"To access the course visit https://edx.org/courses/MITx/999/Robot_Super_Course/ and login.\n\n"
|
||||
"----\nThis email was automatically sent from edx.org to "
|
||||
"student5_1@test.com"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user