Beispiel #1
0
    def setUp(self):
        super(DiscussionAPIUtilsTestCase, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments

        self.course = CourseFactory.create()
        self.course.discussion_blackouts = [
            datetime.now(UTC) - timedelta(days=3),
            datetime.now(UTC) + timedelta(days=3)
        ]
        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.student = UserFactory(username='******', email='*****@*****.**')
        self.student_enrollment = CourseEnrollmentFactory(user=self.student)
        self.student_role.users.add(self.student)
        self.moderator = UserFactory(username='******',
                                     email='*****@*****.**',
                                     is_staff=True)
        self.moderator_enrollment = CourseEnrollmentFactory(
            user=self.moderator)
        self.moderator_role.users.add(self.moderator)
        self.community_ta = UserFactory(username='******',
                                        email='*****@*****.**')
        self.community_ta_role.users.add(self.community_ta)
    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)

        CourseEnrollmentFactory.create(
            user=user,
            course_id=self.course.id,
            mode='audit'
        )

        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,
        )
Beispiel #3
0
    def setUp(self):
        super().setUp()

        self.course = CourseFactory.create(
            default_store=ModuleStoreEnum.Type.split)
        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.student_user = UserFactory(password=self.TEST_PASSWORD)
        self.moderator_user = UserFactory(password=self.TEST_PASSWORD)
        self.community_ta_user = UserFactory(password=self.TEST_PASSWORD)
        self.student_role.users.add(self.student_user)
        self.moderator_role.users.add(self.moderator_user)
        self.community_ta_role.users.add(self.community_ta_user)
Beispiel #4
0
    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)
        assert response.status_code == 200, 'Should not expire access for user'
Beispiel #5
0
    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_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)

        CourseEnrollmentFactory.create(
            mode=CourseMode.AUDIT,
            course_id=self.course.id,
            user=expired_staff,
        )
        Schedule.objects.update(start_date=self.THREE_YEARS_AGO)

        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=[str(self.course.id)])
        response = self.client.get(course_home_url, follow=True)
        assert response.status_code == 200
        self.assertCountEqual(response.redirect_chain, [])
        banner_text = 'This learner does not have access to this course. Their access expired on'
        self.assertNotContains(response, banner_text)