'Server-to-server calls should be allowed to change the mode of any
enrollment, as long as the enrollment is not being deactivated during
the same call (this is assumed to be an error on the client\'s side).'

@ddt.data(*itertools.product((CourseMode.HONOR, CourseMode.VERIFIED), (CourseMode.HONOR, CourseMode.VERIFIED), (True, False), (True, False)))
@ddt.unpack
def test_change_mode_from_server(self, old_mode, new_mode, old_is_active, new_is_active):

    for mode in [CourseMode.HONOR, CourseMode.VERIFIED]:
        CourseModeFactory.create(course_id=self.course.id, mode_slug=mode, mode_display_name=mode)
    self.assert_enrollment_status(as_server=True, mode=old_mode, is_active=old_is_active)
    (course_mode, is_active) = CourseEnrollment.enrollment_mode_for_user(self.user, self.course.id)
    self.assertEqual(is_active, old_is_active)
    self.assertEqual(course_mode, old_mode)
    expected_status = (status.HTTP_400_BAD_REQUEST if ((old_mode != new_mode) and (old_is_active != new_is_active) and (not new_is_active)) else status.HTTP_200_OK)
    response = self.assert_enrollment_status(as_server=True, mode=new_mode, is_active=new_is_active, expected_status=expected_status)
    (course_mode, is_active) = CourseEnrollment.enrollment_mode_for_user(self.user, self.course.id)
    if (expected_status == status.HTTP_400_BAD_REQUEST):
        self.assertEqual(is_active, old_is_active)
        self.assertEqual(course_mode, old_mode)
        self.assertRegexpMatches(json.loads(response.content)['message'], 'Enrollment    mode    mismatch')
    else:
        self.assertEqual(is_active, new_is_active)
        self.assertEqual(course_mode, new_mode)
