def handle(self, *args, **options): try: # a course key may have unicode chars in it try: course_key = text_type(options['course_key'], 'utf8') # May already be decoded to unicode if coming in through tests, this is ok. except TypeError: course_key = text_type(options['course_key']) course_key = CourseKey.from_string(course_key) except InvalidKeyError: raise CommandError(u'Invalid course_key: {}'.format( options['course_key'])) if not modulestore().get_course(course_key): raise CommandError(u'Course not found: {}'.format( options['course_key'])) print(u'Preparing to delete course %s from module store....' % options['course_key']) if query_yes_no(u'Are you sure you want to delete course {}?'.format( course_key), default='no'): if query_yes_no(u'Are you sure? This action cannot be undone!', default='no'): delete_course(course_key, ModuleStoreEnum.UserID.mgmt_command, options['keep_instructors']) if options['remove_assets']: contentstore().delete_all_course_assets(course_key) print(u'Deleted assets for course'.format(course_key)) print(u'Deleted course {}'.format(course_key))
def test_get_course_list_with_invalid_course_location(self, store): """ Test getting courses with invalid course location (course deleted from modulestore). """ with self.store.default_store(store): course_key = self.store.make_course_key('Org', 'Course', 'Run') self._create_course_with_access_groups(course_key, self.user, store) # get courses through iterating all courses courses_iter, __ = _accessible_courses_iter_for_tests(self.request) courses_list = list(courses_iter) self.assertEqual(len(courses_list), 1) courses_summary_iter, __ = _accessible_courses_summary_iter( self.request) courses_summary_list = list(courses_summary_iter) # Verify fetched accessible courses list is a list of CourseSummery instances and only one course # is returned self.assertTrue( all( isinstance(course, CourseSummary) for course in courses_summary_list)) self.assertEqual(len(courses_summary_list), 1) # get courses by reversing group name formats courses_list_by_groups, __ = _accessible_courses_list_from_groups( self.request) self.assertEqual(len(courses_list_by_groups), 1) course_keys_in_course_list = [course.id for course in courses_list] course_keys_in_courses_list_by_groups = [ course.id for course in courses_list_by_groups ] # check course lists have same courses self.assertEqual(course_keys_in_course_list, course_keys_in_courses_list_by_groups) # now delete this course and re-add user to instructor group of this course delete_course(course_key, self.user.id) CourseInstructorRole(course_key).add_users(self.user) # Get courses through iterating all courses courses_iter, __ = _accessible_courses_iter_for_tests(self.request) # Get course summaries by iterating all courses courses_summary_iter, __ = _accessible_courses_summary_iter( self.request) # Get courses by reversing group name formats courses_list_by_groups, __ = _accessible_courses_list_from_groups( self.request) # Test that course list returns no course self.assertEqual([ len(list(courses_iter)), len(courses_list_by_groups), len(list(courses_summary_iter)) ], [0, 0, 0])
def handle(self, *args, **options): try: course_key = CourseKey.from_string(options['course_key']) except InvalidKeyError: raise CommandError('Invalid course_key: {}'.format( options['course_key'])) if not modulestore().get_course(course_key): raise CommandError('Course not found: {}'.format( options['course_key'])) print('Preparing to delete course %s from module store....' % options['course_key']) if query_yes_no('Are you sure you want to delete course {}?'.format( course_key), default='no'): if query_yes_no('Are you sure? This action cannot be undone!', default='no'): delete_course(course_key, ModuleStoreEnum.UserID.mgmt_command, options['keep_instructors']) if options['remove_assets']: contentstore().delete_all_course_assets(course_key) print('Deleted assets for course'.format(course_key)) print('Deleted course {}'.format(course_key))
def handle(self, *args, **options): try: # a course key may have unicode chars in it try: course_key = text_type(options['course_key'], 'utf8') # May already be decoded to unicode if coming in through tests, this is ok. except TypeError: course_key = text_type(options['course_key']) course_key = CourseKey.from_string(course_key) except InvalidKeyError: raise CommandError(u'Invalid course_key: {}'.format(options['course_key'])) if not modulestore().get_course(course_key): raise CommandError(u'Course not found: {}'.format(options['course_key'])) print(u'Preparing to delete course %s from module store....' % options['course_key']) if query_yes_no(u'Are you sure you want to delete course {}?'.format(course_key), default='no'): if query_yes_no(u'Are you sure? This action cannot be undone!', default='no'): delete_course(course_key, ModuleStoreEnum.UserID.mgmt_command, options['keep_instructors']) if options['remove_assets']: contentstore().delete_all_course_assets(course_key) print(u'Deleted assets for course'.format(course_key)) print(u'Deleted course {}'.format(course_key))
def handle(self, *args, **options): try: course_key = CourseKey.from_string(options['course_key']) except InvalidKeyError: raise CommandError("Invalid course_key: '%s'." % options['course_key']) if not modulestore().get_course(course_key): raise CommandError("Course with '%s' key not found." % options['course_key']) print 'Going to delete the %s course from DB....' % options['course_key'] if query_yes_no("Deleting course {0}. Confirm?".format(course_key), default="no"): if query_yes_no("Are you sure. This action cannot be undone!", default="no"): delete_course(course_key, ModuleStoreEnum.UserID.mgmt_command, options['keep_instructors']) print "Deleted course {}".format(course_key)
def test_get_course_list_with_invalid_course_location(self, store): """ Test getting courses with invalid course location (course deleted from modulestore). """ with self.store.default_store(store): course_key = self.store.make_course_key('Org', 'Course', 'Run') self._create_course_with_access_groups(course_key, self.user, store) # get courses through iterating all courses courses_iter, __ = _accessible_courses_iter_for_tests(self.request) courses_list = list(courses_iter) self.assertEqual(len(courses_list), 1) courses_summary_iter, __ = _accessible_courses_summary_iter(self.request) courses_summary_list = list(courses_summary_iter) # Verify fetched accessible courses list is a list of CourseSummery instances and only one course # is returned self.assertTrue(all(isinstance(course, CourseSummary) for course in courses_summary_list)) self.assertEqual(len(courses_summary_list), 1) # get courses by reversing group name formats courses_list_by_groups, __ = _accessible_courses_list_from_groups(self.request) self.assertEqual(len(courses_list_by_groups), 1) course_keys_in_course_list = [course.id for course in courses_list] course_keys_in_courses_list_by_groups = [course.id for course in courses_list_by_groups] # check course lists have same courses self.assertEqual(course_keys_in_course_list, course_keys_in_courses_list_by_groups) # now delete this course and re-add user to instructor group of this course delete_course(course_key, self.user.id) CourseInstructorRole(course_key).add_users(self.user) # Get courses through iterating all courses courses_iter, __ = _accessible_courses_iter_for_tests(self.request) # Get course summaries by iterating all courses courses_summary_iter, __ = _accessible_courses_summary_iter(self.request) # Get courses by reversing group name formats courses_list_by_groups, __ = _accessible_courses_list_from_groups(self.request) # Test that course list returns no course self.assertEqual( [len(list(courses_iter)), len(courses_list_by_groups), len(list(courses_summary_iter))], [0, 0, 0] )
def test_user_forum_default_role_on_course_deletion(self): """ Test that a user enrolls and gets "Student" forum role for that course which he creates and remains enrolled even the course is deleted and keeps its "Student" forum role for that course """ # check that user has enrollment for this course self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_key)) # check that user has his default "Student" forum role for this course self.assertTrue(self.user.roles.filter(name="Student", course_id=self.course_key)) delete_course(self.course_key, self.user.id) # check that user's enrollment for this course is not deleted self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_key)) # check that user has forum role for this course even after deleting it self.assertTrue(self.user.roles.filter(name="Student", course_id=self.course_key))
def test_user_role_on_course_recreate_with_change_name_case(self): """ Test that creating same course again with different name case after deleting it gives user his default forum role "Student" for that course """ # check that user has enrollment and his default "Student" forum role for this course self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_key)) # delete this course and recreate this course with same user delete_course(self.course_key, self.user.id) # now create same course with different name case ('uppercase') new_course_key = self.course_key.replace(course=self.course_key.course.upper()) resp = self._create_course_with_given_location(new_course_key) self.assertEqual(resp.status_code, 200) # check that user has his default "Student" forum role again for this course (with changed name case) self.assertTrue( self.user.roles.filter(name="Student", course_id=new_course_key) )
def test_user_role_on_course_recreate(self): """ Test that creating same course again after deleting it gives user his default forum role "Student" for that course """ # check that user has enrollment and his default "Student" forum role for this course self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_key)) self.assertTrue(self.user.roles.filter(name="Student", course_id=self.course_key)) # delete this course and recreate this course with same user delete_course(self.course_key, self.user.id) resp = self._create_course_with_given_location(self.course_key) self.assertEqual(resp.status_code, 200) # check that user has his enrollment for this course self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_key)) # check that user has his default "Student" forum role for this course self.assertTrue(self.user.roles.filter(name="Student", course_id=self.course_key))