예제 #1
0
    def test__has_access_to_location(self):
        location = Location("i4x://edX/toy/course/2012_Fall")

        self.assertFalse(access._has_access_to_location(None, location, "staff", None))
        u = Mock()
        u.is_authenticated.return_value = False
        self.assertFalse(access._has_access_to_location(u, location, "staff", None))
        u = Mock(is_staff=True)
        self.assertTrue(access._has_access_to_location(u, location, "instructor", None))
        # A user has staff access if they are in the staff group
        u = Mock(is_staff=False)
        g = Mock()
        g.name = "staff_edX/toy/2012_Fall"
        u.groups.all.return_value = [g]
        self.assertTrue(access._has_access_to_location(u, location, "staff", None))
        # A user has staff access if they are in the instructor group
        g.name = "instructor_edX/toy/2012_Fall"
        self.assertTrue(access._has_access_to_location(u, location, "staff", None))

        # A user has instructor access if they are in the instructor group
        g.name = "instructor_edX/toy/2012_Fall"
        self.assertTrue(access._has_access_to_location(u, location, "instructor", None))

        # A user does not have staff access if they are
        # not in either the staff or the the instructor group
        g.name = "student_only"
        self.assertFalse(access._has_access_to_location(u, location, "staff", None))

        # A user does not have instructor access if they are
        # not in the instructor group
        g.name = "student_only"
        self.assertFalse(access._has_access_to_location(u, location, "instructor", None))
예제 #2
0
    def test__has_access_to_location(self):
        location = Location('i4x://edX/toy/course/2012_Fall')

        self.assertFalse(
            access._has_access_to_location(None, location, 'staff', None))
        u = Mock()
        u.is_authenticated.return_value = False
        self.assertFalse(
            access._has_access_to_location(u, location, 'staff', None))
        u = Mock(is_staff=True)
        self.assertTrue(
            access._has_access_to_location(u, location, 'instructor', None))
        # A user has staff access if they are in the staff group
        u = Mock(is_staff=False)
        g = Mock()
        g.name = 'staff_edX/toy/2012_Fall'
        u.groups.all.return_value = [g]
        self.assertTrue(
            access._has_access_to_location(u, location, 'staff', None))
        # A user has staff access if they are in the instructor group
        g.name = 'instructor_edX/toy/2012_Fall'
        self.assertTrue(
            access._has_access_to_location(u, location, 'staff', None))

        # A user has instructor access if they are in the instructor group
        g.name = 'instructor_edX/toy/2012_Fall'
        self.assertTrue(
            access._has_access_to_location(u, location, 'instructor', None))

        # A user does not have staff access if they are
        # not in either the staff or the the instructor group
        g.name = 'student_only'
        self.assertFalse(
            access._has_access_to_location(u, location, 'staff', None))

        # A user does not have instructor access if they are
        # not in the instructor group
        g.name = 'student_only'
        self.assertFalse(
            access._has_access_to_location(u, location, 'instructor', None))
예제 #3
0
    def test__has_access_to_location(self):
        self.assertFalse(access._has_access_to_location(None, self.course, 'staff', None))

        self.assertFalse(access._has_access_to_location(self.anonymous_user, self.course, 'staff', None))
        self.assertFalse(access._has_access_to_location(self.anonymous_user, self.course, 'instructor', None))

        self.assertTrue(access._has_access_to_location(self.global_staff, self.course, 'staff', None))
        self.assertTrue(access._has_access_to_location(self.global_staff, self.course, 'instructor', None))

        # A user has staff access if they are in the staff group
        self.assertTrue(access._has_access_to_location(self.course_staff, self.course, 'staff', None))
        self.assertFalse(access._has_access_to_location(self.course_staff, self.course, 'instructor', None))

        # A user has staff and instructor access if they are in the instructor group
        self.assertTrue(access._has_access_to_location(self.course_instructor, self.course, 'staff', None))
        self.assertTrue(access._has_access_to_location(self.course_instructor, self.course, 'instructor', None))

        # A user does not have staff or instructor access if they are
        # not in either the staff or the the instructor group
        self.assertFalse(access._has_access_to_location(self.student, self.course, 'staff', None))
        self.assertFalse(access._has_access_to_location(self.student, self.course, 'instructor', None))
예제 #4
0
    def test__has_access_to_location(self):
        self.assertFalse(
            access._has_access_to_location(None, self.course, 'staff', None))

        self.assertFalse(
            access._has_access_to_location(self.anonymous_user, self.course,
                                           'staff', None))
        self.assertFalse(
            access._has_access_to_location(self.anonymous_user, self.course,
                                           'instructor', None))

        self.assertTrue(
            access._has_access_to_location(self.global_staff, self.course,
                                           'staff', None))
        self.assertTrue(
            access._has_access_to_location(self.global_staff, self.course,
                                           'instructor', None))

        # A user has staff access if they are in the staff group
        self.assertTrue(
            access._has_access_to_location(self.course_staff, self.course,
                                           'staff', None))
        self.assertFalse(
            access._has_access_to_location(self.course_staff, self.course,
                                           'instructor', None))

        # A user has staff and instructor access if they are in the instructor group
        self.assertTrue(
            access._has_access_to_location(self.course_instructor, self.course,
                                           'staff', None))
        self.assertTrue(
            access._has_access_to_location(self.course_instructor, self.course,
                                           'instructor', None))

        # A user does not have staff or instructor access if they are
        # not in either the staff or the the instructor group
        self.assertFalse(
            access._has_access_to_location(self.student, self.course, 'staff',
                                           None))
        self.assertFalse(
            access._has_access_to_location(self.student, self.course,
                                           'instructor', None))