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)
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))
def test_unenroll(self): # Enroll the user in the course CourseEnrollment.enroll(self.user, self.course.id, mode="honor") enrollment = data.update_course_enrollment(self.user.username, str(self.course.id), is_active=False) # Determine that the returned enrollment is inactive. assert not enrollment['is_active'] # Expect that we're no longer enrolled assert not CourseEnrollment.is_enrolled(self.user, self.course.id)
def test_unenroll(self): # Enroll the user in the course CourseEnrollment.enroll(self.user, self.course.id, mode="honor") enrollment = data.update_course_enrollment( self.user.username, six.text_type(self.course.id), is_active=False ) # Determine that the returned enrollment is inactive. self.assertFalse(enrollment['is_active']) # Expect that we're no longer enrolled self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id))
def test_update_for_non_existent_course(self): enrollment = data.update_course_enrollment(self.user.username, "some/fake/course", is_active=False) assert enrollment is None
def test_update_for_non_existent_user(self): with pytest.raises(UserNotFoundError): data.update_course_enrollment("some_fake_user", six.text_type(self.course.id), is_active=False)
def test_update_for_non_existent_course(self): enrollment = data.update_course_enrollment(self.user.username, "some/fake/course", is_active=False) self.assertIsNone(enrollment)
def test_update_for_non_existent_user(self): with pytest.raises(UserNotFoundError): data.update_course_enrollment("some_fake_user", six.text_type(self.course.id), is_active=False)