Commit 2dd26a8d by Waheed Ahmed

Fixed split get_courses.

PLAT-747
parent ee0cd9e8
...@@ -865,17 +865,18 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase): ...@@ -865,17 +865,18 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
# collect ids and then query for those # collect ids and then query for those
version_guids = [] version_guids = []
id_version_map = {} id_version_map = defaultdict(list)
for course_index in matching_indexes: for course_index in matching_indexes:
version_guid = course_index['versions'][branch] version_guid = course_index['versions'][branch]
version_guids.append(version_guid) version_guids.append(version_guid)
id_version_map[version_guid] = course_index id_version_map[version_guid].append(course_index)
if not version_guids: if not version_guids:
return return
for entry in self.find_structures_by_id(version_guids): for entry in self.find_structures_by_id(version_guids):
yield entry, id_version_map[entry['_id']] for course_index in id_version_map[entry['_id']]:
yield entry, course_index
def _get_structures_for_branch_and_locator(self, branch, locator_factory, **kwargs): def _get_structures_for_branch_and_locator(self, branch, locator_factory, **kwargs):
......
...@@ -625,6 +625,26 @@ class SplitModuleCourseTests(SplitModuleTest): ...@@ -625,6 +625,26 @@ class SplitModuleCourseTests(SplitModuleTest):
self.assertDictEqual(course.grade_cutoffs, {"Pass": 0.45}) self.assertDictEqual(course.grade_cutoffs, {"Pass": 0.45})
@patch('xmodule.tabs.CourseTab.from_json', side_effect=mock_tab_from_json) @patch('xmodule.tabs.CourseTab.from_json', side_effect=mock_tab_from_json)
def test_get_courses_with_same_course_index(self, _from_json):
"""
Test that if two courses pointing to same course index,
get_courses should return both.
"""
courses = modulestore().get_courses(branch=BRANCH_NAME_DRAFT)
# Should have gotten 3 draft courses.
self.assertEqual(len(courses), 3)
course_index = modulestore().get_course_index_info(courses[0].id)
# Creating a new course with same course index of another course.
new_draft_course = modulestore().create_course(
'testX', 'rerun_2.0', 'run_q2', 1, BRANCH_NAME_DRAFT, versions_dict=course_index['versions']
)
courses = modulestore().get_courses(branch=BRANCH_NAME_DRAFT)
# Should have gotten 4 draft courses.
self.assertEqual(len(courses), 4)
self.assertIn(new_draft_course.id.version_agnostic(), [c.id for c in courses])
@patch('xmodule.tabs.CourseTab.from_json', side_effect=mock_tab_from_json)
def test_get_org_courses(self, _from_json): def test_get_org_courses(self, _from_json):
courses = modulestore().get_courses(branch=BRANCH_NAME_DRAFT, org='guestx') courses = modulestore().get_courses(branch=BRANCH_NAME_DRAFT, org='guestx')
......
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