Ejemplo n.º 1
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 = [six.text_type(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)
        self.assertFalse(response)
        self.assertIsInstance(response, access_response.MilestoneAccessError)
        # Staff can always access course
        staff = StaffFactory.create(course_key=course.id)
        self.assertTrue(access._has_access_course(staff, 'load', course))

        # User should be able access after completing required course
        fulfill_course_milestone(pre_requisite_course.id, user)
        self.assertTrue(access._has_access_course(user, 'load', course))
Ejemplo n.º 2
0
    def test__access_on_mobile(self, mobile_available, student_expected, staff_expected):
        """
        Test course access on mobile for staff and students.
        """
        descriptor = CourseFactory()
        descriptor.visible_to_staff_only = False
        descriptor.mobile_available = mobile_available

        assert bool(access._has_access_course(self.student, 'load_mobile', descriptor)) == student_expected
        assert bool(access._has_access_course(self.staff, 'load_mobile', descriptor)) == staff_expected
Ejemplo n.º 3
0
    def test__course_default_invite_only_flag_true(self):
        """
        Ensure that COURSES_INVITE_ONLY takes precedence over the course invitation_only settings.
        """

        user = UserFactory.create()

        # User cannot enroll in the course if it is just invitation only and COURSES_INVITE_ONLY is also set.
        course = self._mock_course_with_invitation(invitation=True)
        self.assertFalse(access._has_access_course(user, 'enroll', course))

        # User cannot enroll in the course if COURSES_INVITE_ONLY is set despite of the course invitation_only value.
        course = self._mock_course_with_invitation(invitation=False)
        self.assertFalse(access._has_access_course(user, 'enroll', course))
Ejemplo n.º 4
0
    def test__course_default_invite_only_flag_false(self):
        """
        Ensure that COURSES_INVITE_ONLY does not take precedence,
        if it is not set over the course invitation_only settings.
        """

        user = UserFactory.create()

        # User cannot enroll in the course if it is just invitation only.
        course = self._mock_course_with_invitation(invitation=True)
        self.assertFalse(access._has_access_course(user, 'enroll', course))

        # User can enroll in the course if it is not just invitation only.
        course = self._mock_course_with_invitation(invitation=False)
        self.assertTrue(access._has_access_course(user, 'enroll', course))
Ejemplo n.º 5
0
 def test_old_mongo_is_invite_only(self, old_mongo):
     """
     Ensure that Old Mongo courses are marked as invite only and don't allow enrollment
     """
     user = UserFactory.create()
     course = self._mock_course_with_invitation(invitation=False, deprecated=old_mongo)
     self.assertEqual(course_is_invitation_only(course), old_mongo)
     self.assertEqual(access._has_access_course(user, 'enroll', course).has_access, not old_mongo)
Ejemplo n.º 6
0
    def test__has_access_course_can_enroll(self):
        yesterday = datetime.datetime.now(
            pytz.utc) - datetime.timedelta(days=1)
        tomorrow = datetime.datetime.now(pytz.utc) + datetime.timedelta(days=1)

        # Non-staff can enroll if authenticated and specifically allowed for that course
        # even outside the open enrollment period
        user = UserFactory.create()
        course = Mock(enrollment_start=tomorrow,
                      enrollment_end=tomorrow,
                      id=CourseLocator('edX', 'test', '2012_Fall'),
                      enrollment_domain='')
        CourseEnrollmentAllowedFactory(email=user.email, course_id=course.id)
        self.assertTrue(access._has_access_course(user, 'enroll', course))

        # Staff can always enroll even outside the open enrollment period
        user = StaffFactory.create(course_key=course.id)
        self.assertTrue(access._has_access_course(user, 'enroll', course))

        # Non-staff cannot enroll if it is between the start and end dates and invitation only
        # and not specifically allowed
        course = Mock(enrollment_start=yesterday,
                      enrollment_end=tomorrow,
                      id=CourseLocator('edX', 'test', '2012_Fall'),
                      enrollment_domain='',
                      invitation_only=True)
        user = UserFactory.create()
        self.assertFalse(access._has_access_course(user, 'enroll', course))

        # Non-staff can enroll if it is between the start and end dates and not invitation only
        course = Mock(enrollment_start=yesterday,
                      enrollment_end=tomorrow,
                      id=CourseLocator('edX', 'test', '2012_Fall'),
                      enrollment_domain='',
                      invitation_only=False)
        self.assertTrue(access._has_access_course(user, 'enroll', course))

        # Non-staff cannot enroll outside the open enrollment period if not specifically allowed
        course = Mock(enrollment_start=tomorrow,
                      enrollment_end=tomorrow,
                      id=CourseLocator('edX', 'test', '2012_Fall'),
                      enrollment_domain='',
                      invitation_only=False)
        self.assertFalse(access._has_access_course(user, 'enroll', course))
Ejemplo n.º 7
0
    def test__catalog_visibility(self):
        """
        Tests the catalog visibility tri-states
        """
        user = UserFactory.create()
        course_id = CourseLocator('edX', 'test', '2012_Fall')
        staff = StaffFactory.create(course_key=course_id)

        course = Mock(id=course_id,
                      catalog_visibility=CATALOG_VISIBILITY_CATALOG_AND_ABOUT)
        self.assertTrue(
            access._has_access_course(user, 'see_in_catalog', course))
        self.assertTrue(
            access._has_access_course(user, 'see_about_page', course))
        self.assertTrue(
            access._has_access_course(staff, 'see_in_catalog', course))
        self.assertTrue(
            access._has_access_course(staff, 'see_about_page', course))

        # Now set visibility to just about page
        course = Mock(id=CourseLocator('edX', 'test', '2012_Fall'),
                      catalog_visibility=CATALOG_VISIBILITY_ABOUT)
        self.assertFalse(
            access._has_access_course(user, 'see_in_catalog', course))
        self.assertTrue(
            access._has_access_course(user, 'see_about_page', course))
        self.assertTrue(
            access._has_access_course(staff, 'see_in_catalog', course))
        self.assertTrue(
            access._has_access_course(staff, 'see_about_page', course))

        # Now set visibility to none, which means neither in catalog nor about pages
        course = Mock(id=CourseLocator('edX', 'test', '2012_Fall'),
                      catalog_visibility=CATALOG_VISIBILITY_NONE)
        self.assertFalse(
            access._has_access_course(user, 'see_in_catalog', course))
        self.assertFalse(
            access._has_access_course(user, 'see_about_page', course))
        self.assertTrue(
            access._has_access_course(staff, 'see_in_catalog', course))
        self.assertTrue(
            access._has_access_course(staff, 'see_about_page', course))