Exemplo n.º 1
0
def cohorting_settings(request, course_key_string):
    """
    The handler for verified track cohorting requests.
    This will raise 404 if user is not staff.

    Returns a JSON representation of whether or not the course has verified track cohorting enabled.
    The "verified_cohort_name" field will only be present if "enabled" is True.

    Example:
        >>> example = {
        >>>               "enabled": True,
        >>>               "verified_cohort_name" : "Micromasters"
        >>>           }
    """
    course_key = CourseKey.from_string(course_key_string)
    get_course_with_access(request.user, 'staff', course_key)

    settings = {}
    verified_track_cohort_enabled = VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(
        course_key)
    settings['enabled'] = verified_track_cohort_enabled
    if verified_track_cohort_enabled:
        settings[
            'verified_cohort_name'] = VerifiedTrackCohortedCourse.verified_cohort_name_for_course(
                course_key)

    return JsonResponse(settings)
Exemplo n.º 2
0
    def test_course_enabled(self):
        course_key = CourseKey.from_string(self.SAMPLE_COURSE)
        # Test when no configuration exists
        self.assertFalse(VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(course_key))

        # Enable for a course
        config = VerifiedTrackCohortedCourse.objects.create(course_key=course_key, enabled=True)
        config.save()
        self.assertTrue(VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(course_key))

        # Disable for the course
        config.enabled = False
        config.save()
        self.assertFalse(VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(course_key))
Exemplo n.º 3
0
    def test_automatic_cohorting_enabled(self):
        """
        If the VerifiedTrackCohortedCourse feature is enabled for a course (with course cohorting enabled
        with an existing verified cohort), enrollment in the verified track automatically moves learners
        into the verified cohort.
        """
        # Enable cohorting and create a verified cohort.
        self._enable_cohorting()
        self._create_verified_cohort()
        # Enable verified track cohorting feature
        self._enable_verified_track_cohorting()
        self.assertTrue(
            VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(
                self.course.id))
        self._enroll_in_course()

        self.assertEqual(2, self.mocked_celery_task.call_count)
        self.assertEqual(
            DEFAULT_COHORT_NAME,
            get_cohort(self.user, self.course.id, assign=False).name)

        self._upgrade_to_verified()
        self.assertEqual(4, self.mocked_celery_task.call_count)
        self.assertEqual(
            VERIFIED_COHORT_NAME,
            get_cohort(self.user, self.course.id, assign=False).name)
Exemplo n.º 4
0
 def test_verified_cohort_name(self):
     COHORT_NAME = 'verified cohort'
     course_key = CourseKey.from_string(self.SAMPLE_COURSE)
     config = VerifiedTrackCohortedCourse.objects.create(
         course_key=course_key, enabled=True, verified_cohort_name=COHORT_NAME
     )
     config.save()
     self.assertEqual(VerifiedTrackCohortedCourse.verified_cohort_name_for_course(course_key), COHORT_NAME)
Exemplo n.º 5
0
 def test_cohorting_enabled_course_not_cohorted(self, error_logger):
     """
     If the VerifiedTrackCohortedCourse feature is enabled for a course, but the course is not cohorted,
     an error is logged and enrollment mode changes do not move learners into a cohort.
     """
     # Enable verified track cohorting feature, but course has not been marked as cohorting.
     self._enable_verified_track_cohorting()
     self.assertTrue(VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(self.course.id))
     self._verify_no_automatic_cohorting()
     self.assertTrue(error_logger.called)
     self.assertIn("course is not cohorted", error_logger.call_args[0][0])
Exemplo n.º 6
0
 def test_automatic_cohorting_disabled(self, error_logger):
     """
     If the VerifiedTrackCohortedCourse feature is disabled for a course, enrollment mode changes do not move
     learners into a cohort.
     """
     # Enable cohorting and create a verified cohort.
     self._enable_cohorting()
     self._create_verified_cohort()
     # But do not enable the verified track cohorting feature.
     self.assertFalse(VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(self.course.id))
     self._verify_no_automatic_cohorting()
     # No logging occurs if feature is disabled for course.
     self.assertFalse(error_logger.called)
Exemplo n.º 7
0
 def test_cohorting_enabled_missing_verified_cohort(self, error_logger):
     """
     If the VerifiedTrackCohortedCourse feature is enabled for a course and the course is cohorted,
     but the course does not have a verified cohort, an error is logged and enrollment mode changes do not
     move learners into a cohort.
     """
     # Enable cohorting, but do not create the verified cohort.
     self._enable_cohorting()
     # Enable verified track cohorting feature
     self._enable_verified_track_cohorting()
     self.assertTrue(VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(self.course.id))
     self._verify_no_automatic_cohorting()
     self.assertTrue(error_logger.called)
     self.assertIn("course does not have a verified cohort", error_logger.call_args[0][0])
Exemplo n.º 8
0
def _section_send_email(course, access):
    """ Provide data for the corresponding bulk email section """
    course_key = course.id

    # Monkey-patch applicable_aside_types to return no asides for the duration of this render
    with patch.object(course.runtime, 'applicable_aside_types', null_applicable_aside_types):
        # This HtmlDescriptor is only being used to generate a nice text editor.
        html_module = HtmlDescriptor(
            course.system,
            DictFieldData({'data': ''}),
            ScopeIds(None, None, None, course_key.make_usage_key('html', 'fake'))
        )
        fragment = course.system.render(html_module, 'studio_view')
    fragment = wrap_xblock(
        'LmsRuntime', html_module, 'studio_view', fragment, None,
        extra_data={"course-id": unicode(course_key)},
        usage_id_serializer=lambda usage_id: quote_slashes(unicode(usage_id)),
        # Generate a new request_token here at random, because this module isn't connected to any other
        # xblock rendering.
        request_token=uuid.uuid1().get_hex()
    )
    cohorts = []
    if is_course_cohorted(course_key):
        cohorts = get_course_cohorts(course)
    course_modes = []
    from verified_track_content.models import VerifiedTrackCohortedCourse
    if not VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(course_key):
        course_modes = CourseMode.modes_for_course(course_key)
    email_editor = fragment.content
    section_data = {
        'section_key': 'send_email',
        'section_display_name': _('Email'),
        'access': access,
        'send_email': reverse('send_email', kwargs={'course_id': unicode(course_key)}),
        'editor': email_editor,
        'cohorts': cohorts,
        'course_modes': course_modes,
        'default_cohort_name': DEFAULT_COHORT_NAME,
        'list_instructor_tasks_url': reverse(
            'list_instructor_tasks', kwargs={'course_id': unicode(course_key)}
        ),
        'email_background_tasks_url': reverse(
            'list_background_email_tasks', kwargs={'course_id': unicode(course_key)}
        ),
        'email_content_history_url': reverse(
            'list_email_content', kwargs={'course_id': unicode(course_key)}
        ),
    }
    return section_data
Exemplo n.º 9
0
def _section_send_email(course, access):
    """ Provide data for the corresponding bulk email section """
    course_key = course.id

    # Monkey-patch applicable_aside_types to return no asides for the duration of this render
    with patch.object(course.runtime, 'applicable_aside_types', null_applicable_aside_types):
        # This HtmlDescriptor is only being used to generate a nice text editor.
        html_module = HtmlDescriptor(
            course.system,
            DictFieldData({'data': ''}),
            ScopeIds(None, None, None, course_key.make_usage_key('html', 'fake'))
        )
        fragment = course.system.render(html_module, 'studio_view')
    fragment = wrap_xblock(
        'LmsRuntime', html_module, 'studio_view', fragment, None,
        extra_data={"course-id": unicode(course_key)},
        usage_id_serializer=lambda usage_id: quote_slashes(unicode(usage_id)),
        # Generate a new request_token here at random, because this module isn't connected to any other
        # xblock rendering.
        request_token=uuid.uuid1().get_hex()
    )
    cohorts = []
    if is_course_cohorted(course_key):
        cohorts = get_course_cohorts(course)
    course_modes = []
    from verified_track_content.models import VerifiedTrackCohortedCourse
    if not VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(course_key):
        course_modes = CourseMode.modes_for_course(course_key, include_expired=True, only_selectable=False)
    email_editor = fragment.content
    section_data = {
        'section_key': 'send_email',
        'section_display_name': _('Email'),
        'access': access,
        'send_email': reverse('send_email', kwargs={'course_id': unicode(course_key)}),
        'editor': email_editor,
        'cohorts': cohorts,
        'course_modes': course_modes,
        'default_cohort_name': DEFAULT_COHORT_NAME,
        'list_instructor_tasks_url': reverse(
            'list_instructor_tasks', kwargs={'course_id': unicode(course_key)}
        ),
        'email_background_tasks_url': reverse(
            'list_background_email_tasks', kwargs={'course_id': unicode(course_key)}
        ),
        'email_content_history_url': reverse(
            'list_email_content', kwargs={'course_id': unicode(course_key)}
        ),
    }
    return section_data
Exemplo n.º 10
0
def cohorting_settings(request, course_key_string):
    """
    The handler for verified track cohorting requests.
    This will raise 404 if user is not staff.

    Returns a JSON representation of whether or not the course has verified track cohorting enabled.
    The "verified_cohort_name" field will only be present if "enabled" is True.

    Example:
        >>> example = {
        >>>               "enabled": True,
        >>>               "verified_cohort_name" : "Micromasters"
        >>>           }
    """
    course_key = CourseKey.from_string(course_key_string)
    get_course_with_access(request.user, 'staff', course_key)

    settings = {}
    verified_track_cohort_enabled = VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(course_key)
    settings['enabled'] = verified_track_cohort_enabled
    if verified_track_cohort_enabled:
        settings['verified_cohort_name'] = VerifiedTrackCohortedCourse.verified_cohort_name_for_course(course_key)

    return JsonResponse(settings)
Exemplo n.º 11
0
 def test_cohorting_enabled_missing_verified_cohort(self, error_logger):
     """
     If the VerifiedTrackCohortedCourse feature is enabled for a course and the course is cohorted,
     but the course does not have a verified cohort, an error is logged and enrollment mode changes do not
     move learners into a cohort.
     """
     # Enable cohorting, but do not create the verified cohort.
     self._enable_cohorting()
     # Enable verified track cohorting feature
     self._enable_verified_track_cohorting()
     self.assertTrue(VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(self.course.id))
     self._verify_no_automatic_cohorting()
     self.assertTrue(error_logger.called)
     error_message = "cohort named '%s' does not exist"
     self.assertIn(error_message, error_logger.call_args[0][0])
Exemplo n.º 12
0
 def test_cohorting_enabled_too_many_random_cohorts(self, error_logger):
     """
     If the VerifiedTrackCohortedCourse feature is enabled for a course and the course is cohorted,
     but the course has > 1 random cohorts, an error is logged and enrollment mode changes do not
     move learners into a cohort.
     """
     # Enable cohorting, and create the verified cohort.
     self._enable_cohorting()
     self._create_verified_cohort()
     # Create two random cohorts.
     self._create_named_random_cohort("Random 1")
     self._create_named_random_cohort("Random 2")
     # Enable verified track cohorting feature
     self._enable_verified_track_cohorting()
     self.assertTrue(VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(self.course.id))
     self._verify_no_automatic_cohorting()
     self.assertTrue(error_logger.called)
     error_message = "course does not have exactly one default cohort"
     self.assertIn(error_message, error_logger.call_args[0][0])
Exemplo n.º 13
0
    def test_automatic_cohorting_enabled(self):
        """
        If the VerifiedTrackCohortedCourse feature is enabled for a course (with course cohorting enabled
        with an existing verified cohort), enrollment in the verified track automatically moves learners
        into the verified cohort.
        """
        # Enable cohorting and create a verified cohort.
        self._enable_cohorting()
        self._create_verified_cohort()
        # Enable verified track cohorting feature
        self._enable_verified_track_cohorting()
        self.assertTrue(VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(self.course.id))
        self._enroll_in_course()

        self.assertEqual(2, self.mocked_celery_task.call_count)
        self.assertEqual(DEFAULT_COHORT_NAME, get_cohort(self.user, self.course.id, assign=False).name)

        self._upgrade_to_verified()
        self.assertEqual(4, self.mocked_celery_task.call_count)
        self.assertEqual(DEFAULT_VERIFIED_COHORT_NAME, get_cohort(self.user, self.course.id, assign=False).name)
Exemplo n.º 14
0
 def test_cohorting_enabled_too_many_random_cohorts(self, error_logger):
     """
     If the VerifiedTrackCohortedCourse feature is enabled for a course and the course is cohorted,
     but the course has > 1 random cohorts, an error is logged and enrollment mode changes do not
     move learners into a cohort.
     """
     # Enable cohorting, and create the verified cohort.
     self._enable_cohorting()
     self._create_verified_cohort()
     # Create two random cohorts.
     self._create_named_random_cohort("Random 1")
     self._create_named_random_cohort("Random 2")
     # Enable verified track cohorting feature
     self._enable_verified_track_cohorting()
     self.assertTrue(
         VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(
             self.course.id))
     self._verify_no_automatic_cohorting()
     self.assertTrue(error_logger.called)
     error_message = "course does not have exactly one default cohort"
     self.assertIn(error_message, error_logger.call_args[0][0])
Exemplo n.º 15
0
 def test_unset_verified_cohort_name(self):
     fake_course_id = 'fake/course/key'
     course_key = CourseKey.from_string(fake_course_id)
     self.assertEqual(
         VerifiedTrackCohortedCourse.verified_cohort_name_for_course(
             course_key), None)
Exemplo n.º 16
0
 def test_unset_verified_cohort_name(self):
     fake_course_id = 'fake/course/key'
     course_key = CourseKey.from_string(fake_course_id)
     self.assertEqual(VerifiedTrackCohortedCourse.verified_cohort_name_for_course(course_key), None)