def test_clone_course(self): course_data = { 'template': 'i4x://edx/templates/course/Empty', 'org': 'MITx', 'number': '999', 'display_name': 'Robot Super Course', } module_store = modulestore('direct') import_from_xml(module_store, 'common/test/data/', ['full']) resp = self.client.post(reverse('create_new_course'), course_data) self.assertEqual(resp.status_code, 200) data = parse_json(resp) self.assertEqual(data['id'], 'i4x://MITx/999/course/Robot_Super_Course') content_store = contentstore() source_location = CourseDescriptor.id_to_location('edX/full/6.002_Spring_2012') dest_location = CourseDescriptor.id_to_location('MITx/999/Robot_Super_Course') clone_course(module_store, content_store, source_location, dest_location) # now loop through all the units in the course and verify that the clone can render them, which # means the objects are at least present items = module_store.get_items(Location(['i4x', 'edX', 'full', 'vertical', None])) self.assertGreater(len(items), 0) clone_items = module_store.get_items(Location(['i4x', 'MITx', '999', 'vertical', None])) self.assertGreater(len(clone_items), 0) for descriptor in items: new_loc = descriptor.location.replace(org='MITx', course='999') print "Checking {0} should now also be at {1}".format(descriptor.location.url(), new_loc.url()) resp = self.client.get(reverse('edit_unit', kwargs={'location': new_loc.url()})) self.assertEqual(resp.status_code, 200)
def test_clone_course(self): course_data = { "template": "i4x://edx/templates/course/Empty", "org": "MITx", "number": "999", "display_name": "Robot Super Course", } module_store = modulestore("direct") import_from_xml(module_store, "common/test/data/", ["full"]) resp = self.client.post(reverse("create_new_course"), course_data) self.assertEqual(resp.status_code, 200) data = parse_json(resp) self.assertEqual(data["id"], "i4x://MITx/999/course/Robot_Super_Course") content_store = contentstore() source_location = CourseDescriptor.id_to_location("edX/full/6.002_Spring_2012") dest_location = CourseDescriptor.id_to_location("MITx/999/Robot_Super_Course") clone_course(module_store, content_store, source_location, dest_location) # now loop through all the units in the course and verify that the clone can render them, which # means the objects are at least present items = module_store.get_items(Location(["i4x", "edX", "full", "vertical", None])) self.assertGreater(len(items), 0) clone_items = module_store.get_items(Location(["i4x", "MITx", "999", "vertical", None])) self.assertGreater(len(clone_items), 0) for descriptor in items: new_loc = descriptor.location.replace(org="MITx", course="999") print "Checking {0} should now also be at {1}".format(descriptor.location.url(), new_loc.url()) resp = self.client.get(reverse("edit_unit", kwargs={"location": new_loc.url()})) self.assertEqual(resp.status_code, 200)
def handle(self, *args, **options): "Execute the command" if len(args) != 2: raise CommandError("clone requires two arguments: <source-course_id> <dest-course_id>") source_course_id = args[0] dest_course_id = args[1] mstore = modulestore('direct') cstore = contentstore() org, course_num, run = dest_course_id.split("/") mstore.ignore_write_events_on_courses.append('{0}/{1}'.format(org, course_num)) print("Cloning course {0} to {1}".format(source_course_id, dest_course_id)) source_location = CourseDescriptor.id_to_location(source_course_id) dest_location = CourseDescriptor.id_to_location(dest_course_id) if clone_course(mstore, cstore, source_location, dest_location): # be sure to recompute metadata inheritance after all those updates mstore.refresh_cached_metadata_inheritance_tree(dest_location) print("copying User permissions...") _copy_course_group(source_location, dest_location)
def handle(self, *args, **options): "Execute the command" if len(args) != 2: raise CommandError("clone requires 2 arguments: <source-course_id> <dest-course_id>") source_course_id = args[0] dest_course_id = args[1] mstore = modulestore('direct') cstore = contentstore() course_id_dict = Location.parse_course_id(dest_course_id) mstore.ignore_write_events_on_courses.append('{org}/{course}'.format(**course_id_dict)) print("Cloning course {0} to {1}".format(source_course_id, dest_course_id)) source_location = CourseDescriptor.id_to_location(source_course_id) dest_location = CourseDescriptor.id_to_location(dest_course_id) if clone_course(mstore, cstore, source_location, dest_location): # be sure to recompute metadata inheritance after all those updates mstore.refresh_cached_metadata_inheritance_tree(dest_location) print("copying User permissions...") # purposely avoids auth.add_user b/c it doesn't have a caller to authorize CourseInstructorRole(dest_location).add_users( *CourseInstructorRole(source_location).users_with_role() ) CourseStaffRole(dest_location).add_users( *CourseStaffRole(source_location).users_with_role() )
def handle(self, *args, **options): "Execute the command" if len(args) != 2: raise CommandError( "clone requires 2 arguments: <source-course_id> <dest-course_id>" ) source_course_id = args[0] dest_course_id = args[1] mstore = modulestore('direct') cstore = contentstore() course_id_dict = Location.parse_course_id(dest_course_id) mstore.ignore_write_events_on_courses.append( '{org}/{course}'.format(**course_id_dict)) print("Cloning course {0} to {1}".format(source_course_id, dest_course_id)) source_location = CourseDescriptor.id_to_location(source_course_id) dest_location = CourseDescriptor.id_to_location(dest_course_id) if clone_course(mstore, cstore, source_location, dest_location): # be sure to recompute metadata inheritance after all those updates mstore.refresh_cached_metadata_inheritance_tree(dest_location) print("copying User permissions...") # purposely avoids auth.add_user b/c it doesn't have a caller to authorize CourseInstructorRole(dest_location).add_users( *CourseInstructorRole(source_location).users_with_role()) CourseStaffRole(dest_location).add_users( *CourseStaffRole(source_location).users_with_role())
def handle(self, *args, **options): "Execute the command" if len(args) != 2: raise CommandError( "clone requires two arguments: <source-course_id> <dest-course_id>" ) source_course_id = args[0] dest_course_id = args[1] mstore = modulestore('direct') cstore = contentstore() org, course_num, run = dest_course_id.split("/") mstore.ignore_write_events_on_courses.append('{0}/{1}'.format( org, course_num)) print("Cloning course {0} to {1}".format(source_course_id, dest_course_id)) source_location = CourseDescriptor.id_to_location(source_course_id) dest_location = CourseDescriptor.id_to_location(dest_course_id) if clone_course(mstore, cstore, source_location, dest_location): # be sure to recompute metadata inheritance after all those updates mstore.refresh_cached_metadata_inheritance_tree(dest_location) print("copying User permissions...") _copy_course_group(source_location, dest_location)
def handle(self, *args, **options): "Execute the command" if len(args) != 2: raise CommandError( "clone requires 2 arguments: <source-course_id> <dest-course_id>" ) source_course_id = self.course_key_from_arg(args[0]) dest_course_id = self.course_key_from_arg(args[1]) mstore = modulestore('direct') cstore = contentstore() mstore.ignore_write_events_on_courses.add(dest_course_id) print("Cloning course {0} to {1}".format(source_course_id, dest_course_id)) if clone_course(mstore, cstore, source_course_id, dest_course_id): print("copying User permissions...") # purposely avoids auth.add_user b/c it doesn't have a caller to authorize CourseInstructorRole(dest_course_id).add_users( *CourseInstructorRole(source_course_id).users_with_role()) CourseStaffRole(dest_course_id).add_users( *CourseStaffRole(source_course_id).users_with_role())
def handle(self, *args, **options): if len(args) != 2: raise CommandError("clone requires two arguments: <source-location> <dest-location>") source_location_str = args[0] dest_location_str = args[1] ms = modulestore('direct') cs = contentstore() print "Cloning course {0} to {1}".format(source_location_str, dest_location_str) source_location = CourseDescriptor.id_to_location(source_location_str) dest_location = CourseDescriptor.id_to_location(dest_location_str) if clone_course(ms, cs, source_location, dest_location): print "copying User permissions..." _copy_course_group(source_location, dest_location)
def handle(self, *args, **options): if len(args) != 2: raise CommandError( "clone requires two arguments: <source-location> <dest-location>") source_location_str = args[0] dest_location_str = args[1] ms = modulestore('direct') cs = contentstore() print "Cloning course {0} to {1}".format(source_location_str, dest_location_str) source_location = CourseDescriptor.id_to_location(source_location_str) dest_location = CourseDescriptor.id_to_location(dest_location_str) if clone_course(ms, cs, source_location, dest_location): print "copying User permissions..." _copy_course_group(source_location, dest_location)
def handle(self, *args, **options): "Execute the command" if len(args) != 2: raise CommandError("clone requires 2 arguments: <source-course_id> <dest-course_id>") source_course_id = self.course_key_from_arg(args[0]) dest_course_id = self.course_key_from_arg(args[1]) mstore = modulestore() cstore = contentstore() print("Cloning course {0} to {1}".format(source_course_id, dest_course_id)) with store_bulk_write_operations_on_course(mstore, dest_course_id): if clone_course(mstore, cstore, source_course_id, dest_course_id, None): print("copying User permissions...") # purposely avoids auth.add_user b/c it doesn't have a caller to authorize CourseInstructorRole(dest_course_id).add_users( *CourseInstructorRole(source_course_id).users_with_role() ) CourseStaffRole(dest_course_id).add_users( *CourseStaffRole(source_course_id).users_with_role() )