def setUp(self): super(AccessUtilsTestCase, self).setUp(create_user=False) self.course = CourseFactory.create() self.course_id = self.course.id self.student_role = RoleFactory(name='Student', course_id=self.course_id) self.moderator_role = RoleFactory(name='Moderator', course_id=self.course_id) self.community_ta_role = RoleFactory(name='Community TA', course_id=self.course_id) self.student1 = UserFactory(username='******', email='*****@*****.**') self.student1_enrollment = CourseEnrollmentFactory(user=self.student1) self.student_role.users.add(self.student1) self.student2 = UserFactory(username='******', email='*****@*****.**') self.student2_enrollment = CourseEnrollmentFactory(user=self.student2) self.moderator = UserFactory(username='******', email='*****@*****.**', is_staff=True) self.moderator_enrollment = CourseEnrollmentFactory( user=self.moderator) self.moderator_role.users.add(self.moderator) self.community_ta1 = UserFactory(username='******', email='*****@*****.**') self.community_ta_role.users.add(self.community_ta1) self.community_ta2 = UserFactory(username='******', email='*****@*****.**') self.community_ta_role.users.add(self.community_ta2)
def setUp(self): self.course_id = 'edX/toy/2012_Fall' self.student_role = RoleFactory(name='Student', course_id=self.course_id) self.moderator_role = RoleFactory(name='Moderator', course_id=self.course_id) self.community_ta_role = RoleFactory(name='Community TA', course_id=self.course_id) self.student1 = UserFactory(username='******', email='*****@*****.**') self.student1_enrollment = CourseEnrollmentFactory(user=self.student1) self.student_role.users.add(self.student1) self.student2 = UserFactory(username='******', email='*****@*****.**') self.student2_enrollment = CourseEnrollmentFactory(user=self.student2) self.moderator = UserFactory(username='******', email='*****@*****.**', is_staff=True) self.moderator_enrollment = CourseEnrollmentFactory( user=self.moderator) self.moderator_role.users.add(self.moderator) self.community_ta1 = UserFactory(username='******', email='*****@*****.**') self.community_ta_role.users.add(self.community_ta1) self.community_ta2 = UserFactory(username='******', email='*****@*****.**') self.community_ta_role.users.add(self.community_ta2)
def test_access_user_with_forum_role(self, role_name): """ Test that users with a given forum role do not lose access to graded content """ user = UserFactory.create() role = RoleFactory(name=role_name, course_id=self.course.id) role.users.add(user) _assert_block_is_gated( block=self.blocks_dict['problem'], user=user, course=self.course, is_gated=False, request_factory=self.factory, )
def test_course_does_not_expire_for_user_with_course_role(self, role_name): """ Test that users with the above roles for a course do not lose access """ course = CourseFactory.create(start=THREE_YEARS_AGO) url = course_home_url(course) user = UserFactory.create() role = RoleFactory(name=role_name, course_id=course.id) role.users.add(user) # ensure the user has indefinite access self.client.login(username=user.username, password=self.TEST_PASSWORD) response = self.client.get(url) self.assertEqual(response.status_code, 200, "Should not expire access for user")
def test_no_banner_when_masquerading_as_forum_staff(self, role_name, mock_get_course_run_details): """ When masquerading as a specific expired user, if that user has a forum staff role the expired course banner will not show up. """ mock_get_course_run_details.return_value = {'weeks_to_complete': 1} expired_staff = UserFactory.create() role = RoleFactory(name=role_name, course_id=self.course.id) role.users.add(expired_staff) ScheduleFactory( start=self.THREE_YEARS_AGO, enrollment__mode=CourseMode.AUDIT, enrollment__course_id=self.course.id, enrollment__user=expired_staff ) CourseDurationLimitConfig.objects.create( enabled=True, course=CourseOverview.get_from_id(self.course.id), enabled_as_of=self.course.start, ) staff_user = StaffFactory.create(password=TEST_PASSWORD, course_key=self.course.id) CourseEnrollmentFactory.create( user=staff_user, course_id=self.course.id, mode='audit' ) self.client.login(username=staff_user.username, password='******') self.update_masquerade(username=expired_staff.username) course_home_url = reverse('openedx.course_experience.course_home', args=[unicode(self.course.id)]) response = self.client.get(course_home_url, follow=True) self.assertEqual(response.status_code, 200) self.assertItemsEqual(response.redirect_chain, []) banner_text = 'This learner does not have access to this course. Their access expired on' self.assertNotIn(banner_text, response.content)
def test_access_masquerade_as_user_with_forum_role(self, role_name): """ Test that when masquerading as a user with a given forum role you do not lose access to graded content """ staff_user = StaffFactory.create(password=TEST_PASSWORD, course_key=self.course.id) CourseEnrollmentFactory.create(user=staff_user, course_id=self.course.id, mode='audit') self.client.login(username=staff_user.username, password=TEST_PASSWORD) user = UserFactory.create() role = RoleFactory(name=role_name, course_id=self.course.id) role.users.add(user) self.update_masquerade(username=user.username) _assert_block_is_gated( block=self.blocks_dict['problem'], user=user, course=self.course, is_gated=False, request_factory=self.factory, )