Updates after review feedback.

This commit is contained in:
Douglas Hall
2018-04-11 16:04:54 -04:00
parent 4d72d9caae
commit a2f5210969
4 changed files with 15 additions and 11 deletions

View File

@@ -77,7 +77,7 @@ class CcxRestApiTest(CcxTestCase, APITestCase):
self.course.enable_ccx = True
self.mstore.update_item(self.course, self.coach.id)
# making the master course chapters easily available
self.master_course_chapters = courses.get_course_chapters(self.master_course_key)
self.master_course_chapters = courses.get_course_chapter_ids(self.master_course_key)
def get_auth_token(self, app_grant, app_client):
"""

View File

@@ -186,7 +186,7 @@ def valid_course_modules(course_module_list, master_course_key):
Returns:
bool: whether or not all the course module strings belong to the master course
"""
course_chapters = courses.get_course_chapters(master_course_key)
course_chapters = courses.get_course_chapter_ids(master_course_key)
return set(course_module_list).intersection(set(course_chapters)) == set(course_module_list)

View File

@@ -595,7 +595,7 @@ def get_current_child(xmodule, min_depth=None, requested_child=None):
return child
def get_course_chapters(course_key):
def get_course_chapter_ids(course_key):
"""
Extracts the chapter block keys from a course structure.
@@ -605,7 +605,8 @@ def get_course_chapters(course_key):
list (string): The list of string representations of the chapter block keys in the course.
"""
try:
chapters = modulestore().get_items(course_key, qualifiers={'category': 'chapter'})
chapter_keys = modulestore().get_course(course_key).children
except Exception: # pylint: disable=broad-except
log.exception('Failed to retrieve course from modulestore.')
return []
return [unicode(chapter.location) for chapter in chapters]
return [unicode(chapter_key) for chapter_key in chapter_keys if chapter_key.block_type == 'chapter']

View File

@@ -22,7 +22,7 @@ from courseware.courses import (
get_cms_course_link,
get_course_about_section,
get_course_by_id,
get_course_chapters,
get_course_chapter_ids,
get_course_info_section,
get_course_overview_with_access,
get_course_with_access,
@@ -431,25 +431,28 @@ class CourseInstantiationTests(ModuleStoreTestCase):
@attr(shard=1)
class TestGetCourseChapters(ModuleStoreTestCase):
"""
Tests for the `get_course_chapters` function.
Tests for the `get_course_chapter_ids` function.
"""
def test_get_non_existant_course(self):
"""
Test non-existant course returns empty list.
"""
self.assertEqual(get_course_chapters(None), [])
self.assertEqual(get_course_chapter_ids(None), [])
# build a fake key
fake_course_key = CourseKey.from_string('course-v1:FakeOrg+CN1+CR-FALLNEVER1')
self.assertEqual(get_course_chapters(fake_course_key), [])
self.assertEqual(get_course_chapter_ids(fake_course_key), [])
def test_get_chapters(self):
"""
Test get_course_chapters returns expected result.
Test get_course_chapter_ids returns expected result.
"""
course = CourseFactory()
ItemFactory(parent=course, category='chapter')
ItemFactory(parent=course, category='chapter')
course_chapter_ids = get_course_chapter_ids(course.location.course_key)
self.assertEqual(len(course_chapter_ids), 2)
self.assertEqual(
get_course_chapters(course.location.course_key),
course_chapter_ids,
[unicode(child) for child in course.children]
)