Beispiel #1
0
 def test_get_user_for_role(self):
     """
     test users_for_role
     """
     role = CourseStaffRole(self.course_key)
     role.add_users(self.student)
     assert len(role.users_with_role()) > 0
Beispiel #2
0
    def test_enrollment_limit(self):
        """
        Assert that in a course with max student limit set to 1, we can enroll staff and instructor along with
        student. To make sure course full check excludes staff and instructors.
        """
        assert self.course_limited.max_student_enrollments_allowed == 1
        user1 = UserFactory.create(username="******", email="*****@*****.**", password="******")
        user2 = UserFactory.create(username="******", email="*****@*****.**", password="******")

        # create staff on course.
        staff = UserFactory.create(username="******", email="*****@*****.**", password="******")
        role = CourseStaffRole(self.course_limited.id)
        role.add_users(staff)

        # create instructor on course.
        instructor = UserFactory.create(username="******", email="*****@*****.**", password="******")
        role = CourseInstructorRole(self.course_limited.id)
        role.add_users(instructor)

        CourseEnrollment.enroll(staff, self.course_limited.id, check_access=True)
        CourseEnrollment.enroll(instructor, self.course_limited.id, check_access=True)

        assert CourseEnrollment.objects.filter(course_id=self.course_limited.id, user=staff).exists()

        assert CourseEnrollment.objects.filter(course_id=self.course_limited.id, user=instructor).exists()

        CourseEnrollment.enroll(user1, self.course_limited.id, check_access=True)
        assert CourseEnrollment.objects.filter(course_id=self.course_limited.id, user=user1).exists()

        with pytest.raises(CourseFullError):
            CourseEnrollment.enroll(user2, self.course_limited.id, check_access=True)

        assert not CourseEnrollment.objects.filter(course_id=self.course_limited.id, user=user2).exists()
Beispiel #3
0
    def test_transcript_delete_handler(self, is_staff, is_course_staff):
        """
        Tests that transcript delete handler works as expected with combinations of staff and course's staff.
        """
        # Setup user's roles
        self.user.is_staff = is_staff
        self.user.save()
        course_staff_role = CourseStaffRole(self.course.id)
        if is_course_staff:
            course_staff_role.add_users(self.user)
        else:
            course_staff_role.remove_users(self.user)

        # Assert the user role
        self.assertEqual(self.user.is_staff, is_staff)
        self.assertEqual(
            CourseStaffRole(self.course.id).has_user(self.user),
            is_course_staff)

        video_id, language_code = u'1234', u'en'
        # Create a real transcript in VAL.
        api.create_or_update_video_transcript(video_id=video_id,
                                              language_code=language_code,
                                              metadata={'file_format': 'srt'})

        # Make request to transcript deletion handler
        response = self.client.delete(
            self.get_url_for_course_key(self.course.id,
                                        edx_video_id=video_id,
                                        language_code=language_code))
        self.assertEqual(response.status_code, 200)
        self.assertFalse(
            api.get_video_transcript_data(video_id=video_id,
                                          language_code=language_code))
Beispiel #4
0
    def make_staff(self):
        """
        create staff user.
        """
        staff = UserFactory.create(password="******")
        role = CourseStaffRole(self.course.id)
        role.add_users(staff)

        return staff
Beispiel #5
0
    def test_update_and_assign_or_revoke_staff(self):
        """
        Successfully updates existing enrollments to assign or revoke the CourseStaff role.
        """
        course_staff_role = CourseStaffRole(self.course_id)
        course_staff_role.add_users(self.student_2)

        self.create_program_and_course_enrollments('learner-1',
                                                   user=self.student_1)
        self.create_program_and_course_enrollments('learner-2',
                                                   user=self.student_2)
        self.create_program_and_course_enrollments('learner-3', user=None)
        learner_4_enrollment = self.create_program_and_course_enrollments(
            'learner-4', user=None)
        learner_5_enrollment = self.create_program_and_course_enrollments(
            'learner-5', user=None)
        CourseAccessRoleAssignment.objects.create(
            enrollment=learner_4_enrollment,
            role=ProgramCourseEnrollmentRoles.COURSE_STAFF,
        )
        CourseAccessRoleAssignment.objects.create(
            enrollment=learner_5_enrollment,
            role=ProgramCourseEnrollmentRoles.COURSE_STAFF,
        )
        course_enrollment_requests = [
            self.course_enrollment_request('learner-1', CourseStatuses.ACTIVE,
                                           True),
            self.course_enrollment_request('learner-2', CourseStatuses.ACTIVE,
                                           False),
            self.course_enrollment_request('learner-3', CourseStatuses.ACTIVE,
                                           True),
            self.course_enrollment_request('learner-4', CourseStatuses.ACTIVE,
                                           False),
            self.course_enrollment_request('learner-5', CourseStatuses.ACTIVE,
                                           True),
        ]
        write_program_course_enrollments(
            self.program_uuid,
            self.course_id,
            course_enrollment_requests,
            True,
            True,
        )
        # Role is revoked for user's with a linked enrollment
        self.assertListEqual([self.student_1],
                             list(course_staff_role.users_with_role()))

        # CourseAccessRoleAssignment objects are created/revoked for enrollments with no linked user
        pending_role_assingments = CourseAccessRoleAssignment.objects.all()
        assert pending_role_assingments.count() == 2
        pending_role_assingments.get(
            enrollment__program_enrollment__external_user_key='learner-3',
            enrollment__course_key=self.course_id)
        pending_role_assingments.get(
            enrollment__program_enrollment__external_user_key='learner-5',
            enrollment__course_key=self.course_id)
Beispiel #6
0
 def test_add_users_doesnt_add_duplicate_entry(self):
     """
     Tests that calling add_users multiple times before a single call
     to remove_users does not result in the user remaining in the group.
     """
     role = CourseStaffRole(self.course_key)
     role.add_users(self.student)
     assert role.has_user(self.student)
     # Call add_users a second time, then remove just once.
     role.add_users(self.student)
     role.remove_users(self.student)
     assert not role.has_user(self.student)
Beispiel #7
0
    def test_create_enrollments_and_assign_staff(self,
                                                 request_user_key_prefix):
        """
        Successfully creates both waiting and linked program course enrollments with the course staff role.
        """
        course_staff_role = CourseStaffRole(self.course_id)
        course_staff_role.add_users(self.student_1)

        self.create_program_enrollment('learner-1', user=None)
        self.create_program_enrollment('learner-2', user=self.student_1)
        self.create_program_enrollment('learner-3', user=self.student_2)

        course_enrollment_requests = [
            self.course_enrollment_request(
                '{}-1'.format(request_user_key_prefix), CourseStatuses.ACTIVE,
                True),
            self.course_enrollment_request(
                '{}-2'.format(request_user_key_prefix), CourseStatuses.ACTIVE,
                True),
            self.course_enrollment_request(
                '{}-3'.format(request_user_key_prefix), CourseStatuses.ACTIVE,
                True),
        ]
        write_program_course_enrollments(
            self.program_uuid,
            self.course_id,
            course_enrollment_requests,
            True,
            True,
        )

        self.assert_program_course_enrollment('learner-1',
                                              CourseStatuses.ACTIVE, False)
        self.assert_program_course_enrollment('learner-2',
                                              CourseStatuses.ACTIVE, True)
        self.assert_program_course_enrollment('learner-3',
                                              CourseStatuses.ACTIVE, True)

        # Users linked to either enrollment are given the course staff role
        self.assertListEqual([self.student_1, self.student_2],
                             list(course_staff_role.users_with_role()))

        # CourseAccessRoleAssignment objects are created for enrollments with no linked user
        pending_role_assingments = CourseAccessRoleAssignment.objects.all()
        assert pending_role_assingments.count() == 1
        pending_role_assingments.get(
            enrollment__program_enrollment__external_user_key='learner-1',
            enrollment__course_key=self.course_id)