Пример #1
0
 def test_add_course_content_milestone(self):
     """ Unit Test: test_add_course_content_milestone """
     with self.assertNumQueries(3):
         api.add_course_content_milestone(
             self.test_course_key,
             self.test_content_key,
             self.relationship_types['REQUIRES'],
             self.test_milestone
         )
     requirer_milestones = api.get_course_content_milestones(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES']
     )
     self.assertEqual(len(requirer_milestones), 1)
     with self.assertNumQueries(3):
         api.add_course_content_milestone(
             self.test_prerequisite_course_key,
             self.test_content_key,
             self.relationship_types['FULFILLS'],
             self.test_milestone,
             {'min_score': 80}
         )
     fulfiller_milestones = api.get_course_content_milestones(
         self.test_prerequisite_course_key,
         self.test_content_key,
         self.relationship_types['FULFILLS']
     )
     self.assertEqual(len(fulfiller_milestones), 1)
Пример #2
0
 def test_remove_course_content_milestone(self):
     """ Unit Test: test_remove_course_content_milestone """
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone
     )
     requirer_milestones = api.get_course_content_milestones(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES']
     )
     self.assertEqual(len(requirer_milestones), 1)
     with self.assertNumQueries(2):
         api.remove_course_content_milestone(
             self.test_course_key,
             self.test_content_key,
             self.test_milestone
         )
     requirer_milestones = api.get_course_content_milestones(
         self.test_course_key,
         self.test_content_key
     )
     self.assertEqual(len(requirer_milestones), 0)
def get_course_content_milestones(course_id, content_id=None, relationship='requires', user_id=None):
    """
    Client API operation adapter/wrapper
    Uses the request cache to store all of a user's
    milestones

    Returns all content blocks in a course if content_id is None, otherwise it just returns that
    specific content block.
    """
    if not settings.FEATURES.get('MILESTONES_APP'):
        return []

    if user_id is None:
        return milestones_api.get_course_content_milestones(course_id, content_id, relationship)

    request_cache_dict = get_cache(REQUEST_CACHE_NAME)
    if user_id not in request_cache_dict:
        request_cache_dict[user_id] = {}

    if relationship not in request_cache_dict[user_id]:
        request_cache_dict[user_id][relationship] = milestones_api.get_course_content_milestones(
            course_key=course_id,
            relationship=relationship,
            user={"id": user_id}
        )

    if content_id is None:
        return request_cache_dict[user_id][relationship]

    return [m for m in request_cache_dict[user_id][relationship] if m['content_id'] == six.text_type(content_id)]
def get_course_content_milestones(course_id,
                                  content_id,
                                  relationship,
                                  user_id=None):
    """
    Client API operation adapter/wrapper
    Uses the request cache to store all of a user's
    milestones
    """
    if not settings.FEATURES.get('MILESTONES_APP'):
        return []

    if user_id is None:
        return milestones_api.get_course_content_milestones(
            course_id, content_id, relationship)

    request_cache_dict = request_cache.get_cache(REQUEST_CACHE_NAME)
    if user_id not in request_cache_dict:
        request_cache_dict[user_id] = {}

    if relationship not in request_cache_dict[user_id]:
        request_cache_dict[user_id][
            relationship] = milestones_api.get_course_content_milestones(
                course_key=course_id,
                relationship=relationship,
                user={"id": user_id})

    return [
        m for m in request_cache_dict[user_id][relationship]
        if m['content_id'] == unicode(content_id)
    ]
Пример #5
0
    def test_remove_content_references(self):
        """ Unit Test: test_remove_content_references """
        # Add a course dependency on the test milestone
        api.add_course_milestone(
            self.test_course_key,
            self.relationship_types['REQUIRES'],
            self.test_milestone
        )
        self.assertEqual(len(api.get_course_milestones(self.test_course_key)), 1)

        # Add a content fulfillment for the test milestone
        api.add_course_content_milestone(
            self.test_course_key,
            self.test_content_key,
            self.relationship_types['FULFILLS'],
            self.test_milestone
        )
        milestones = api.get_course_content_milestones(self.test_course_key, self.test_content_key)
        self.assertEqual(len(milestones), 1)

        # Remove the content dependency
        with self.assertNumQueries(2):
            api.remove_content_references(self.test_content_key)
        milestones = api.get_course_content_milestones(self.test_course_key, self.test_content_key)
        self.assertEqual(len(milestones), 0)
Пример #6
0
def get_course_content_milestones(course_id, content_id=None, relationship='requires', user_id=None):
    """
    Client API operation adapter/wrapper
    Uses the request cache to store all of a user's
    milestones

    Returns all content blocks in a course if content_id is None, otherwise it just returns that
    specific content block.
    """
    if not ENABLE_MILESTONES_APP.is_enabled():
        return []

    if user_id is None:
        return milestones_api.get_course_content_milestones(course_id, content_id, relationship)

    request_cache_dict = get_cache(REQUEST_CACHE_NAME)
    if user_id not in request_cache_dict:
        request_cache_dict[user_id] = {}

    if relationship not in request_cache_dict[user_id]:
        request_cache_dict[user_id][relationship] = milestones_api.get_course_content_milestones(
            course_key=course_id,
            relationship=relationship,
            user={"id": user_id}
        )

    if content_id is None:
        return request_cache_dict[user_id][relationship]

    return [m for m in request_cache_dict[user_id][relationship] if m['content_id'] == six.text_type(content_id)]
Пример #7
0
 def _fulfill_content_milestones(user, course_key, content_key):
     """
     Internal helper to handle milestone fulfillments for the specified content module
     """
     # Fulfillment Use Case: Entrance Exam
     # If this module is part of an entrance exam, we'll need to see if the student
     # has reached the point at which they can collect the associated milestone
     if settings.FEATURES.get('ENTRANCE_EXAMS', False):
         course = modulestore().get_course(course_key)
         content = modulestore().get_item(content_key)
         entrance_exam_enabled = getattr(course, 'entrance_exam_enabled',
                                         False)
         in_entrance_exam = getattr(content, 'in_entrance_exam', False)
         if entrance_exam_enabled and in_entrance_exam:
             exam_pct = _calculate_entrance_exam_score(user, course)
             if exam_pct >= course.entrance_exam_minimum_score_pct:
                 exam_key = UsageKey.from_string(course.entrance_exam_id)
                 relationship_types = milestones_api.get_milestone_relationship_types(
                 )
                 content_milestones = milestones_api.get_course_content_milestones(
                     course_key,
                     exam_key,
                     relationship=relationship_types['FULFILLS'])
                 # Add each milestone to the user's set...
                 user = {'id': user.id}
                 for milestone in content_milestones:
                     milestones_api.add_user_milestone(user, milestone)
Пример #8
0
 def test_add_course_content_milestone_inactive_to_active_update_requirements(self):
     """ Unit Test: test_add_course_content_milestone_inactive_to_active_update_requirement """
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone,
         {'min_score': 60}
     )
     api.remove_course_content_milestone(
         self.test_course_key,
         self.test_content_key,
         self.test_milestone
     )
     with self.assertNumQueries(3):
         api.add_course_content_milestone(
             self.test_course_key,
             self.test_content_key,
             self.relationship_types['REQUIRES'],
             self.test_milestone,
             {'min_score': 80}
         )
     milestone = api.get_course_content_milestones(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES']
     )
     for m in milestone:
         self.assertEqual(m['requirements'], {'min_score': 80})
Пример #9
0
 def _fulfill_content_milestones(user, course_key, content_key):
     """
     Internal helper to handle milestone fulfillments for the specified content module
     """
     # Fulfillment Use Case: Entrance Exam
     # If this module is part of an entrance exam, we'll need to see if the student
     # has reached the point at which they can collect the associated milestone
     if settings.FEATURES.get('ENTRANCE_EXAMS', False):
         course = modulestore().get_course(course_key)
         content = modulestore().get_item(content_key)
         entrance_exam_enabled = getattr(course, 'entrance_exam_enabled', False)
         in_entrance_exam = getattr(content, 'in_entrance_exam', False)
         if entrance_exam_enabled and in_entrance_exam:
             exam_pct = _calculate_entrance_exam_score(user, course)
             if exam_pct >= course.entrance_exam_minimum_score_pct:
                 exam_key = UsageKey.from_string(course.entrance_exam_id)
                 relationship_types = milestones_api.get_milestone_relationship_types()
                 content_milestones = milestones_api.get_course_content_milestones(
                     course_key,
                     exam_key,
                     relationship=relationship_types['FULFILLS']
                 )
                 # Add each milestone to the user's set...
                 user = {'id': user.id}
                 for milestone in content_milestones:
                     milestones_api.add_user_milestone(user, milestone)
Пример #10
0
    def test_get_gated_content(self):
        """
        Verify staff bypasses gated content and student gets list of unfulfilled prerequisites.
        """

        staff = UserFactory(is_staff=True)
        student = UserFactory(is_staff=False)

        self.assertEqual(gating_api.get_gated_content(self.course, staff), [])
        self.assertEqual(gating_api.get_gated_content(self.course, student),
                         [])

        gating_api.add_prerequisite(self.course.id, self.seq1.location)
        gating_api.set_required_content(self.course.id, self.seq2.location,
                                        self.seq1.location, 100)
        milestone = milestones_api.get_course_content_milestones(
            self.course.id, self.seq2.location, 'requires')[0]

        self.assertEqual(gating_api.get_gated_content(self.course, staff), [])
        self.assertEqual(gating_api.get_gated_content(self.course, student),
                         [unicode(self.seq2.location)])

        milestones_api.add_user_milestone({'id': student.id}, milestone)  # pylint: disable=no-member

        self.assertEqual(gating_api.get_gated_content(self.course, student),
                         [])
Пример #11
0
def get_course_content_milestones(course_id, content_id, relationship):
    """
    Client API operation adapter/wrapper
    """
    if not settings.FEATURES.get('MILESTONES_APP', False):
        return []
    from milestones import api as milestones_api
    return milestones_api.get_course_content_milestones(course_id, content_id, relationship)
Пример #12
0
 def test_remove_course_content_milestone(self):
     """ Unit Test: test_remove_course_content_milestone """
     api.add_course_content_milestone(self.test_course_key,
                                      self.test_content_key,
                                      self.relationship_types['REQUIRES'],
                                      self.test_milestone)
     requirer_milestones = api.get_course_content_milestones(
         self.test_course_key, self.test_content_key,
         self.relationship_types['REQUIRES'])
     self.assertEqual(len(requirer_milestones), 1)
     with self.assertNumQueries(2):
         api.remove_course_content_milestone(self.test_course_key,
                                             self.test_content_key,
                                             self.test_milestone)
     requirer_milestones = api.get_course_content_milestones(
         self.test_course_key, self.test_content_key)
     self.assertEqual(len(requirer_milestones), 0)
Пример #13
0
def get_course_content_milestones(course_id, content_id, relationship):
    """
    Client API operation adapter/wrapper
    """
    if not settings.FEATURES.get('MILESTONES_APP', False):
        return []
    from milestones import api as milestones_api
    return milestones_api.get_course_content_milestones(course_id, content_id, relationship)
Пример #14
0
 def test_remove_course_content_milestone_missing_milestone(self):
     """ Unit Test: test_remove_course_content_milestone_missing_milestone """
     with self.assertNumQueries(1):
         api.remove_course_content_milestone(self.test_course_key,
                                             self.test_content_key,
                                             self.test_milestone)
     requirer_milestones = api.get_course_content_milestones(
         self.test_course_key, self.test_content_key)
     self.assertEqual(len(requirer_milestones), 0)
Пример #15
0
def remove_course_content_user_milestones(course_key, content_key, user, relationship):
    """
    Removes the specified User-Milestone link from the system for the specified course content module.
    """
    if not settings.FEATURES.get('MILESTONES_APP'):
        return []

    course_content_milestones = milestones_api.get_course_content_milestones(course_key, content_key, relationship)
    for milestone in course_content_milestones:
        milestones_api.remove_user_milestone({'id': user.id}, milestone)
def remove_course_content_user_milestones(course_key, content_key, user, relationship):
    """
    Removes the specified User-Milestone link from the system for the specified course content module.
    """
    if not settings.FEATURES.get('MILESTONES_APP'):
        return []

    course_content_milestones = milestones_api.get_course_content_milestones(course_key, content_key, relationship)
    for milestone in course_content_milestones:
        milestones_api.remove_user_milestone({'id': user.id}, milestone)
Пример #17
0
 def test_add_course_content_milestone(self):
     """ Unit Test: test_add_course_content_milestone """
     with self.assertNumQueries(3):
         api.add_course_content_milestone(
             self.test_course_key, self.test_content_key,
             self.relationship_types['REQUIRES'], self.test_milestone)
     requirer_milestones = api.get_course_content_milestones(
         self.test_course_key, self.test_content_key,
         self.relationship_types['REQUIRES'])
     self.assertEqual(len(requirer_milestones), 1)
     with self.assertNumQueries(3):
         api.add_course_content_milestone(
             self.test_prerequisite_course_key, self.test_content_key,
             self.relationship_types['FULFILLS'], self.test_milestone,
             {'min_score': 80})
     fulfiller_milestones = api.get_course_content_milestones(
         self.test_prerequisite_course_key, self.test_content_key,
         self.relationship_types['FULFILLS'])
     self.assertEqual(len(fulfiller_milestones), 1)
Пример #18
0
def remove_course_content_user_milestones(course_key, content_key, user, relationship):
    """
    Removes the specified User-Milestone link from the system for the specified course content module.
    """
    if not ENABLE_MILESTONES_APP.is_enabled():
        return []

    course_content_milestones = milestones_api.get_course_content_milestones(course_key, content_key, relationship)
    for milestone in course_content_milestones:
        milestones_api.remove_user_milestone({'id': user.id}, milestone)
Пример #19
0
 def test_get_course_content_milestones_with_unfulfilled_user_milestones(
         self):
     """ Unit Test: test_get_course_content_milestones_with_unfulfilled_user_milestones """
     api.add_course_content_milestone(self.test_course_key,
                                      self.test_content_key,
                                      self.relationship_types['REQUIRES'],
                                      self.test_milestone)
     with self.assertNumQueries(2):
         requirer_milestones = api.get_course_content_milestones(
             self.test_course_key, self.test_content_key,
             self.relationship_types['REQUIRES'], {'id': self.test_user.id})
     self.assertEqual(len(requirer_milestones), 1)
Пример #20
0
 def test_remove_course_content_milestone_missing_milestone(self):
     """ Unit Test: test_remove_course_content_milestone_missing_milestone """
     with self.assertNumQueries(1):
         api.remove_course_content_milestone(
             self.test_course_key,
             self.test_content_key,
             self.test_milestone
         )
     requirer_milestones = api.get_course_content_milestones(
         self.test_course_key,
         self.test_content_key
     )
     self.assertEqual(len(requirer_milestones), 0)
def get_course_content_milestones(course_id, content_id, relationship, user_id=None):
    """
    Client API operation adapter/wrapper
    Uses the request cache to store all of a user's
    milestones
    """
    if not settings.FEATURES.get('MILESTONES_APP'):
        return []

    if user_id is None:
        return milestones_api.get_course_content_milestones(course_id, content_id, relationship)

    request_cache_dict = request_cache.get_cache(REQUEST_CACHE_NAME)
    if user_id not in request_cache_dict:
        request_cache_dict[user_id] = {}

    if relationship not in request_cache_dict[user_id]:
        request_cache_dict[user_id][relationship] = milestones_api.get_course_content_milestones(
            course_key=course_id,
            relationship=relationship,
            user={"id": user_id}
        )

    return [m for m in request_cache_dict[user_id][relationship] if m['content_id'] == content_id]
Пример #22
0
    def test_remove_content_references(self):
        """ Unit Test: test_remove_content_references """
        # Add a course dependency on the test milestone
        api.add_course_milestone(self.test_course_key,
                                 self.relationship_types['REQUIRES'],
                                 self.test_milestone)
        self.assertEqual(len(api.get_course_milestones(self.test_course_key)),
                         1)

        # Add a content fulfillment for the test milestone
        api.add_course_content_milestone(self.test_course_key,
                                         self.test_content_key,
                                         self.relationship_types['FULFILLS'],
                                         self.test_milestone)
        milestones = api.get_course_content_milestones(self.test_course_key,
                                                       self.test_content_key)
        self.assertEqual(len(milestones), 1)

        # Remove the content dependency
        with self.assertNumQueries(2):
            api.remove_content_references(self.test_content_key)
        milestones = api.get_course_content_milestones(self.test_course_key,
                                                       self.test_content_key)
        self.assertEqual(len(milestones), 0)
Пример #23
0
 def test_get_course_content_milestones_without_content_key(self):
     """ Unit Test: test_get_course_content_milestones_without_content_key """
     api.add_course_content_milestone(self.test_course_key,
                                      self.test_content_key,
                                      self.relationship_types['REQUIRES'],
                                      self.test_milestone)
     api.add_course_content_milestone(self.test_course_key,
                                      self.test_alternate_content_key,
                                      self.relationship_types['REQUIRES'],
                                      self.test_milestone)
     with self.assertNumQueries(2):
         requirer_milestones = api.get_course_content_milestones(
             self.test_course_key, None,
             self.relationship_types['REQUIRES'])
     self.assertEqual(len(requirer_milestones), 2)
Пример #24
0
 def test_get_course_content_milestones_with_unfulfilled_user_milestones(self):
     """ Unit Test: test_get_course_content_milestones_with_unfulfilled_user_milestones """
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone
     )
     with self.assertNumQueries(2):
         requirer_milestones = api.get_course_content_milestones(
             self.test_course_key,
             self.test_content_key,
             self.relationship_types['REQUIRES'],
             {'id': self.test_user.id}
         )
     self.assertEqual(len(requirer_milestones), 1)
Пример #25
0
 def _fulfill_content_milestones(course_key, content_key, user_id):  # pylint: disable=unused-argument
     """
     Internal helper to handle milestone fulfillments for the specified content module
     """
     # Fulfillment Use Case: Entrance Exam
     # If this module is part of an entrance exam, we'll need to see if the student
     # has reached the point at which they can collect the associated milestone
     if settings.FEATURES.get('ENTRANCE_EXAMS', False):
         course = modulestore().get_course(course_key)
         content = modulestore().get_item(content_key)
         entrance_exam_enabled = getattr(course, 'entrance_exam_enabled', False)
         in_entrance_exam = getattr(content, 'in_entrance_exam', False)
         if entrance_exam_enabled and in_entrance_exam:
             exam_key = UsageKey.from_string(course.entrance_exam_id)
             exam_descriptor = modulestore().get_item(exam_key)
             exam_modules = yield_dynamic_descriptor_descendents(
                 exam_descriptor,
                 inner_get_module
             )
             ignore_categories = ['course', 'chapter', 'sequential', 'vertical']
             module_pcts = []
             exam_pct = 0
             for module in exam_modules:
                 if module.graded and module.category not in ignore_categories:
                     module_pct = 0
                     try:
                         student_module = StudentModule.objects.get(
                             module_state_key=module.scope_ids.usage_id,
                             student_id=user_id
                         )
                         if student_module.max_grade:
                             module_pct = student_module.grade / student_module.max_grade
                     except StudentModule.DoesNotExist:
                         pass
                     module_pcts.append(module_pct)
             exam_pct = sum(module_pcts) / float(len(module_pcts))
             if exam_pct >= course.entrance_exam_minimum_score_pct:
                 relationship_types = milestones_api.get_milestone_relationship_types()
                 content_milestones = milestones_api.get_course_content_milestones(
                     course_key,
                     exam_key,
                     relationship=relationship_types['FULFILLS']
                 )
                 # Add each milestone to the user's set...
                 user = {'id': user_id}
                 for milestone in content_milestones:
                     milestones_api.add_user_milestone(user, milestone)
Пример #26
0
 def _fulfill_content_milestones(course_key, content_key, user_id):  # pylint: disable=unused-argument
     """
     Internal helper to handle milestone fulfillments for the specified content module
     """
     # Fulfillment Use Case: Entrance Exam
     # If this module is part of an entrance exam, we'll need to see if the student
     # has reached the point at which they can collect the associated milestone
     if settings.FEATURES.get('ENTRANCE_EXAMS', False):
         course = modulestore().get_course(course_key)
         content = modulestore().get_item(content_key)
         entrance_exam_enabled = getattr(course, 'entrance_exam_enabled',
                                         False)
         in_entrance_exam = getattr(content, 'in_entrance_exam', False)
         if entrance_exam_enabled and in_entrance_exam:
             exam_key = UsageKey.from_string(course.entrance_exam_id)
             exam_descriptor = modulestore().get_item(exam_key)
             exam_modules = yield_dynamic_descriptor_descendents(
                 exam_descriptor, inner_get_module)
             ignore_categories = [
                 'course', 'chapter', 'sequential', 'vertical'
             ]
             module_pcts = []
             exam_pct = 0
             for module in exam_modules:
                 if module.graded and module.category not in ignore_categories:
                     module_pct = 0
                     try:
                         student_module = StudentModule.objects.get(
                             module_state_key=module.scope_ids.usage_id,
                             student_id=user_id)
                         if student_module.max_grade:
                             module_pct = student_module.grade / student_module.max_grade
                     except StudentModule.DoesNotExist:
                         pass
                     module_pcts.append(module_pct)
             exam_pct = sum(module_pcts) / float(len(module_pcts))
             if exam_pct >= course.entrance_exam_minimum_score_pct:
                 relationship_types = milestones_api.get_milestone_relationship_types(
                 )
                 content_milestones = milestones_api.get_course_content_milestones(
                     course_key,
                     exam_key,
                     relationship=relationship_types['FULFILLS'])
                 # Add each milestone to the user's set...
                 user = {'id': user_id}
                 for milestone in content_milestones:
                     milestones_api.add_user_milestone(user, milestone)
Пример #27
0
    def test_get_gated_content(self):
        """ Test test_get_gated_content """

        mock_user = MagicMock()
        mock_user.id.return_value = 1

        self.assertEqual(gating_api.get_gated_content(self.course, mock_user), [])

        gating_api.add_prerequisite(self.course.id, self.seq1.location)
        gating_api.set_required_content(self.course.id, self.seq2.location, self.seq1.location, 100)
        milestone = milestones_api.get_course_content_milestones(self.course.id, self.seq2.location, 'requires')[0]

        self.assertEqual(gating_api.get_gated_content(self.course, mock_user), [unicode(self.seq2.location)])

        milestones_api.add_user_milestone({'id': mock_user.id}, milestone)

        self.assertEqual(gating_api.get_gated_content(self.course, mock_user), [])
Пример #28
0
def find_gating_milestones(course_key, content_key=None, relationship=None, user=None):
    """
    Finds gating milestone dicts related to the given supplied parameters.

    Arguments:
        course_key (str|CourseKey): The course key
        content_key (str|UsageKey): The content usage key
        relationship (str): The relationship type (e.g. 'requires')
        user (dict): The user dict (e.g. {'id': 4})

    Returns:
        list: A list of milestone dicts
    """
    return [
        m for m in milestones_api.get_course_content_milestones(course_key, content_key, relationship, user)
        if GATING_NAMESPACE_QUALIFIER in m.get('namespace')
    ]
Пример #29
0
def find_gating_milestones(course_key, content_key=None, relationship=None, user=None):
    """
    Finds gating milestone dicts related to the given supplied parameters.

    Arguments:
        course_key (str|CourseKey): The course key
        content_key (str|UsageKey): The content usage key
        relationship (str): The relationship type (e.g. 'requires')
        user (dict): The user dict (e.g. {'id': 4})

    Returns:
        list: A list of milestone dicts
    """
    return [
        m for m in milestones_api.get_course_content_milestones(course_key, content_key, relationship, user)
        if GATING_NAMESPACE_QUALIFIER in m.get('namespace')
    ]
Пример #30
0
 def test_add_course_content_milestone_active_exists_update_requirements(
         self):
     """ Unit Test: test_add_course_content_milestone_active_exists_update_requirement """
     api.add_course_content_milestone(self.test_course_key,
                                      self.test_content_key,
                                      self.relationship_types['REQUIRES'],
                                      self.test_milestone,
                                      {'min_score': 60})
     with self.assertNumQueries(3):
         api.add_course_content_milestone(
             self.test_course_key, self.test_content_key,
             self.relationship_types['REQUIRES'], self.test_milestone,
             {'min_score': 80})
     milestone = api.get_course_content_milestones(
         self.test_course_key, self.test_content_key,
         self.relationship_types['REQUIRES'])
     for m in milestone:
         self.assertEqual(m['requirements'], {'min_score': 80})
Пример #31
0
    def test_get_gated_content(self):
        """
        Verify staff bypasses gated content and student gets list of unfulfilled prerequisites.
        """

        staff = UserFactory(is_staff=True)
        student = UserFactory(is_staff=False)

        self.assertEqual(gating_api.get_gated_content(self.course, staff), [])
        self.assertEqual(gating_api.get_gated_content(self.course, student), [])

        gating_api.add_prerequisite(self.course.id, self.seq1.location)
        gating_api.set_required_content(self.course.id, self.seq2.location, self.seq1.location, 100)
        milestone = milestones_api.get_course_content_milestones(self.course.id, self.seq2.location, 'requires')[0]

        self.assertEqual(gating_api.get_gated_content(self.course, staff), [])
        self.assertEqual(gating_api.get_gated_content(self.course, student), [unicode(self.seq2.location)])

        milestones_api.add_user_milestone({'id': student.id}, milestone)  # pylint: disable=no-member

        self.assertEqual(gating_api.get_gated_content(self.course, student), [])
Пример #32
0
    def test_get_gated_content(self):
        """
        Verify staff bypasses gated content and student gets list of unfulfilled prerequisites.
        """

        staff = UserFactory(is_staff=True)
        student = UserFactory(is_staff=False)

        assert gating_api.get_gated_content(self.course, staff) == []
        assert gating_api.get_gated_content(self.course, student) == []

        gating_api.add_prerequisite(self.course.id, self.seq1.location)
        gating_api.set_required_content(self.course.id, self.seq2.location, self.seq1.location, 100)
        milestone = milestones_api.get_course_content_milestones(self.course.id, self.seq2.location, 'requires')[0]

        assert gating_api.get_gated_content(self.course, staff) == []
        assert gating_api.get_gated_content(self.course, student) == [str(self.seq2.location)]

        milestones_api.add_user_milestone({'id': student.id}, milestone)

        assert gating_api.get_gated_content(self.course, student) == []
Пример #33
0
 def test_get_course_content_milestones_with_invalid_relationship(self):
     """ Unit Test: test_get_course_content_milestones_with_invalid_relationship """
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone
     )
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_alternate_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone
     )
     with self.assertNumQueries(1):
         requirer_milestones = api.get_course_content_milestones(
             self.test_course_key,
             self.test_content_key,
             'INVALID RELATIONSHIP TYPE'
         )
     self.assertEqual(len(requirer_milestones), 0)
Пример #34
0
 def test_get_course_content_milestones_without_content_key(self):
     """ Unit Test: test_get_course_content_milestones_without_content_key """
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone
     )
     api.add_course_content_milestone(
         self.test_course_key,
         self.test_alternate_content_key,
         self.relationship_types['REQUIRES'],
         self.test_milestone
     )
     with self.assertNumQueries(2):
         requirer_milestones = api.get_course_content_milestones(
             self.test_course_key,
             None,
             self.relationship_types['REQUIRES']
         )
     self.assertEqual(len(requirer_milestones), 2)
Пример #35
0
        def test_contentstore_views_entrance_exam_post(self):
            """
            Unit Test: test_contentstore_views_entrance_exam_post
            """
            resp = self.client.post(self.exam_url, {}, http_accept='application/json')
            self.assertEqual(resp.status_code, 201)
            resp = self.client.get(self.exam_url)
            self.assertEqual(resp.status_code, 200)

            # Reload the test course now that the exam module has been added
            self.course = modulestore().get_course(self.course.id)
            metadata = CourseMetadata.fetch_all(self.course)
            self.assertTrue(metadata['entrance_exam_enabled'])
            self.assertIsNotNone(metadata['entrance_exam_minimum_score_pct'])
            self.assertIsNotNone(metadata['entrance_exam_id']['value'])
            self.assertTrue(len(milestones_api.get_course_milestones(unicode(self.course.id))))
            content_milestones = milestones_api.get_course_content_milestones(
                unicode(self.course.id),
                metadata['entrance_exam_id']['value'],
                self.milestone_relationship_types['FULFILLS']
            )
            self.assertTrue(len(content_milestones))
Пример #36
0
        def test_contentstore_views_entrance_exam_post(self):
            """
            Unit Test: test_contentstore_views_entrance_exam_post
            """
            resp = self.client.post(self.exam_url, {},
                                    http_accept='application/json')
            self.assertEqual(resp.status_code, 201)
            resp = self.client.get(self.exam_url)
            self.assertEqual(resp.status_code, 200)

            # Reload the test course now that the exam module has been added
            self.course = modulestore().get_course(self.course.id)
            metadata = CourseMetadata.fetch_all(self.course)
            self.assertTrue(metadata['entrance_exam_enabled'])
            self.assertIsNotNone(metadata['entrance_exam_minimum_score_pct'])
            self.assertIsNotNone(metadata['entrance_exam_id']['value'])
            self.assertTrue(
                len(
                    milestones_api.get_course_milestones(
                        unicode(self.course.id))))
            content_milestones = milestones_api.get_course_content_milestones(
                unicode(self.course.id), metadata['entrance_exam_id']['value'],
                self.milestone_relationship_types['FULFILLS'])
            self.assertTrue(len(content_milestones))