def test_colon_in_url_name(self): """Ensure that colons in url_names convert to file paths properly""" print("Starting import") # Not using get_courses because we need the modulestore object too afterward modulestore = XMLModuleStore(DATA_DIR, course_dirs=['toy']) courses = modulestore.get_courses() self.assertEquals(len(courses), 1) course = courses[0] course_id = course.id print("course errors:") for (msg, err) in modulestore.get_item_errors(course.location): print(msg) print(err) chapters = course.get_children() self.assertEquals(len(chapters), 2) ch2 = chapters[1] self.assertEquals(ch2.url_name, "secret:magic") print("Ch2 location: ", ch2.location) also_ch2 = modulestore.get_instance(course_id, ch2.location) self.assertEquals(ch2, also_ch2) print("making sure html loaded") cloc = course.location loc = Location(cloc.tag, cloc.org, cloc.course, 'html', 'secret:toylab') html = modulestore.get_instance(course_id, loc) self.assertEquals(html.display_name, "Toy lab")
def test_colon_in_url_name(self): """Ensure that colons in url_names convert to file paths properly""" print("Starting import") # Not using get_courses because we need the modulestore object too # afterward modulestore = XMLModuleStore(DATA_DIR, course_dirs=['toy']) courses = modulestore.get_courses() self.assertEquals(len(courses), 1) course = courses[0] course_id = course.id print("course errors:") for (msg, err) in modulestore.get_item_errors(course.location): print(msg) print(err) chapters = course.get_children() self.assertEquals(len(chapters), 2) ch2 = chapters[1] self.assertEquals(ch2.url_name, "secret:magic") print("Ch2 location: ", ch2.location) also_ch2 = modulestore.get_instance(course_id, ch2.location) self.assertEquals(ch2, also_ch2) print("making sure html loaded") cloc = course.location loc = Location(cloc.tag, cloc.org, cloc.course, 'html', 'secret:toylab') html = modulestore.get_instance(course_id, loc) self.assertEquals(html.display_name, "Toy lab")
def test_poll_and_conditional_import(self): modulestore = XMLModuleStore(DATA_DIR, course_dirs=["conditional_and_poll"]) course = modulestore.get_courses()[0] chapters = course.get_children() ch1 = chapters[0] sections = ch1.get_children() self.assertEqual(len(sections), 1) location = course.location conditional_location = Location(location.tag, location.org, location.course, "conditional", "condone") module = modulestore.get_instance(course.id, conditional_location) self.assertEqual(len(module.children), 1) poll_location = Location(location.tag, location.org, location.course, "poll_question", "first_poll") module = modulestore.get_instance(course.id, poll_location) self.assertEqual(len(module.get_children()), 0) self.assertEqual(module.voted, False) self.assertEqual(module.poll_answer, "") self.assertEqual(module.poll_answers, {}) self.assertEqual( module.answers, [{"text": u"Yes", "id": "Yes"}, {"text": u"No", "id": "No"}, {"text": u"Don't know", "id": "Dont_know"}], )
def test_definition_loading(self): """When two courses share the same org and course name and both have a module with the same url_name, the definitions shouldn't clash. TODO (vshnayder): once we have a CMS, this shouldn't happen--locations should uniquely name definitions. But in our imperfect XML world, it can (and likely will) happen.""" modulestore = XMLModuleStore(DATA_DIR, course_dirs=['toy', 'two_toys']) toy_id = "edX/toy/2012_Fall" two_toy_id = "edX/toy/TT_2012_Fall" location = Location(["i4x", "edX", "toy", "video", "Welcome"]) toy_video = modulestore.get_instance(toy_id, location) two_toy_video = modulestore.get_instance(two_toy_id, location) self.assertEqual(etree.fromstring(toy_video.data).get('youtube'), "1.0:p2Q6BrNhdh8") self.assertEqual(etree.fromstring(two_toy_video.data).get('youtube'), "1.0:p2Q6BrNhdh9")
def test_definition_loading(self): """When two courses share the same org and course name and both have a module with the same url_name, the definitions shouldn't clash. TODO (vshnayder): once we have a CMS, this shouldn't happen--locations should uniquely name definitions. But in our imperfect XML world, it can (and likely will) happen.""" modulestore = XMLModuleStore(DATA_DIR, course_dirs=['toy', 'two_toys']) toy_id = "edX/toy/2012_Fall" two_toy_id = "edX/toy/TT_2012_Fall" location = Location(["i4x", "edX", "toy", "video", "Welcome"]) toy_video = modulestore.get_instance(toy_id, location) two_toy_video = modulestore.get_instance(two_toy_id, location) self.assertEqual(toy_video.youtube_id_1_0, "p2Q6BrNhdh8") self.assertEqual(two_toy_video.youtube_id_1_0, "p2Q6BrNhdh9")
def test_poll_and_conditional_import(self): modulestore = XMLModuleStore( DATA_DIR, course_dirs=['conditional_and_poll']) course = modulestore.get_courses()[0] chapters = course.get_children() ch1 = chapters[0] sections = ch1.get_children() self.assertEqual(len(sections), 1) location = course.location conditional_location = Location( location.tag, location.org, location.course, 'conditional', 'condone' ) module = modulestore.get_instance(course.id, conditional_location) self.assertEqual(len(module.children), 1) poll_location = Location( location.tag, location.org, location.course, 'poll_question', 'first_poll' ) module = modulestore.get_instance(course.id, poll_location) self.assertEqual(len(module.get_children()), 0) self.assertEqual(module.voted, False) self.assertEqual(module.poll_answer, '') self.assertEqual(module.poll_answers, {}) self.assertEqual( module.answers, [ {'text': u'Yes', 'id': 'Yes'}, {'text': u'No', 'id': 'No'}, {'text': u"Don't know", 'id': 'Dont_know'} ] )
def test_graphicslidertool_import(self): ''' Check to see if definition_from_xml in gst_module.py works properly. Pulls data from the graphic_slider_tool directory in the test data directory. ''' modulestore = XMLModuleStore(DATA_DIR, course_dirs=['graphic_slider_tool']) sa_id = "edX/gst_test/2012_Fall" location = Location(["i4x", "edX", "gst_test", "graphical_slider_tool", "sample_gst"]) gst_sample = modulestore.get_instance(sa_id, location) render_string_from_sample_gst_xml = """ <slider var="a" style="width:400px;float:left;"/>\ <plot style="margin-top:15px;margin-bottom:15px;"/>""".strip() self.assertEqual(gst_sample.render, render_string_from_sample_gst_xml)
def test_poll_and_conditional_import(self): modulestore = XMLModuleStore(DATA_DIR, course_dirs=['conditional_and_poll']) course = modulestore.get_courses()[0] chapters = course.get_children() ch1 = chapters[0] sections = ch1.get_children() self.assertEqual(len(sections), 1) location = course.location conditional_location = Location(location.tag, location.org, location.course, 'conditional', 'condone') module = modulestore.get_instance(course.id, conditional_location) self.assertEqual(len(module.children), 1) poll_location = Location(location.tag, location.org, location.course, 'poll_question', 'first_poll') module = modulestore.get_instance(course.id, poll_location) self.assertEqual(len(module.get_children()), 0) self.assertEqual(module.voted, False) self.assertEqual(module.poll_answer, '') self.assertEqual(module.poll_answers, {}) self.assertEqual(module.answers, [{ 'text': u'Yes', 'id': 'Yes' }, { 'text': u'No', 'id': 'No' }, { 'text': u"Don't know", 'id': 'Dont_know' }])
def test_graphicslidertool_import(self): ''' Check to see if definition_from_xml in gst_module.py works properly. Pulls data from the graphic_slider_tool directory in the test data directory. ''' modulestore = XMLModuleStore(DATA_DIR, course_dirs=['graphic_slider_tool']) sa_id = "edX/gst_test/2012_Fall" location = Location(["i4x", "edX", "gst_test", "graphical_slider_tool", "sample_gst"]) gst_sample = modulestore.get_instance(sa_id, location) render_string_from_sample_gst_xml = """ <slider var="a" style="width:400px;float:left;"/>\ <plot style="margin-top:15px;margin-bottom:15px;"/>""".strip() self.assertIn(render_string_from_sample_gst_xml, gst_sample.data)
def test_word_cloud_import(self): modulestore = XMLModuleStore(DATA_DIR, course_dirs=["word_cloud"]) course = modulestore.get_courses()[0] chapters = course.get_children() ch1 = chapters[0] sections = ch1.get_children() self.assertEqual(len(sections), 1) location = course.location location = Location(location.tag, location.org, location.course, "word_cloud", "cloud1") module = modulestore.get_instance(course.id, location) self.assertEqual(len(module.get_children()), 0) self.assertEqual(module.num_inputs, 5) self.assertEqual(module.num_top_words, 250)
def test_word_cloud_import(self): modulestore = XMLModuleStore(DATA_DIR, course_dirs=['word_cloud']) course = modulestore.get_courses()[0] chapters = course.get_children() ch1 = chapters[0] sections = ch1.get_children() self.assertEqual(len(sections), 1) location = course.location location = Location(location.tag, location.org, location.course, 'word_cloud', 'cloud1') module = modulestore.get_instance(course.id, location) self.assertEqual(len(module.get_children()), 0) self.assertEqual(module.num_inputs, 5) self.assertEqual(module.num_top_words, 250)
class DummyModulestore(object): """ A mixin that allows test classes to have convenience functions to get a module given a location """ get_test_system = get_test_system() def setup_modulestore(self, name): self.modulestore = XMLModuleStore(DATA_DIR, course_dirs=[name]) def get_course(self, name): """Get a test course by directory name. If there's more than one, error.""" courses = self.modulestore.get_courses() return courses[0] def get_module_from_location(self, location, course): course = self.get_course(course) if not isinstance(location, Location): location = Location(location) descriptor = self.modulestore.get_instance(course.id, location, depth=None) return descriptor.xmodule(self.test_system)
class DummyModulestore(object): """ A mixin that allows test classes to have convenience functions to get a module given a location """ def get_module_system(self, descriptor): raise NotImplementedError("Sub-tests must specify how to generate a module-system") def setup_modulestore(self, name): self.modulestore = XMLModuleStore(DATA_DIR, course_dirs=[name]) def get_course(self, _): """Get a test course by directory name. If there's more than one, error.""" courses = self.modulestore.get_courses() return courses[0] def get_module_from_location(self, location, course): course = self.get_course(course) if not isinstance(location, Location): location = Location(location) descriptor = self.modulestore.get_instance(course.id, location, depth=None) descriptor.xmodule_runtime = self.get_module_system(descriptor) return descriptor