Support unicode in course ids when dumping all courses
Fixes: AN-657
This commit is contained in:
@@ -11,6 +11,9 @@ from xmodule.modulestore.django import modulestore
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
Simple command to dump the course_ids available to the lms.
|
||||
|
||||
Output is UTF-8 encoded by default.
|
||||
|
||||
"""
|
||||
help = dedent(__doc__).strip()
|
||||
option_list = BaseCommand.option_list + (
|
||||
@@ -21,7 +24,7 @@ class Command(BaseCommand):
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
output = []
|
||||
results = []
|
||||
|
||||
try:
|
||||
name = options['modulestore']
|
||||
@@ -31,6 +34,8 @@ class Command(BaseCommand):
|
||||
|
||||
for course in store.get_courses():
|
||||
course_id = course.location.course_id
|
||||
output.append(course_id)
|
||||
results.append(course_id)
|
||||
|
||||
return '\n'.join(output) + '\n'
|
||||
output = '\n'.join(results) + '\n'
|
||||
|
||||
return output.encode('utf-8')
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# coding=utf-8
|
||||
|
||||
"""Tests for Django management commands"""
|
||||
|
||||
import json
|
||||
@@ -18,6 +20,7 @@ from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE
|
||||
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from xmodule.modulestore.xml_importer import import_from_xml
|
||||
|
||||
DATA_DIR = 'common/test/data/'
|
||||
@@ -41,6 +44,14 @@ class CommandsTestBase(TestCase):
|
||||
"""Load test courses and return list of ids"""
|
||||
store = modulestore()
|
||||
|
||||
# Add a course with a unicode name, if the modulestore
|
||||
# supports adding modules.
|
||||
if hasattr(store, 'create_xmodule'):
|
||||
CourseFactory.create(org=u'édX',
|
||||
course=u'śíḿṕĺé',
|
||||
display_name=u'2012_Fáĺĺ',
|
||||
modulestore=store)
|
||||
|
||||
courses = store.get_courses()
|
||||
if TEST_COURSE_ID not in [c.id for c in courses]:
|
||||
import_from_xml(store, DATA_DIR, ['toy', 'simple'])
|
||||
@@ -57,7 +68,8 @@ class CommandsTestBase(TestCase):
|
||||
def test_dump_course_ids(self):
|
||||
kwargs = {'modulestore': 'default'}
|
||||
output = self.call_command('dump_course_ids', **kwargs)
|
||||
dumped_courses = output.strip().split('\n')
|
||||
dumped_courses = output.decode('utf-8').strip().split('\n')
|
||||
|
||||
self.assertEqual(self.loaded_courses, dumped_courses)
|
||||
|
||||
def test_dump_course_structure(self):
|
||||
|
||||
Reference in New Issue
Block a user