コード例 #1
0
ファイル: test_data.py プロジェクト: edx/edx-platform
    def test_add_or_update_enrollment_attr(self, course_modes, enrollment_mode):
        # Create the course modes (if any) required for this test case
        self._create_course_modes(course_modes)
        data.create_course_enrollment(self.user.username, six.text_type(self.course.id), enrollment_mode, True)
        enrollment_attributes = [
            {
                "namespace": "credit",
                "name": "provider_id",
                "value": "hogwarts",
            }
        ]

        data.add_or_update_enrollment_attr(self.user.username, six.text_type(self.course.id), enrollment_attributes)
        enrollment_attr = data.get_enrollment_attributes(self.user.username, six.text_type(self.course.id))
        self.assertEqual(enrollment_attr[0], enrollment_attributes[0])

        enrollment_attributes = [
            {
                "namespace": "credit",
                "name": "provider_id",
                "value": "ASU",
            }
        ]

        data.add_or_update_enrollment_attr(self.user.username, six.text_type(self.course.id), enrollment_attributes)
        enrollment_attr = data.get_enrollment_attributes(self.user.username, six.text_type(self.course.id))
        self.assertEqual(enrollment_attr[0], enrollment_attributes[0])
コード例 #2
0
ファイル: test_data.py プロジェクト: rmulder/edx-platform
    def test_add_or_update_enrollment_attr(self, course_modes,
                                           enrollment_mode):
        # Create the course modes (if any) required for this test case
        self._create_course_modes(course_modes)
        data.create_course_enrollment(self.user.username,
                                      six.text_type(self.course.id),
                                      enrollment_mode, True)
        enrollment_attributes = [{
            "namespace": "credit",
            "name": "provider_id",
            "value": "hogwarts",
        }]

        data.add_or_update_enrollment_attr(self.user.username,
                                           six.text_type(self.course.id),
                                           enrollment_attributes)
        enrollment_attr = data.get_enrollment_attributes(
            self.user.username, six.text_type(self.course.id))
        assert enrollment_attr[0] == enrollment_attributes[0]

        enrollment_attributes = [{
            "namespace": "credit",
            "name": "provider_id",
            "value": "ASU",
        }]

        data.add_or_update_enrollment_attr(self.user.username,
                                           six.text_type(self.course.id),
                                           enrollment_attributes)
        enrollment_attr = data.get_enrollment_attributes(
            self.user.username, six.text_type(self.course.id))
        assert enrollment_attr[0] == enrollment_attributes[0]
コード例 #3
0
ファイル: test_data.py プロジェクト: rmulder/edx-platform
    def test_get_course_enrollments(self, course_modes, course_numbers):
        # Create all the courses
        created_courses = []
        for course_number in course_numbers:
            created_courses.append(CourseFactory.create(number=course_number))

        created_enrollments = []
        for course in created_courses:
            self._create_course_modes(course_modes, course=course)
            # Create the original enrollment.
            created_enrollments.append(
                data.create_course_enrollment(self.user.username,
                                              six.text_type(course.id),
                                              'honor', True))

        # Compare the created enrollments with the results
        # from the get enrollments request.
        results = data.get_course_enrollments(self.user.username)
        assert results == created_enrollments

        # Now create a course enrollment with some invalid course (does
        # not exist in database) for the user and check that the method
        # 'get_course_enrollments' ignores course enrollments for invalid
        # or deleted courses
        non_existent_course_id = 'InvalidOrg/InvalidCourse/InvalidRun'
        enrollement = CourseEnrollmentFactory.create(
            user=self.user,
            course_id=non_existent_course_id,
            mode='honor',
            is_active=True)
        enrollement.course.delete()

        updated_results = data.get_course_enrollments(self.user.username)
        assert results == updated_results
コード例 #4
0
ファイル: test_data.py プロジェクト: edx/edx-platform
    def test_get_course_enrollments(self, course_modes, course_numbers):
        # Create all the courses
        created_courses = []
        for course_number in course_numbers:
            created_courses.append(CourseFactory.create(number=course_number))

        created_enrollments = []
        for course in created_courses:
            self._create_course_modes(course_modes, course=course)
            # Create the original enrollment.
            created_enrollments.append(data.create_course_enrollment(
                self.user.username,
                six.text_type(course.id),
                'honor',
                True
            ))

        # Compare the created enrollments with the results
        # from the get enrollments request.
        results = data.get_course_enrollments(self.user.username)
        self.assertEqual(results, created_enrollments)

        # Now create a course enrollment with some invalid course (does
        # not exist in database) for the user and check that the method
        # 'get_course_enrollments' ignores course enrollments for invalid
        # or deleted courses
        CourseEnrollment.objects.create(
            user=self.user,
            course_id='InvalidOrg/InvalidCourse/InvalidRun',
            mode='honor',
            is_active=True
        )
        updated_results = data.get_course_enrollments(self.user.username)
        self.assertEqual(results, updated_results)
コード例 #5
0
ファイル: test_data.py プロジェクト: rmulder/edx-platform
    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
コード例 #6
0
ファイル: test_data.py プロジェクト: edx/edx-platform
    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)
コード例 #7
0
ファイル: test_data.py プロジェクト: edx/edx-platform
    def test_get_enrollments_including_inactive(self):
        """ Verify that if 'include_inactive' is True, all enrollments
        are returned including inactive.
        """
        course_modes, course_numbers = ['honor', 'verified', 'audit'], ['1', '2', '3']
        created_courses = []
        for course_number in course_numbers:
            created_courses.append(CourseFactory.create(number=course_number))

        created_enrollments = []
        for course in created_courses:
            self._create_course_modes(course_modes, course=course)
            # Create the original enrollment.
            created_enrollments.append(data.create_course_enrollment(
                self.user.username,
                six.text_type(course.id),
                'honor',
                True
            ))

        # deactivate one enrollment
        data.update_course_enrollment(
            self.user.username,
            six.text_type(created_courses[0].id),
            'honor',
            False
        )

        # by default in-active enrollment will be excluded.
        results = data.get_course_enrollments(self.user.username)
        self.assertNotEqual(len(results), len(created_enrollments))

        # we can get all enrollments including inactive by passing "include_inactive"
        results = data.get_course_enrollments(self.user.username, include_inactive=True)
        self.assertEqual(len(results), len(created_enrollments))
コード例 #8
0
ファイル: test_data.py プロジェクト: rmulder/edx-platform
    def test_get_enrollments_including_inactive(self):
        """ Verify that if 'include_inactive' is True, all enrollments
        are returned including inactive.
        """
        course_modes, course_numbers = ['honor', 'verified',
                                        'audit'], ['1', '2', '3']
        created_courses = []
        for course_number in course_numbers:
            created_courses.append(CourseFactory.create(number=course_number))

        created_enrollments = []
        for course in created_courses:
            self._create_course_modes(course_modes, course=course)
            # Create the original enrollment.
            created_enrollments.append(
                data.create_course_enrollment(self.user.username,
                                              six.text_type(course.id),
                                              'honor', True))

        # deactivate one enrollment
        data.update_course_enrollment(self.user.username,
                                      six.text_type(created_courses[0].id),
                                      'honor', False)

        # by default in-active enrollment will be excluded.
        results = data.get_course_enrollments(self.user.username)
        assert len(results) != len(created_enrollments)

        # we can get all enrollments including inactive by passing "include_inactive"
        results = data.get_course_enrollments(self.user.username,
                                              include_inactive=True)
        assert len(results) == len(created_enrollments)
コード例 #9
0
ファイル: test_data.py プロジェクト: rmulder/edx-platform
    def test_get_course_enrollment(self, course_modes, enrollment_mode):
        self._create_course_modes(course_modes)

        # Try to get an enrollment before it exists.
        result = data.get_course_enrollment(self.user.username,
                                            six.text_type(self.course.id))
        assert result is None

        # Create the original enrollment.
        enrollment = data.create_course_enrollment(
            self.user.username, six.text_type(self.course.id), enrollment_mode,
            True)
        # Get the enrollment and compare it to the original.
        result = data.get_course_enrollment(self.user.username,
                                            six.text_type(self.course.id))
        assert self.user.username == result['user']
        assert enrollment == result
コード例 #10
0
ファイル: test_data.py プロジェクト: edx/edx-platform
    def test_get_course_enrollment(self, course_modes, enrollment_mode):
        self._create_course_modes(course_modes)

        # Try to get an enrollment before it exists.
        result = data.get_course_enrollment(self.user.username, six.text_type(self.course.id))
        self.assertIsNone(result)

        # Create the original enrollment.
        enrollment = data.create_course_enrollment(
            self.user.username,
            six.text_type(self.course.id),
            enrollment_mode,
            True
        )
        # Get the enrollment and compare it to the original.
        result = data.get_course_enrollment(self.user.username, six.text_type(self.course.id))
        self.assertEqual(self.user.username, result['user'])
        self.assertEqual(enrollment, result)
コード例 #11
0
ファイル: test_data.py プロジェクト: rmulder/edx-platform
    def test_enroll(self, course_modes, enrollment_mode):
        # Create the course modes (if any) required for this test case
        self._create_course_modes(course_modes)
        enrollment = data.create_course_enrollment(
            self.user.username, six.text_type(self.course.id), enrollment_mode,
            True)

        assert CourseEnrollment.is_enrolled(self.user, self.course.id)
        course_mode, is_active = CourseEnrollment.enrollment_mode_for_user(
            self.user, self.course.id)
        assert is_active
        assert course_mode == enrollment_mode

        # Confirm the returned enrollment and the data match up.
        assert course_mode == enrollment['mode']
        assert is_active == enrollment['is_active']
        assert self.course.display_name_with_default == enrollment[
            'course_details']['course_name']
コード例 #12
0
ファイル: test_data.py プロジェクト: edx/edx-platform
    def test_enroll(self, course_modes, enrollment_mode):
        # Create the course modes (if any) required for this test case
        self._create_course_modes(course_modes)
        enrollment = data.create_course_enrollment(
            self.user.username,
            six.text_type(self.course.id),
            enrollment_mode,
            True
        )

        self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course.id))
        course_mode, is_active = CourseEnrollment.enrollment_mode_for_user(self.user, self.course.id)
        self.assertTrue(is_active)
        self.assertEqual(course_mode, enrollment_mode)

        # Confirm the returned enrollment and the data match up.
        self.assertEqual(course_mode, enrollment['mode'])
        self.assertEqual(is_active, enrollment['is_active'])
        self.assertEqual(self.course.display_name_with_default, enrollment['course_details']['course_name'])
コード例 #13
0
ファイル: test_data.py プロジェクト: rmulder/edx-platform
 def test_enrollment_for_enrolled_course(self, mock_enroll):
     mock_enroll.side_effect = AlreadyEnrolledError("Bad things happened")
     with pytest.raises(CourseEnrollmentExistsError):
         data.create_course_enrollment(self.user.username,
                                       six.text_type(self.course.id),
                                       'honor', True)
コード例 #14
0
ファイル: test_data.py プロジェクト: uetuluk/edx-platform
 def test_enrollment_for_full_course(self, mock_enroll):
     mock_enroll.side_effect = CourseFullError("Bad things happened")
     with pytest.raises(CourseEnrollmentFullError):
         data.create_course_enrollment(self.user.username,
                                       str(self.course.id), 'honor', True)
コード例 #15
0
ファイル: test_data.py プロジェクト: rmulder/edx-platform
 def test_enrollment_for_non_existent_course(self):
     with pytest.raises(CourseNotFoundError):
         data.create_course_enrollment(self.user.username,
                                       "some/fake/course", 'honor', True)
コード例 #16
0
ファイル: test_data.py プロジェクト: rmulder/edx-platform
 def test_enrollment_for_non_existent_user(self):
     with pytest.raises(UserNotFoundError):
         data.create_course_enrollment("some_fake_user",
                                       six.text_type(self.course.id),
                                       'honor', True)
コード例 #17
0
ファイル: test_data.py プロジェクト: edx/edx-platform
 def test_enrollment_for_non_existent_user(self):
     with pytest.raises(UserNotFoundError):
         data.create_course_enrollment("some_fake_user", six.text_type(self.course.id), 'honor', True)
コード例 #18
0
ファイル: test_data.py プロジェクト: edx/edx-platform
 def test_enrollment_for_non_existent_course(self):
     with pytest.raises(CourseNotFoundError):
         data.create_course_enrollment(self.user.username, "some/fake/course", 'honor', True)
コード例 #19
0
ファイル: test_data.py プロジェクト: edx/edx-platform
 def test_enrollment_for_enrolled_course(self, mock_enroll):
     mock_enroll.side_effect = AlreadyEnrolledError("Bad things happened")
     with pytest.raises(CourseEnrollmentExistsError):
         data.create_course_enrollment(self.user.username, six.text_type(self.course.id), 'honor', True)