Commit 9ecf2c00 by Carlos Andrés Rocha

Support unicode in course ids when dumping all courses

Fixes: AN-657
parent acea6c83
...@@ -11,6 +11,9 @@ from xmodule.modulestore.django import modulestore ...@@ -11,6 +11,9 @@ from xmodule.modulestore.django import modulestore
class Command(BaseCommand): class Command(BaseCommand):
""" """
Simple command to dump the course_ids available to the lms. Simple command to dump the course_ids available to the lms.
Output is UTF-8 encoded by default.
""" """
help = dedent(__doc__).strip() help = dedent(__doc__).strip()
option_list = BaseCommand.option_list + ( option_list = BaseCommand.option_list + (
...@@ -21,7 +24,7 @@ class Command(BaseCommand): ...@@ -21,7 +24,7 @@ class Command(BaseCommand):
) )
def handle(self, *args, **options): def handle(self, *args, **options):
output = [] results = []
try: try:
name = options['modulestore'] name = options['modulestore']
...@@ -31,6 +34,8 @@ class Command(BaseCommand): ...@@ -31,6 +34,8 @@ class Command(BaseCommand):
for course in store.get_courses(): for course in store.get_courses():
course_id = course.location.course_id course_id = course.location.course_id
output.append(course_id) results.append(course_id)
output = '\n'.join(results) + '\n'
return '\n'.join(output) + '\n' return output.encode('utf-8')
# coding=utf-8
"""Tests for Django management commands""" """Tests for Django management commands"""
import json import json
...@@ -18,6 +20,7 @@ from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE ...@@ -18,6 +20,7 @@ from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.xml_importer import import_from_xml from xmodule.modulestore.xml_importer import import_from_xml
DATA_DIR = 'common/test/data/' DATA_DIR = 'common/test/data/'
...@@ -41,6 +44,14 @@ class CommandsTestBase(TestCase): ...@@ -41,6 +44,14 @@ class CommandsTestBase(TestCase):
"""Load test courses and return list of ids""" """Load test courses and return list of ids"""
store = modulestore() 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() courses = store.get_courses()
if TEST_COURSE_ID not in [c.id for c in courses]: if TEST_COURSE_ID not in [c.id for c in courses]:
import_from_xml(store, DATA_DIR, ['toy', 'simple']) import_from_xml(store, DATA_DIR, ['toy', 'simple'])
...@@ -57,7 +68,8 @@ class CommandsTestBase(TestCase): ...@@ -57,7 +68,8 @@ class CommandsTestBase(TestCase):
def test_dump_course_ids(self): def test_dump_course_ids(self):
kwargs = {'modulestore': 'default'} kwargs = {'modulestore': 'default'}
output = self.call_command('dump_course_ids', **kwargs) 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) self.assertEqual(self.loaded_courses, dumped_courses)
def test_dump_course_structure(self): def test_dump_course_structure(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment