From 1b0eff52edbf229d55eaa7f82a3e0de33a7bd0fd Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Fri, 10 May 2013 10:01:10 -0400 Subject: [PATCH 1/4] create test cases to simulate error exporting/importing textbooks --- cms/djangoapps/contentstore/tests/test_contentstore.py | 8 ++++++++ common/test/data/full/course.xml | 2 +- common/test/data/full/course/6.002_Spring_2012.xml | 5 +++-- lms/djangoapps/courseware/tests/tests.py | 8 ++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 07b7032e60..7879ae9222 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -220,6 +220,14 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): num_drafts = self._get_draft_counts(course) self.assertEqual(num_drafts, 1) + def test_import_textbook_as_content_element(self): + import_from_xml(modulestore(), 'common/test/data/', ['full']) + + module_store = modulestore('direct') + course = module_store.get_item(Location(['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None])) + + self.assertGreater(len(course.textbooks), 0) + def test_static_tab_reordering(self): import_from_xml(modulestore(), 'common/test/data/', ['full']) diff --git a/common/test/data/full/course.xml b/common/test/data/full/course.xml index 4f093a1128..7a05db42f2 100644 --- a/common/test/data/full/course.xml +++ b/common/test/data/full/course.xml @@ -1 +1 @@ - + diff --git a/common/test/data/full/course/6.002_Spring_2012.xml b/common/test/data/full/course/6.002_Spring_2012.xml index 0d22e96beb..e0beb5a3ee 100644 --- a/common/test/data/full/course/6.002_Spring_2012.xml +++ b/common/test/data/full/course/6.002_Spring_2012.xml @@ -1,4 +1,5 @@ - + + @@ -9,4 +10,4 @@ - + diff --git a/lms/djangoapps/courseware/tests/tests.py b/lms/djangoapps/courseware/tests/tests.py index d5064ec5e5..235f7d60bb 100644 --- a/lms/djangoapps/courseware/tests/tests.py +++ b/lms/djangoapps/courseware/tests/tests.py @@ -399,6 +399,14 @@ class TestCoursesLoadTestCase_MongoModulestore(PageLoaderTestCase): import_from_xml(module_store, TEST_DATA_DIR, ['toy']) self.check_random_page_loads(module_store) + def test_full_textbooks_loads(self): + module_store = modulestore() + import_from_xml(module_store, TEST_DATA_DIR, ['full']) + + course = module_store.get_item(Location(['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None])) + + self.assertGreater(len(course.textbooks), 0) + @override_settings(MODULESTORE=TEST_DATA_XML_MODULESTORE) class TestNavigation(LoginEnrollmentTestCase): From d95e87cf6734ae0eede773bdd61ccf4e5f24db65 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Sat, 11 May 2013 10:34:36 -0400 Subject: [PATCH 2/4] insert the textbook XML element when writing definition to xml --- common/lib/xmodule/xmodule/course_module.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 5efd7b4005..2a34b75a1f 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -382,6 +382,19 @@ class CourseDescriptor(CourseFields, SequenceDescriptor): return definition, children + def definition_to_xml(self, resource_fs): + xml_object = super(CourseDescriptor, self).definition_to_xml(resource_fs) + + if len(self.textbooks) > 0: + textbook_xml_object = etree.Element('textbook') + for textbook in self.textbooks: + textbook_xml_object.set('title', textbook.title) + textbook_xml_object.set('book_url', textbook.book_url) + + xml_object.append(textbook_xml_object) + + return xml_object + def has_ended(self): """ Returns True if the current time is after the specified course end date. From 3cf865a88f9a41022f7446a089bcc5627a89d489 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Mon, 13 May 2013 10:16:18 -0400 Subject: [PATCH 3/4] added another unit test check point for export/import of classic textbooks --- cms/djangoapps/contentstore/tests/test_contentstore.py | 7 ++++++- common/lib/xmodule/xmodule/course_module.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 273a276c00..927df009bf 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -226,7 +226,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): module_store = modulestore('direct') course = module_store.get_item(Location(['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None])) - self.assertGreater(len(course.textbooks), 0) + self.assertGreater(len(course.textbooks), 0) def test_static_tab_reordering(self): import_from_xml(modulestore(), 'common/test/data/', ['full']) @@ -498,6 +498,11 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): self.assertTrue(getattr(test_private_vertical, 'is_draft', False)) + # make sure the textbook survived the export/import + course = module_store.get_item(Location(['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None])) + + self.assertGreater(len(course.textbooks), 0) + shutil.rmtree(root_dir) def test_course_handouts_rewrites(self): diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 2a34b75a1f..063e53aef4 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -392,7 +392,7 @@ class CourseDescriptor(CourseFields, SequenceDescriptor): textbook_xml_object.set('book_url', textbook.book_url) xml_object.append(textbook_xml_object) - + return xml_object def has_ended(self): From 4d197e10ec3f25225e4b8b02e78d52c5b2d27d56 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Mon, 13 May 2013 11:10:11 -0400 Subject: [PATCH 4/4] fix some violations. Build up karma --- .../contentstore/tests/test_contentstore.py | 3 +- .../contentstore/tests/test_course_updates.py | 75 +++++++++---------- .../contentstore/tests/test_i18n.py | 29 ++++--- 3 files changed, 52 insertions(+), 55 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 927df009bf..c11b350349 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -226,7 +226,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): module_store = modulestore('direct') course = module_store.get_item(Location(['i4x', 'edX', 'full', 'course', '6.002_Spring_2012', None])) - self.assertGreater(len(course.textbooks), 0) + self.assertGreater(len(course.textbooks), 0) def test_static_tab_reordering(self): import_from_xml(modulestore(), 'common/test/data/', ['full']) @@ -301,7 +301,6 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): # make sure the parent no longer points to the child object which was deleted self.assertFalse(sequential.location.url() in chapter.children) - def test_about_overrides(self): ''' This test case verifies that a course can use specialized override for about data, e.g. /about/Fall_2012/effort.html diff --git a/cms/djangoapps/contentstore/tests/test_course_updates.py b/cms/djangoapps/contentstore/tests/test_course_updates.py index 80d4f0bbc2..ae14555b32 100644 --- a/cms/djangoapps/contentstore/tests/test_course_updates.py +++ b/cms/djangoapps/contentstore/tests/test_course_updates.py @@ -10,9 +10,9 @@ class CourseUpdateTest(CourseTestCase): '''Go through each interface and ensure it works.''' # first get the update to force the creation url = reverse('course_info', - kwargs={'org': self.course_location.org, - 'course': self.course_location.course, - 'name': self.course_location.name}) + kwargs={'org': self.course_location.org, + 'course': self.course_location.course, + 'name': self.course_location.name}) self.client.get(url) init_content = '