Commit 526bc963 by Adam

Merge pull request #6231 from edx/adam/fix-unenroll-enroll-inst-dash

fix enrollment issue in instructor dash (ECOM-776)
parents 84a2eeb8 c1dd64c0
......@@ -35,7 +35,7 @@ class EmailEnrollmentState(object):
exists_ce = False
full_name = None
ceas = CourseEnrollmentAllowed.objects.filter(course_id=course_id, email=email).all()
exists_allowed = len(ceas) > 0
exists_allowed = ceas.exists()
state_auto_enroll = exists_allowed and ceas[0].auto_enroll
self.user = exists_user
......@@ -88,7 +88,13 @@ def enroll_email(course_id, student_email, auto_enroll=False, email_students=Fal
previous_state = EmailEnrollmentState(course_id, student_email)
if previous_state.user:
CourseEnrollment.enroll_by_email(student_email, course_id, previous_state.mode)
# if the student is currently unenrolled, don't enroll them in their
# previous mode
course_mode = u"honor"
if previous_state.enrollment:
course_mode = previous_state.mode
CourseEnrollment.enroll_by_email(student_email, course_id, course_mode)
if email_students:
email_params['message'] = 'enrolled_enroll'
email_params['email_address'] = student_email
......
......@@ -1077,23 +1077,53 @@ class TestInstructorAPIEnrollment(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.assertEqual(course_enrollment.mode, u'verified')
# now re-enroll the student through the instructor dash
self._change_student_enrollment(self.enrolled_student, self.course, 'enroll')
# affirm that the student is still in "verified" mode
course_enrollment = CourseEnrollment.objects.get(
user=self.enrolled_student, course_id=self.course.id
)
self.assertEqual(course_enrollment.mode, u"verified")
def test_unenroll_and_enroll_verified(self):
"""
Test that unenrolling and enrolling a student from a verified track
results in that student being in an honor track
"""
course_enrollment = CourseEnrollment.objects.get(
user=self.enrolled_student, course_id=self.course.id
)
# upgrade enrollment
course_enrollment.mode = u'verified'
course_enrollment.save()
self.assertEqual(course_enrollment.mode, u'verified')
self._change_student_enrollment(self.enrolled_student, self.course, 'unenroll')
self._change_student_enrollment(self.enrolled_student, self.course, 'enroll')
course_enrollment = CourseEnrollment.objects.get(
user=self.enrolled_student, course_id=self.course.id
)
self.assertEqual(course_enrollment.mode, u'honor')
def _change_student_enrollment(self, user, course, action):
"""
Helper function that posts to 'students_update_enrollment' to change
a student's enrollment
"""
url = reverse(
'students_update_enrollment',
kwargs={'course_id': self.course.id.to_deprecated_string()},
kwargs={'course_id': course.id.to_deprecated_string()},
)
params = {
'identifiers': self.enrolled_student.email,
'action': 'enroll',
'identifiers': user.email,
'action': action,
'email_students': True,
}
response = self.client.post(url, params)
self.assertEqual(response.status_code, 200)
# affirm that the student is still in "verified" mode
course_enrollment = CourseEnrollment.objects.get(
user=self.enrolled_student, course_id=self.course.id
)
self.assertEqual(course_enrollment.mode, u"verified")
return response
@ddt.ddt
......
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