Exemple #1
0
    def test_update_enrollment_attributes(self):
        # Add fake course enrollment information to the fake data API
        fake_data_api.add_course(
            self.COURSE_ID,
            course_modes=['honor', 'verified', 'audit', 'credit'])
        # Enroll in the course and verify the URL we get sent to
        result = api.add_enrollment(self.USERNAME,
                                    self.COURSE_ID,
                                    mode='audit')
        get_result = api.get_enrollment(self.USERNAME, self.COURSE_ID)
        self.assertEquals(result, get_result)

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

        result = api.update_enrollment(
            self.USERNAME,
            self.COURSE_ID,
            mode='credit',
            enrollment_attributes=enrollment_attributes)
        self.assertEquals('credit', result['mode'])
        attributes = api.get_enrollment_attributes(self.USERNAME,
                                                   self.COURSE_ID)
        self.assertEquals(enrollment_attributes[0], attributes[0])
Exemple #2
0
 def test_get_course_details(self):
     # Add a fake course enrollment information to the fake data API
     fake_data_api.add_course(self.COURSE_ID,
                              course_modes=['honor', 'verified', 'audit'])
     result = api.get_course_enrollment_details(self.COURSE_ID)
     self.assertEquals(result['course_id'], self.COURSE_ID)
     self.assertEquals(3, len(result['course_modes']))
Exemple #3
0
 def test_unenroll_not_enrolled_in_course(self):
     # Add a fake course enrollment information to the fake data API
     fake_data_api.add_course(self.COURSE_ID, course_modes=['honor'])
     api.update_enrollment(self.USERNAME,
                           self.COURSE_ID,
                           mode='honor',
                           is_active=False)
 def assert_add_modes_with_enrollment(self, enrollment_mode):
     """ Dry method for adding fake course enrollment information to fake
     data API and enroll the student in the course. """
     fake_data_api.add_course(self.COURSE_ID, course_modes=['honor', 'verified', 'audit'])
     result = api.add_enrollment(self.USERNAME, self.COURSE_ID, mode=enrollment_mode)
     get_result = api.get_enrollment(self.USERNAME, self.COURSE_ID)
     self.assertEquals(result, get_result)
     # set the course verify mode as expire.
     fake_data_api.set_expired_mode(self.COURSE_ID)
Exemple #5
0
 def test_get_all_enrollments(self, enrollments):
     for enrollment in enrollments:
         fake_data_api.add_course(enrollment['course_id'], course_modes=enrollment['course_modes'])
         api.add_enrollment(self.USERNAME, enrollment['course_id'], enrollment['mode'])
     result = api.get_enrollments(self.USERNAME)
     self.assertEqual(len(enrollments), len(result))
     for result_enrollment in result:
         self.assertIn(
             result_enrollment['course']['course_id'],
             [enrollment['course_id'] for enrollment in enrollments]
         )
Exemple #6
0
    def test_enroll(self, course_modes, mode):
        # Add a fake course enrollment information to the fake data API
        fake_data_api.add_course(self.COURSE_ID, course_modes=course_modes)
        # Enroll in the course and verify the URL we get sent to
        result = api.add_enrollment(self.USERNAME, self.COURSE_ID, mode=mode)
        self.assertIsNotNone(result)
        self.assertEquals(result['student'], self.USERNAME)
        self.assertEquals(result['course']['course_id'], self.COURSE_ID)
        self.assertEquals(result['mode'], mode)

        get_result = api.get_enrollment(self.USERNAME, self.COURSE_ID)
        self.assertEquals(result, get_result)
Exemple #7
0
 def test_enroll_no_mode_success(self, course_modes, expected_mode):
     # Add a fake course enrollment information to the fake data API
     fake_data_api.add_course(self.COURSE_ID, course_modes=course_modes)
     with patch('enrollment.api.CourseMode.modes_for_course') as mock_modes_for_course:
         mock_course_modes = [Mock(slug=mode) for mode in course_modes]
         mock_modes_for_course.return_value = mock_course_modes
         # Enroll in the course and verify the URL we get sent to
         result = api.add_enrollment(self.USERNAME, self.COURSE_ID)
         self.assertIsNotNone(result)
         self.assertEquals(result['student'], self.USERNAME)
         self.assertEquals(result['course']['course_id'], self.COURSE_ID)
         self.assertEquals(result['mode'], expected_mode)
Exemple #8
0
 def assert_add_modes_with_enrollment(self, enrollment_mode):
     """ Dry method for adding fake course enrollment information to fake
     data API and enroll the student in the course. """
     fake_data_api.add_course(self.COURSE_ID,
                              course_modes=['honor', 'verified', 'audit'])
     result = api.add_enrollment(self.USERNAME,
                                 self.COURSE_ID,
                                 mode=enrollment_mode)
     get_result = api.get_enrollment(self.USERNAME, self.COURSE_ID)
     self.assertEquals(result, get_result)
     # set the course verify mode as expire.
     fake_data_api.set_expired_mode(self.COURSE_ID)
Exemple #9
0
    def test_update_enrollment(self):
        # Add fake course enrollment information to the fake data API
        fake_data_api.add_course(self.COURSE_ID, course_modes=['honor', 'verified', 'audit'])
        # Enroll in the course and verify the URL we get sent to
        result = api.add_enrollment(self.USERNAME, self.COURSE_ID, mode='audit')
        get_result = api.get_enrollment(self.USERNAME, self.COURSE_ID)
        self.assertEquals(result, get_result)

        result = api.update_enrollment(self.USERNAME, self.COURSE_ID, mode='honor')
        self.assertEquals('honor', result['mode'])

        result = api.update_enrollment(self.USERNAME, self.COURSE_ID, mode='verified')
        self.assertEquals('verified', result['mode'])
Exemple #10
0
 def test_enroll_no_mode_success(self, course_modes, expected_mode):
     # Add a fake course enrollment information to the fake data API
     fake_data_api.add_course(self.COURSE_ID, course_modes=course_modes)
     with patch('enrollment.api.CourseMode.modes_for_course'
                ) as mock_modes_for_course:
         mock_course_modes = [Mock(slug=mode) for mode in course_modes]
         mock_modes_for_course.return_value = mock_course_modes
         # Enroll in the course and verify the URL we get sent to
         result = api.add_enrollment(self.USERNAME, self.COURSE_ID)
         self.assertIsNotNone(result)
         self.assertEquals(result['student'], self.USERNAME)
         self.assertEquals(result['course']['course_id'], self.COURSE_ID)
         self.assertEquals(result['mode'], expected_mode)
Exemple #11
0
    def test_caching(self):
        # Add fake course enrollment information to the fake data API
        fake_data_api.add_course(self.COURSE_ID, course_modes=['honor', 'verified', 'audit'])

        # Hit the fake data API.
        details = api.get_course_enrollment_details(self.COURSE_ID)

        # Reset the fake data API, should rely on the cache.
        fake_data_api.reset()
        cached_details = api.get_course_enrollment_details(self.COURSE_ID)

        # The data matches
        self.assertEqual(len(details['course_modes']), 3)
        self.assertEqual(details, cached_details)
Exemple #12
0
    def test_update_enrollment_attributes(self):
        # Add fake course enrollment information to the fake data API
        fake_data_api.add_course(self.COURSE_ID, course_modes=['honor', 'verified', 'audit', 'credit'])
        # Enroll in the course and verify the URL we get sent to
        result = api.add_enrollment(self.USERNAME, self.COURSE_ID, mode='audit')
        get_result = api.get_enrollment(self.USERNAME, self.COURSE_ID)
        self.assertEquals(result, get_result)

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

        result = api.update_enrollment(
            self.USERNAME, self.COURSE_ID, mode='credit', enrollment_attributes=enrollment_attributes
        )
        self.assertEquals('credit', result['mode'])
        attributes = api.get_enrollment_attributes(self.USERNAME, self.COURSE_ID)
        self.assertEquals(enrollment_attributes[0], attributes[0])
Exemple #13
0
 def test_get_course_details(self):
     # Add a fake course enrollment information to the fake data API
     fake_data_api.add_course(self.COURSE_ID, course_modes=['honor', 'verified', 'audit'])
     result = api.get_course_enrollment_details(self.COURSE_ID)
     self.assertEquals(result['course_id'], self.COURSE_ID)
     self.assertEquals(3, len(result['course_modes']))
Exemple #14
0
 def test_enroll_no_mode_error(self, course_modes):
     # Add a fake course enrollment information to the fake data API
     fake_data_api.add_course(self.COURSE_ID, course_modes=course_modes)
     # Enroll in the course and verify that we raise CourseModeNotFoundError
     api.add_enrollment(self.USERNAME, self.COURSE_ID)
Exemple #15
0
 def test_prof_ed_enroll(self):
     # Add a fake course enrollment information to the fake data API
     fake_data_api.add_course(self.COURSE_ID, course_modes=['professional'])
     # Enroll in the course and verify the URL we get sent to
     api.add_enrollment(self.USERNAME, self.COURSE_ID, mode='verified')
Exemple #16
0
 def test_unenroll_not_enrolled_in_course(self):
     # Add a fake course enrollment information to the fake data API
     fake_data_api.add_course(self.COURSE_ID, course_modes=['honor'])
     api.update_enrollment(self.USERNAME, self.COURSE_ID, mode='honor', is_active=False)
Exemple #17
0
 def test_enroll_no_mode_error(self, course_modes):
     # Add a fake course enrollment information to the fake data API
     fake_data_api.add_course(self.COURSE_ID, course_modes=course_modes)
     # Enroll in the course and verify that we raise CourseModeNotFoundError
     api.add_enrollment(self.USERNAME, self.COURSE_ID)