From cf71f4858946446807c5f2889fa0132b24b0ff68 Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Tue, 15 Sep 2015 12:06:20 -0400 Subject: [PATCH 1/2] update_course_index should be passed a course key as a kwarg --- common/lib/xmodule/xmodule/modulestore/split_mongo/split.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py index 95cf99e00c..379f5f04ba 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py @@ -312,7 +312,7 @@ class SplitBulkWriteMixin(BulkOperationsMixin): if bulk_write_record.active: bulk_write_record.index = updated_index_entry else: - self.db_connection.update_course_index(updated_index_entry, course_key) + self.db_connection.update_course_index(updated_index_entry, course_context=course_key) def get_structure(self, course_key, version_guid): bulk_write_record = self._get_bulk_ops_record(course_key) From 8dd95a8825b74e1215c62a79978227742fa3a107 Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Tue, 15 Sep 2015 13:18:04 -0400 Subject: [PATCH 2/2] add test for fix_not_found (PLAT-835) (TNL-844) --- .../commands/tests/test_fix_not_found.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 cms/djangoapps/contentstore/management/commands/tests/test_fix_not_found.py diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_fix_not_found.py b/cms/djangoapps/contentstore/management/commands/tests/test_fix_not_found.py new file mode 100644 index 0000000000..bd519a4167 --- /dev/null +++ b/cms/djangoapps/contentstore/management/commands/tests/test_fix_not_found.py @@ -0,0 +1,47 @@ +""" +Tests for the fix_not_found management command +""" + +from django.core.management import call_command +from xmodule.modulestore import ModuleStoreEnum +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory + + +class TestFixNotFound(ModuleStoreTestCase): + """ + Tests for the fix_not_found management command + """ + def test_fix_not_found_non_split(self): + """ + The management command doesn't work on non split courses + """ + course = CourseFactory(default_store=ModuleStoreEnum.Type.mongo) + with self.assertRaises(SystemExit): + call_command("fix_not_found", unicode(course.id)) + + def test_fix_not_found(self): + course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split) + ItemFactory.create(category='chapter', parent_location=course.location) + + # get course again in order to update its children list + course = self.store.get_course(course.id) + + # create a dangling usage key that we'll add to the course's children list + dangling_pointer = course.id.make_usage_key('chapter', 'DanglingPointer') + + course.children.append(dangling_pointer) + self.store.update_item(course, self.user.id) + + # the course block should now point to two children, one of which + # doesn't actually exist + self.assertEqual(len(course.children), 2) + self.assertIn(dangling_pointer, course.children) + + call_command("fix_not_found", unicode(course.id)) + + # make sure the dangling pointer was removed from + # the course block's children + course = self.store.get_course(course.id) + self.assertEqual(len(course.children), 1) + self.assertNotIn(dangling_pointer, course.children)