Пример #1
0
def check_start_date(user,
                     days_early_for_beta,
                     start,
                     course_key,
                     display_error_to_user=True,
                     now=None):
    """
    Verifies whether the given user is allowed access given the
    start date and the Beta offset for the given course.

    Arguments:
        display_error_to_user: If True, display this error to users in the UI.

    Returns:
        AccessResponse: Either ACCESS_GRANTED or StartDateError.
    """
    start_dates_disabled = settings.FEATURES['DISABLE_START_DATES']
    masquerading_as_student = is_masquerading_as_student(user, course_key)

    if start_dates_disabled and not masquerading_as_student:
        return ACCESS_GRANTED
    else:
        if start is None or in_preview_mode() or get_course_masquerade(
                user, course_key):
            return ACCESS_GRANTED

        if now is None:
            now = datetime.now(UTC)
        effective_start = adjust_start_date(user, days_early_for_beta, start,
                                            course_key)
        if now > effective_start:
            return ACCESS_GRANTED

        return StartDateError(start,
                              display_error_to_user=display_error_to_user)
Пример #2
0
    def test_courseware_access(self, api_version):
        self.login()

        course_with_prereq = CourseFactory.create(start=self.LAST_WEEK, mobile_available=True)
        prerequisite_course = CourseFactory.create()
        set_prerequisite_courses(course_with_prereq.id, [str(prerequisite_course.id)])

        # Create list of courses with various expected courseware_access responses and corresponding expected codes
        courses = [
            course_with_prereq,
            CourseFactory.create(start=self.NEXT_WEEK, mobile_available=True),
            CourseFactory.create(visible_to_staff_only=True, mobile_available=True),
            CourseFactory.create(start=self.LAST_WEEK, mobile_available=True, visible_to_staff_only=False),
        ]

        expected_error_codes = [
            MilestoneAccessError().error_code,  # 'unfulfilled_milestones'
            StartDateError(self.NEXT_WEEK).error_code,  # 'course_not_started'
            VisibilityError().error_code,  # 'not_visible_to_user'
            None,
        ]

        # Enroll in all the courses
        for course in courses:
            self.enroll(course.id)

        # Verify courses have the correct response through error code. Last enrolled course is first course in response
        response = self.api_response(api_version=api_version)
        for course_index in range(len(courses)):
            result = response.data[course_index]['course']['courseware_access']
            assert result['error_code'] == expected_error_codes[::(- 1)][course_index]

            if result['error_code'] is not None:
                assert not result['has_access']
Пример #3
0
 def test_unreleased_course(self):
     # ensure the course always starts in the future
     self.course = CourseFactory.create(
         mobile_available=True, static_asset_path="needed_for_split")
     self.course.start = timezone.now() + datetime.timedelta(days=365)
     self.init_course_access()
     self._verify_response(self.ALLOW_ACCESS_TO_UNRELEASED_COURSE,
                           StartDateError(self.course.start))