class IsCourseInstructorTests(TestCase): """ Test for IsCourseInstructor permission class. """ def setUp(self): super(IsCourseInstructorTests, self).setUp() self.permission = IsCourseInstructor() self.request = RequestFactory().get('/') self.course_key = CourseKey.from_string('edx/test123/run') self.obj = TestObject(course_id=self.course_key) def test_course_staff_has_no_access(self): user = UserFactory.create() self.request.user = user CourseStaffRole(course_key=self.course_key).add_users(user) self.assertFalse( self.permission.has_object_permission(self.request, None, self.obj)) def test_course_instructor_has_access(self): user = UserFactory.create() self.request.user = user CourseInstructorRole(course_key=self.course_key).add_users(user) self.assertTrue( self.permission.has_object_permission(self.request, None, self.obj)) def test_anonymous_has_no_access(self): self.assertFalse( self.permission.has_object_permission(self.request, None, self.obj))
def setUp(self): super(IsCourseInstructorTests, self).setUp() self.permission = IsCourseInstructor() self.request = RequestFactory().get('/') self.course_key = CourseKey.from_string('edx/test123/run') self.obj = TestObject(course_id=self.course_key)