def test_get_courses_for_wiki(self): """ Test the get_courses_for_wiki method """ store = XMLModuleStore(DATA_DIR, course_dirs=['toy', 'simple']) for course in store.get_courses(): course_locations = store.get_courses_for_wiki(course.wiki_slug) self.assertEqual(len(course_locations), 1) self.assertIn(course.location, course_locations) course_locations = store.get_courses_for_wiki('no_such_wiki') self.assertEqual(len(course_locations), 0) # now set toy course to share the wiki with simple course toy_course = store.get_course( SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')) toy_course.wiki_slug = 'simple' course_locations = store.get_courses_for_wiki('toy') self.assertEqual(len(course_locations), 0) course_locations = store.get_courses_for_wiki('simple') self.assertEqual(len(course_locations), 2) for course_number in ['toy', 'simple']: self.assertIn( Location('edX', course_number, '2012_Fall', 'course', '2012_Fall'), course_locations)
def test_cohort_config(self): """ Check that cohort config parsing works right. Note: The cohort config on the CourseModule is no longer used. See openedx.core.djangoapps.course_groups.models.CourseCohortSettings. """ modulestore = XMLModuleStore(DATA_DIR, source_dirs=['toy']) toy_id = CourseKey.from_string('edX/toy/2012_Fall') course = modulestore.get_course(toy_id) # No config -> False self.assertFalse(course.is_cohorted) # empty config -> False course.cohort_config = {} self.assertFalse(course.is_cohorted) # false config -> False course.cohort_config = {'cohorted': False} self.assertFalse(course.is_cohorted) # and finally... course.cohort_config = {'cohorted': True} self.assertTrue(course.is_cohorted)
def test_get_courses_for_wiki(self): """ Test the get_courses_for_wiki method """ store = XMLModuleStore(DATA_DIR, source_dirs=['toy', 'simple']) for course in store.get_courses(): course_locations = store.get_courses_for_wiki(course.wiki_slug) self.assertEqual(len(course_locations), 1) self.assertIn(course.location.course_key, course_locations) course_locations = store.get_courses_for_wiki('no_such_wiki') self.assertEqual(len(course_locations), 0) # now set toy course to share the wiki with simple course toy_course = store.get_course( CourseKey.from_string('edX/toy/2012_Fall')) toy_course.wiki_slug = 'simple' course_locations = store.get_courses_for_wiki('toy') self.assertEqual(len(course_locations), 0) course_locations = store.get_courses_for_wiki('simple') self.assertEqual(len(course_locations), 2) for course_number in ['toy', 'simple']: self.assertIn( CourseKey.from_string('/'.join( ['edX', course_number, '2012_Fall'])), course_locations)
def test_cohort_config(self): """ Check that cohort config parsing works right. Note: The cohort config on the CourseModule is no longer used. See openedx.core.djangoapps.course_groups.models.CourseCohortSettings. """ modulestore = XMLModuleStore(DATA_DIR, source_dirs=['toy']) toy_id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall') course = modulestore.get_course(toy_id) # No config -> False self.assertFalse(course.is_cohorted) # empty config -> False course.cohort_config = {} self.assertFalse(course.is_cohorted) # false config -> False course.cohort_config = {'cohorted': False} self.assertFalse(course.is_cohorted) # and finally... course.cohort_config = {'cohorted': True} self.assertTrue(course.is_cohorted)
def test_url_name_mangling(self): """ Make sure that url_names are only mangled once. """ modulestore = XMLModuleStore(DATA_DIR, source_dirs=['toy']) toy_id = CourseKey.from_string('edX/toy/2012_Fall') course = modulestore.get_course(toy_id) chapters = course.get_children() ch1 = chapters[0] sections = ch1.get_children() self.assertEqual(len(sections), 4) for i in (2, 3): video = sections[i] # Name should be 'video_{hash}' print("video {0} url_name: {1}".format(i, video.url_name)) self.assertEqual(len(video.url_name), len('video_') + 12)
def test_url_name_mangling(self): """ Make sure that url_names are only mangled once. """ modulestore = XMLModuleStore(DATA_DIR, source_dirs=['toy']) toy_id = CourseKey.from_string('edX/toy/2012_Fall') course = modulestore.get_course(toy_id) chapters = course.get_children() ch1 = chapters[0] sections = ch1.get_children() self.assertEqual(len(sections), 4) for i in (2, 3): video = sections[i] # Name should be 'video_{hash}' print("video {0} url_name: {1}".format(i, video.url_name)) self.assertEqual(len(video.url_name), len('video_') + 12)
def test_cohort_config(self): """ Check that cohort config parsing works right. """ modulestore = XMLModuleStore(DATA_DIR, course_dirs=['toy']) toy_id = "edX/toy/2012_Fall" course = modulestore.get_course(toy_id) # No config -> False self.assertFalse(course.is_cohorted) # empty config -> False course.cohort_config = {} self.assertFalse(course.is_cohorted) # false config -> False course.cohort_config = {'cohorted': False} self.assertFalse(course.is_cohorted) # and finally... course.cohort_config = {'cohorted': True} self.assertTrue(course.is_cohorted)
def test_cohort_config(self): """ Check that cohort config parsing works right. """ modulestore = XMLModuleStore(DATA_DIR, course_dirs=['toy']) toy_id = "edX/toy/2012_Fall" course = modulestore.get_course(toy_id) # No config -> False self.assertFalse(course.is_cohorted) # empty config -> False course.cohort_config = {} self.assertFalse(course.is_cohorted) # false config -> False course.cohort_config = {'cohorted': False} self.assertFalse(course.is_cohorted) # and finally... course.cohort_config = {'cohorted': True} self.assertTrue(course.is_cohorted)
def test_get_courses_for_wiki(self): """ Test the get_courses_for_wiki method """ store = XMLModuleStore(DATA_DIR, source_dirs=['toy', 'simple']) for course in store.get_courses(): course_locations = store.get_courses_for_wiki(course.wiki_slug) self.assertEqual(len(course_locations), 1) self.assertIn(course.location.course_key, course_locations) course_locations = store.get_courses_for_wiki('no_such_wiki') self.assertEqual(len(course_locations), 0) # now set toy course to share the wiki with simple course toy_course = store.get_course(CourseKey.from_string('edX/toy/2012_Fall')) toy_course.wiki_slug = 'simple' course_locations = store.get_courses_for_wiki('toy') self.assertEqual(len(course_locations), 0) course_locations = store.get_courses_for_wiki('simple') self.assertEqual(len(course_locations), 2) for course_number in ['toy', 'simple']: self.assertIn(CourseKey.from_string('/'.join(['edX', course_number, '2012_Fall'])), course_locations)
def test_get_courses_for_wiki(self): """ Test the get_courses_for_wiki method """ store = XMLModuleStore(DATA_DIR, course_dirs=['toy', 'simple']) for course in store.get_courses(): course_locations = store.get_courses_for_wiki(course.wiki_slug) self.assertEqual(len(course_locations), 1) self.assertIn(course.location, course_locations) course_locations = store.get_courses_for_wiki('no_such_wiki') self.assertEqual(len(course_locations), 0) # now set toy course to share the wiki with simple course toy_course = store.get_course(SlashSeparatedCourseKey('edX', 'toy', '2012_Fall')) toy_course.wiki_slug = 'simple' course_locations = store.get_courses_for_wiki('toy') self.assertEqual(len(course_locations), 0) course_locations = store.get_courses_for_wiki('simple') self.assertEqual(len(course_locations), 2) for course_number in ['toy', 'simple']: self.assertIn(Location('edX', course_number, '2012_Fall', 'course', '2012_Fall'), course_locations)
def test_cohort_config(self): """ Check that cohort config parsing works right. """ modulestore = XMLModuleStore(DATA_DIR, source_dirs=['toy']) toy_id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall') course = modulestore.get_course(toy_id) # No config -> False self.assertFalse(course.is_cohorted) # empty config -> False course.cohort_config = {} self.assertFalse(course.is_cohorted) # false config -> False course.cohort_config = {'cohorted': False} self.assertFalse(course.is_cohorted) # and finally... course.cohort_config = {'cohorted': True} self.assertTrue(course.is_cohorted)
def test_cohort_config(self): """ Check that cohort config parsing works right. """ modulestore = XMLModuleStore(DATA_DIR, source_dirs=['toy']) toy_id = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall') course = modulestore.get_course(toy_id) # No config -> False self.assertFalse(course.is_cohorted) # empty config -> False course.cohort_config = {} self.assertFalse(course.is_cohorted) # false config -> False course.cohort_config = {'cohorted': False} self.assertFalse(course.is_cohorted) # and finally... course.cohort_config = {'cohorted': True} self.assertTrue(course.is_cohorted)