From 9ecf2c00c09c309a7af73f3a1afe23dbebcd455e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s=20Rocha?= Date: Wed, 12 Mar 2014 16:12:18 -0400 Subject: [PATCH] Support unicode in course ids when dumping all courses Fixes: AN-657 --- .../management/commands/dump_course_ids.py | 11 ++++++++--- .../management/commands/tests/__init__.py | 0 .../management/commands/tests/test_dump_course.py | 14 +++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 lms/djangoapps/courseware/management/commands/tests/__init__.py diff --git a/lms/djangoapps/courseware/management/commands/dump_course_ids.py b/lms/djangoapps/courseware/management/commands/dump_course_ids.py index 749b64f6a7..8cba528bb1 100644 --- a/lms/djangoapps/courseware/management/commands/dump_course_ids.py +++ b/lms/djangoapps/courseware/management/commands/dump_course_ids.py @@ -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') diff --git a/lms/djangoapps/courseware/management/commands/tests/__init__.py b/lms/djangoapps/courseware/management/commands/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py b/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py index e45ed8b235..4f446f3698 100644 --- a/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py +++ b/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py @@ -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):