示例#1
0
    def test_get_user_enrollments(self, course_modes, enrollment_mode):
        self._create_course_modes(course_modes)

        # Try to get enrollments before they exist.
        result = data.get_user_enrollments(self.course.id)
        assert not result.exists()

        # Create 10 test users to enroll in the course
        users = []
        for i in range(10):
            users.append(
                UserFactory.create(username=self.USERNAME + str(i),
                                   email=self.EMAIL + str(i),
                                   password=self.PASSWORD + str(i)))

        # Create the original enrollments.
        created_enrollments = []
        for user in users:
            created_enrollments.append(
                data.create_course_enrollment(user.username,
                                              six.text_type(self.course.id),
                                              enrollment_mode, True))

        # Compare the created enrollments with the results
        # from the get user enrollments request.
        results = data.get_user_enrollments(self.course.id)
        assert result.exists()
        assert CourseEnrollmentSerializer(
            results, many=True).data == created_enrollments
示例#2
0
    def test_get_user_enrollments(self, course_modes, enrollment_mode):
        self._create_course_modes(course_modes)

        # Try to get enrollments before they exist.
        result = data.get_user_enrollments(self.course.id)
        self.assertFalse(result.exists())

        # Create 10 test users to enroll in the course
        users = []
        for i in range(10):
            users.append(UserFactory.create(
                username=self.USERNAME + str(i),
                email=self.EMAIL + str(i),
                password=self.PASSWORD + str(i)
            ))

        # Create the original enrollments.
        created_enrollments = []
        for user in users:
            created_enrollments.append(data.create_course_enrollment(
                user.username,
                six.text_type(self.course.id),
                enrollment_mode,
                True
            ))

        # Compare the created enrollments with the results
        # from the get user enrollments request.
        results = data.get_user_enrollments(
            self.course.id
        )
        self.assertTrue(result.exists())
        self.assertEqual(CourseEnrollmentSerializer(results, many=True).data, created_enrollments)