When creating a course in studio set a unique wiki_slug for it.
Currently wiki_slug is set to course number. However, since multiple courses can have the same number this may lead to clashes. So wiki_slug will be set to org.course.name. To maintain the active wiki_slugs for xml courses this cannot be changed in the CourseDescriptor. LMS-2136
This commit is contained in:
@@ -1761,8 +1761,27 @@ class ContentStoreTest(ModuleStoreTestCase):
|
||||
self.assertEquals(course_module.pdf_textbooks[0]["chapters"][0]["url"], '/c4x/MITx/999/asset/Chapter1.pdf')
|
||||
self.assertEquals(course_module.pdf_textbooks[0]["chapters"][1]["url"], '/c4x/MITx/999/asset/Chapter2.pdf')
|
||||
|
||||
# check that URL slug got updated to new course slug
|
||||
self.assertEquals(course_module.wiki_slug, '999')
|
||||
def test_import_into_new_course_id_wiki_slug_renamespacing(self):
|
||||
module_store = modulestore('direct')
|
||||
target_location = Location('i4x', 'MITx', '999', 'course', '2013_Spring')
|
||||
course_data = {
|
||||
'org': target_location.org,
|
||||
'number': target_location.course,
|
||||
'display_name': 'Robot Super Course',
|
||||
'run': target_location.name
|
||||
}
|
||||
target_course_id = '{0}/{1}/{2}'.format(target_location.org, target_location.course, target_location.name)
|
||||
_create_course(self, course_data)
|
||||
|
||||
# Import a course with wiki_slug == location.course
|
||||
import_from_xml(module_store, 'common/test/data/', ['toy'], target_location_namespace=target_location)
|
||||
course_module = module_store.get_instance(target_location.course_id, target_location)
|
||||
self.assertEquals(course_module.wiki_slug, 'MITx.999.2013_Spring')
|
||||
|
||||
# Now try importing a course with wiki_slug == '{0}{1}{2}'.format(location.org, location.course, location.name)
|
||||
import_from_xml(module_store, 'common/test/data/', ['two_toys'], target_location_namespace=target_location)
|
||||
course_module = module_store.get_instance(target_course_id, target_location)
|
||||
self.assertEquals(course_module.wiki_slug, 'MITx.999.2013_Spring')
|
||||
|
||||
def test_import_metadata_with_attempts_empty_string(self):
|
||||
module_store = modulestore('direct')
|
||||
@@ -1915,6 +1934,14 @@ class ContentStoreTest(ModuleStoreTestCase):
|
||||
_test_no_locations(self, resp)
|
||||
return resp
|
||||
|
||||
def test_wiki_slug(self):
|
||||
"""When creating a course a unique wiki_slug should be set."""
|
||||
|
||||
course_location = Location(['i4x', 'MITx', '999', 'course', '2013_Spring'])
|
||||
_create_course(self, self.course_data)
|
||||
course_module = modulestore('direct').get_item(course_location)
|
||||
self.assertEquals(course_module.wiki_slug, 'MITx.999.2013_Spring')
|
||||
|
||||
|
||||
@override_settings(MODULESTORE=TEST_MODULESTORE)
|
||||
class MetadataSaveTestCase(ModuleStoreTestCase):
|
||||
|
||||
@@ -376,8 +376,15 @@ def create_new_course(request):
|
||||
metadata = {}
|
||||
else:
|
||||
metadata = {'display_name': display_name}
|
||||
|
||||
# Set a unique wiki_slug for newly created courses. To maintain active wiki_slugs for existing xml courses this
|
||||
# cannot be changed in CourseDescriptor.
|
||||
wiki_slug = "{0}.{1}.{2}".format(dest_location.org, dest_location.course, dest_location.name)
|
||||
definition_data = {'wiki_slug': wiki_slug}
|
||||
|
||||
modulestore('direct').create_and_save_xmodule(
|
||||
dest_location,
|
||||
definition_data=definition_data,
|
||||
metadata=metadata
|
||||
)
|
||||
new_course = modulestore('direct').get_item(dest_location)
|
||||
|
||||
@@ -514,11 +514,20 @@ def remap_namespace(module, target_location_namespace):
|
||||
chapter['url'], target_location_namespace
|
||||
)
|
||||
|
||||
# if there is a wiki_slug which is the same as the original location
|
||||
# (aka default value), then remap that so the wiki doesn't point to
|
||||
# the old Wiki.
|
||||
if module.wiki_slug == original_location.course:
|
||||
module.wiki_slug = target_location_namespace.course
|
||||
# Original wiki_slugs had value location.course. To make them unique this was changed to 'org.course.name'.
|
||||
# If the wiki_slug is equal to either of these default values then remap that so that the wiki does not point
|
||||
# to the old wiki.
|
||||
original_unique_wiki_slug = '{0}.{1}.{2}'.format(
|
||||
original_location.org,
|
||||
original_location.course,
|
||||
original_location.name
|
||||
)
|
||||
if module.wiki_slug == original_unique_wiki_slug or module.wiki_slug == original_location.course:
|
||||
module.wiki_slug = '{0}.{1}.{2}'.format(
|
||||
target_location_namespace.org,
|
||||
target_location_namespace.course,
|
||||
target_location_namespace.name,
|
||||
)
|
||||
|
||||
module.save()
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<course display_name="Toy Course" graceperiod="2 days 5 hours 59 minutes 59 seconds" start="2015-07-17T12:00">
|
||||
<chapter url_name="Overview"/>
|
||||
<wiki slug="edX.toy.TT_2012_Fall"/>
|
||||
</course>
|
||||
|
||||
Reference in New Issue
Block a user