Esempio n. 1
0
 def test_get_user_for_role(self):
     """
     test users_for_role
     """
     role = CourseStaffRole(self.course_key)
     role.add_users(self.student)
     self.assertGreater(len(role.users_with_role()), 0)
Esempio n. 2
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))
Esempio n. 3
0
 def test_get_user_for_role(self):
     """
     test users_for_role
     """
     role = CourseStaffRole(self.course_key)
     role.add_users(self.student)
     self.assertGreater(len(role.users_with_role()), 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))
Esempio n. 5
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.
        """
        self.assertEqual(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)

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

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

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

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

        self.assertFalse(
            CourseEnrollment.objects.filter(course_id=self.course_limited.id,
                                            user=user2).exists())
Esempio n. 6
0
    def make_staff(self):
        """
        create staff user
        """
        staff = AdminFactory.create(password="******")
        role = CourseStaffRole(self.course.id)
        role.add_users(staff)

        return staff
    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)
Esempio n. 8
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)
     self.assertTrue(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)
     self.assertFalse(role.has_user(self.student))
Esempio n. 9
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)
     self.assertTrue(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)
     self.assertFalse(role.has_user(self.student))
Esempio n. 10
0
    def setUp(self):

        super(TestDirectMessage, self).setUp()

        # create a course
        self.course = CourseFactory.create(
            org='mss', course='999', display_name='eol directmessage course')

        # Patch the comment client user save method so it does not try
        # to create a new cc user when creating a django user
        with patch('student.models.cc.User.save'):
            uname = 'student'
            email = '*****@*****.**'
            password = '******'

            # Create the student
            self.main_student = UserFactory(username=uname,
                                            password=password,
                                            email=email)

            # Enroll the student in the course
            CourseEnrollmentFactory(user=self.main_student,
                                    course_id=self.course.id)

            # Log the student in
            self.main_client = Client()
            assert_true(
                self.main_client.login(username=uname, password=password))

            # Create and Enroll staff user
            self.staff_user = UserFactory(username='******',
                                          password='******',
                                          email='*****@*****.**',
                                          is_staff=True)
            CourseEnrollmentFactory(user=self.staff_user,
                                    course_id=self.course.id)

            role_staff = CourseStaffRole(self.course.id)
            role_staff.add_users(self.staff_user)

            # Log the user staff in
            self.staff_client = Client()
            assert_true(
                self.staff_client.login(username='******',
                                        password='******'))

        # Create users and enroll
        self.users = [UserFactory.create() for _ in range(USER_COUNT)]
        for user in self.users:
            CourseEnrollmentFactory.create(user=user, course_id=self.course.id)
Esempio n. 11
0
    def test_create_enrollments_and_assign_staff(self):
        """
        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('learner-1', CourseStatuses.ACTIVE,
                                           True),
            self.course_enrollment_request('learner-2', CourseStatuses.ACTIVE,
                                           True),
            self.course_enrollment_request('learner-3', 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)
Esempio n. 12
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.
        """
        self.assertEqual(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)

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

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

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

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

        self.assertFalse(
            CourseEnrollment.objects.filter(course_id=self.course_limited.id, user=user2).exists()
        )