Example #1
0
    def test_courseware_page_unfulfilled_prereqs(self):
        """
        Test courseware access when a course has pre-requisite course yet to be completed
        """
        pre_requisite_course = CourseFactory.create(
            org='edX',
            course='900',
            run='test_run',
        )

        pre_requisite_courses = [str(pre_requisite_course.id)]
        course = CourseFactory.create(
            org='edX',
            course='1000',
            run='test_run',
            pre_requisite_courses=pre_requisite_courses,
        )
        set_prerequisite_courses(course.id, pre_requisite_courses)

        test_password = '******'
        user = UserFactory.create()
        user.set_password(test_password)
        user.save()
        self.login(user.email, test_password)
        CourseEnrollmentFactory(user=user, course_id=course.id)

        url = reverse('courseware', args=[str(course.id)])
        response = self.client.get(url)
        self.assertRedirects(response, reverse('dashboard'))
        assert response.status_code == 302

        fulfill_course_milestone(pre_requisite_course.id, user)
        response = self.client.get(url)
        assert response.status_code == 200
Example #2
0
    def setUp(self):
        super().setUp()

        today = datetime.datetime.now(pytz.UTC)
        last_week = today - datetime.timedelta(days=7)
        next_week = today + datetime.timedelta(days=7)

        self.course_default = CourseFactory.create()
        self.course_started = CourseFactory.create(start=last_week)
        self.course_not_started = CourseFactory.create(start=next_week,
                                                       days_early_for_beta=10)
        self.course_staff_only = CourseFactory.create(
            visible_to_staff_only=True)
        self.course_mobile_available = CourseFactory.create(
            mobile_available=True)
        self.course_with_pre_requisite = CourseFactory.create(
            pre_requisite_courses=[str(self.course_started.id)])
        self.course_with_pre_requisites = CourseFactory.create(
            pre_requisite_courses=[
                str(self.course_started.id),
                str(self.course_not_started.id)
            ])

        self.user_normal = UserFactory.create()
        self.user_beta_tester = BetaTesterFactory.create(
            course_key=self.course_not_started.id)
        self.user_completed_pre_requisite = UserFactory.create()
        fulfill_course_milestone(self.course_started.id,
                                 self.user_completed_pre_requisite)
        self.user_staff = UserFactory.create(is_staff=True)
        self.user_anonymous = AnonymousUserFactory.create()
Example #3
0
    def test_access_on_course_with_pre_requisites(self):
        """
        Test course access when a course has pre-requisite course yet to be completed
        """
        user = UserFactory.create()

        pre_requisite_course = CourseFactory.create(org='test_org',
                                                    number='788',
                                                    run='test_run')

        pre_requisite_courses = [str(pre_requisite_course.id)]
        course = CourseFactory.create(
            org='test_org',
            number='786',
            run='test_run',
            pre_requisite_courses=pre_requisite_courses)
        set_prerequisite_courses(course.id, pre_requisite_courses)

        # user should not be able to load course even if enrolled
        CourseEnrollmentFactory(user=user, course_id=course.id)
        response = access._has_access_course(user, 'load', course)
        assert not response
        assert isinstance(response, access_response.MilestoneAccessError)
        # Staff can always access course
        staff = StaffFactory.create(course_key=course.id)
        assert access._has_access_course(staff, 'load', course)

        # User should be able access after completing required course
        fulfill_course_milestone(pre_requisite_course.id, user)
        assert access._has_access_course(user, 'load', course)
Example #4
0
 def test_fulfilled_prerequisite_course(self):
     """
     Tests the case when a user fulfills existing pre-requisite course
     """
     self._add_prerequisite_course()
     add_prerequisite_course(self.course.id, self.prereq_course.id)
     fulfill_course_milestone(self.prereq_course.id, self.user)
     self.init_course_access()
     self.api_response()
Example #5
0
def handle_course_cert_awarded(sender, user, course_key, **kwargs):  # pylint: disable=unused-argument
    """
    Mark a milestone entry if user has passed the course.
    """
    if is_prerequisite_courses_enabled():
        fulfill_course_milestone(course_key, user)