def test_get_required_content_with_anonymous_user(self):
        course = CourseFactory()

        required_content = milestones_helpers.get_required_content(course.id, AnonymousUser())
        assert required_content == []

        # NOTE (CCB): The initial version of anonymous courseware access is very simple. We avoid accidentally
        # exposing locked content by simply avoiding anonymous access altogether for courses runs with milestones.
        milestone = milestones_api.add_milestone({
            'name': 'test',
            'namespace': 'test',
        })
        milestones_helpers.add_course_milestone(str(course.id), 'requires', milestone)
        with pytest.raises(InvalidUserException):
            milestones_helpers.get_required_content(course.id, AnonymousUser())
Exemple #2
0
    def get_required_content(usage_info, block_structure):
        """
        Get the required content for the course.

        This takes into account if the user can skip the entrance exam.

        """
        course_key = block_structure.root_block_usage_key.course_key
        user_can_skip_entrance_exam = False
        if usage_info.user.is_authenticated:
            user_can_skip_entrance_exam = EntranceExamConfiguration.user_can_skip_entrance_exam(
                usage_info.user, course_key)
        required_content = milestones_helpers.get_required_content(
            course_key, usage_info.user)

        if not required_content:
            return required_content

        if user_can_skip_entrance_exam:
            # remove the entrance exam from required content
            entrance_exam_id = block_structure.get_xblock_field(block_structure.root_block_usage_key, 'entrance_exam_id')  # lint-amnesty, pylint: disable=line-too-long
            required_content = [
                content for content in required_content
                if not content == entrance_exam_id
            ]

        return required_content
    def load_data(self):
        """
        Get the required content for the course, and whether
        or not the user can skip the entrance exam.
        """
        self.required_content = milestones_helpers.get_required_content(
            self.course_key, self.user)

        if self.user.is_authenticated:
            self.can_skip_entrance_exam = EntranceExamConfiguration.user_can_skip_entrance_exam(
                self.user, self.course_key)
def get_entrance_exam_content(user, course):
    """
    Get the entrance exam content information (ie, chapter module)
    """
    required_content = get_required_content(course.id, user)

    exam_module = None
    for content in required_content:
        usage_key = UsageKey.from_string(content).map_into_course(course.id)
        module_item = modulestore().get_item(usage_key)
        if not module_item.hide_from_toc and module_item.is_entrance_exam:
            exam_module = module_item
            break
    return exam_module