示例#1
0
class IsCourseStaffInstructorTests(TestCase):
    """ Test for IsCourseStaffInstructor permission class. """

    def setUp(self):
        super(IsCourseStaffInstructorTests, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
        self.permission = IsCourseStaffInstructor()
        self.coach = UserFactory()
        self.user = UserFactory()
        self.request = RequestFactory().get('/')
        self.request.user = self.user
        self.course_key = CourseKey.from_string('edx/test123/run')
        self.obj = TestCcxObject(user=self.coach, course_id=self.course_key)

    def test_course_staff_has_access(self):
        CourseStaffRole(course_key=self.course_key).add_users(self.user)
        assert self.permission.has_object_permission(self.request, None, self.obj)

    def test_course_instructor_has_access(self):
        CourseInstructorRole(course_key=self.course_key).add_users(self.user)
        assert self.permission.has_object_permission(self.request, None, self.obj)

    def test_course_coach_has_access(self):
        self.request.user = self.coach
        assert self.permission.has_object_permission(self.request, None, self.obj)

    def test_any_user_has_no_access(self):
        assert not self.permission.has_object_permission(self.request, None, self.obj)

    def test_anonymous_has_no_access(self):
        self.request.user = AnonymousUser()
        assert not self.permission.has_object_permission(self.request, None, self.obj)
示例#2
0
class IsCourseStaffInstructorTests(TestCase):
    """ Test for IsCourseStaffInstructor permission class. """
    shard = 2

    def setUp(self):
        super(IsCourseStaffInstructorTests, self).setUp()
        self.permission = IsCourseStaffInstructor()
        self.coach = UserFactory()
        self.user = UserFactory()
        self.request = RequestFactory().get('/')
        self.request.user = self.user
        self.course_key = CourseKey.from_string('edx/test123/run')
        self.obj = TestCcxObject(user=self.coach, course_id=self.course_key)

    def test_course_staff_has_access(self):
        CourseStaffRole(course_key=self.course_key).add_users(self.user)
        self.assertTrue(self.permission.has_object_permission(self.request, None, self.obj))

    def test_course_instructor_has_access(self):
        CourseInstructorRole(course_key=self.course_key).add_users(self.user)
        self.assertTrue(self.permission.has_object_permission(self.request, None, self.obj))

    def test_course_coach_has_access(self):
        self.request.user = self.coach
        self.assertTrue(self.permission.has_object_permission(self.request, None, self.obj))

    def test_any_user_has_no_access(self):
        self.assertFalse(self.permission.has_object_permission(self.request, None, self.obj))

    def test_anonymous_has_no_access(self):
        self.request.user = AnonymousUser()
        self.assertFalse(self.permission.has_object_permission(self.request, None, self.obj))
示例#3
0
class IsCourseStaffInstructorTests(TestCase):
    """ Test for IsCourseStaffInstructor permission class. """

    def setUp(self):
        super(IsCourseStaffInstructorTests, self).setUp()
        self.permission = IsCourseStaffInstructor()
        self.coach = UserFactory.create()
        self.user = UserFactory.create()
        self.request = RequestFactory().get('/')
        self.request.user = self.user
        self.course_key = CourseKey.from_string('edx/test123/run')
        self.obj = TestCcxObject(user=self.coach, course_id=self.course_key)

    def test_course_staff_has_access(self):
        CourseStaffRole(course_key=self.course_key).add_users(self.user)
        self.assertTrue(self.permission.has_object_permission(self.request, None, self.obj))

    def test_course_instructor_has_access(self):
        CourseInstructorRole(course_key=self.course_key).add_users(self.user)
        self.assertTrue(self.permission.has_object_permission(self.request, None, self.obj))

    def test_course_coach_has_access(self):
        self.request.user = self.coach
        self.assertTrue(self.permission.has_object_permission(self.request, None, self.obj))

    def test_any_user_has_no_access(self):
        self.assertFalse(self.permission.has_object_permission(self.request, None, self.obj))

    def test_anonymous_has_no_access(self):
        self.request.user = AnonymousUser()
        self.assertFalse(self.permission.has_object_permission(self.request, None, self.obj))
 def setUp(self):
     super(IsCourseStaffInstructorTests, self).setUp()
     self.permission = IsCourseStaffInstructor()
     self.coach = UserFactory()
     self.user = UserFactory()
     self.request = RequestFactory().get('/')
     self.request.user = self.user
     self.course_key = CourseKey.from_string('edx/test123/run')
     self.obj = TestCcxObject(user=self.coach, course_id=self.course_key)
示例#5
0
 def setUp(self):
     super(IsCourseStaffInstructorTests, self).setUp()
     self.permission = IsCourseStaffInstructor()
     self.coach = UserFactory()
     self.user = UserFactory()
     self.request = RequestFactory().get('/')
     self.request.user = self.user
     self.course_key = CourseKey.from_string('edx/test123/run')
     self.obj = TestCcxObject(user=self.coach, course_id=self.course_key)