def test_no_encodings(self): expected = self.parse_xml( """ <video_asset client_video_id="TWINKLE TWINKLE" duration="122.0"/> """ ) self.assert_xml_equal(api.export_to_xml(constants.VIDEO_DICT_STAR["edx_video_id"]), expected)
def definition_to_xml(self, resource_fs): """ Returns an xml string representing this module. """ xml = etree.Element('video') youtube_string = create_youtube_string(self) # Mild workaround to ensure that tests pass -- if a field # is set to its default value, we don't need to write it out. if youtube_string and youtube_string != '1.00:3_yD_cEKoCk': xml.set('youtube', unicode(youtube_string)) xml.set('url_name', self.url_name) attrs = { 'display_name': self.display_name, 'show_captions': json.dumps(self.show_captions), 'start_time': self.start_time, 'end_time': self.end_time, 'sub': self.sub, 'download_track': json.dumps(self.download_track), 'download_video': json.dumps(self.download_video), } for key, value in attrs.items(): # Mild workaround to ensure that tests pass -- if a field # is set to its default value, we don't write it out. if value: if key in self.fields and self.fields[key].is_set_on(self): xml.set(key, unicode(value)) for source in self.html5_sources: ele = etree.Element('source') ele.set('src', source) xml.append(ele) if self.track: ele = etree.Element('track') ele.set('src', self.track) xml.append(ele) if self.handout: ele = etree.Element('handout') ele.set('src', self.handout) xml.append(ele) if self.transcripts is not None: # sorting for easy testing of resulting xml for transcript_language in sorted(self.transcripts.keys()): ele = etree.Element('transcript') ele.set('language', transcript_language) ele.set('src', self.transcripts[transcript_language]) xml.append(ele) if self.edx_video_id and edxval_api: try: xml.append(edxval_api.export_to_xml(self.edx_video_id)) except edxval_api.ValVideoNotFoundError: pass # handle license specifically self.add_license_to_xml(xml) return xml
def test_no_encodings(self): expected = self.parse_xml(""" <video_asset client_video_id="TWINKLE TWINKLE" duration="122.0"/> """) self.assert_xml_equal( api.export_to_xml(constants.VIDEO_DICT_STAR["edx_video_id"]), expected)
def definition_to_xml(self, resource_fs): """ Returns an xml string representing this module. """ xml = etree.Element('video') youtube_string = create_youtube_string(self) # Mild workaround to ensure that tests pass -- if a field # is set to its default value, we don't need to write it out. if youtube_string and youtube_string != '1.00:3_yD_cEKoCk': xml.set('youtube', unicode(youtube_string)) xml.set('url_name', self.url_name) attrs = { 'display_name': self.display_name, 'show_captions': json.dumps(self.show_captions), 'start_time': self.start_time, 'end_time': self.end_time, 'sub': self.sub, 'download_track': json.dumps(self.download_track), 'download_video': json.dumps(self.download_video), } for key, value in attrs.items(): # Mild workaround to ensure that tests pass -- if a field # is set to its default value, we don't write it out. if value: if key in self.fields and self.fields[key].is_set_on(self): xml.set(key, unicode(value)) for source in self.html5_sources: ele = etree.Element('source') ele.set('src', source) xml.append(ele) if self.track: ele = etree.Element('track') ele.set('src', self.track) xml.append(ele) if self.handout: ele = etree.Element('handout') ele.set('src', self.handout) xml.append(ele) # sorting for easy testing of resulting xml for transcript_language in sorted(self.transcripts.keys()): ele = etree.Element('transcript') ele.set('language', transcript_language) ele.set('src', self.transcripts[transcript_language]) xml.append(ele) if self.edx_video_id and edxval_api: try: xml.append(edxval_api.export_to_xml(self.edx_video_id)) except edxval_api.ValVideoNotFoundError: pass # handle license specifically self.add_license_to_xml(xml) return xml
def definition_to_xml(self, resource_fs): """ Returns an xml string representing this module. """ xml = etree.Element("video") youtube_string = create_youtube_string(self) # Mild workaround to ensure that tests pass -- if a field # is set to its default value, we don't need to write it out. if youtube_string and youtube_string != "1.00:3_yD_cEKoCk": xml.set("youtube", unicode(youtube_string)) xml.set("url_name", self.url_name) attrs = { "display_name": self.display_name, "show_captions": json.dumps(self.show_captions), "start_time": self.start_time, "end_time": self.end_time, "sub": self.sub, "download_track": json.dumps(self.download_track), "download_video": json.dumps(self.download_video), } for key, value in attrs.items(): # Mild workaround to ensure that tests pass -- if a field # is set to its default value, we don't write it out. if value: if key in self.fields and self.fields[key].is_set_on(self): xml.set(key, unicode(value)) for source in self.html5_sources: ele = etree.Element("source") ele.set("src", source) xml.append(ele) if self.track: ele = etree.Element("track") ele.set("src", self.track) xml.append(ele) if self.handout: ele = etree.Element("handout") ele.set("src", self.handout) xml.append(ele) # sorting for easy testing of resulting xml for transcript_language in sorted(self.transcripts.keys()): ele = etree.Element("transcript") ele.set("language", transcript_language) ele.set("src", self.transcripts[transcript_language]) xml.append(ele) if self.edx_video_id and edxval_api: try: xml.append(edxval_api.export_to_xml(self.edx_video_id)) except edxval_api.ValVideoNotFoundError: pass return xml
def test_basic(self): expected = self.parse_xml( """ <video_asset client_video_id="Shallow Swordfish" duration="122.0"> <encoded_video url="http://www.meowmix.com" file_size="11" bitrate="22" profile="mobile"/> <encoded_video url="http://www.meowmagic.com" file_size="33" bitrate="44" profile="desktop"/> </video_asset> """ ) self.assert_xml_equal(api.export_to_xml(constants.VIDEO_DICT_FISH["edx_video_id"]), expected)
def test_basic(self): expected = self.parse_xml(""" <video_asset client_video_id="Shallow Swordfish" duration="122.0"> <encoded_video url="http://www.meowmix.com" file_size="11" bitrate="22" profile="mobile"/> <encoded_video url="http://www.meowmagic.com" file_size="33" bitrate="44" profile="desktop"/> </video_asset> """) self.assert_xml_equal( api.export_to_xml(constants.VIDEO_DICT_FISH["edx_video_id"]), expected)
def definition_to_xml(self, resource_fs): """ Returns an xml string representing this module. """ xml = etree.Element('video') youtube_string = create_youtube_string(self) # Mild workaround to ensure that tests pass -- if a field # is set to its default value, we don't need to write it out. if youtube_string and youtube_string != '1.00:3_yD_cEKoCk': xml.set('youtube', unicode(youtube_string)) xml.set('url_name', self.url_name) attrs = { 'display_name': self.display_name, 'show_captions': json.dumps(self.show_captions), 'start_time': self.start_time, 'end_time': self.end_time, 'sub': self.sub, 'download_track': json.dumps(self.download_track), 'download_video': json.dumps(self.download_video), } for key, value in attrs.items(): # Mild workaround to ensure that tests pass -- if a field # is set to its default value, we don't write it out. if value: if key in self.fields and self.fields[key].is_set_on(self): try: xml.set(key, unicode(value)) except UnicodeDecodeError: exception_message = format_xml_exception_message( self.location, key, value) log.exception(exception_message) # If exception is UnicodeDecodeError set value using unicode 'utf-8' scheme. log.info("Setting xml value using 'utf-8' scheme.") xml.set(key, unicode(value, 'utf-8')) except ValueError: exception_message = format_xml_exception_message( self.location, key, value) log.exception(exception_message) raise for source in self.html5_sources: ele = etree.Element('source') ele.set('src', source) xml.append(ele) if self.track: ele = etree.Element('track') ele.set('src', self.track) xml.append(ele) if self.handout: ele = etree.Element('handout') ele.set('src', self.handout) xml.append(ele) if self.transcripts is not None: # sorting for easy testing of resulting xml for transcript_language in sorted(self.transcripts.keys()): ele = etree.Element('transcript') ele.set('language', transcript_language) ele.set('src', self.transcripts[transcript_language]) xml.append(ele) if edxval_api: external, video_ids = get_video_ids_info(self.edx_video_id, self.youtube_id_1_0, self.html5_sources) if video_ids: try: xml.append( edxval_api.export_to_xml( video_ids, unicode(self.runtime.course_id.for_branch(None)), external=external)) except edxval_api.ValVideoNotFoundError: pass # handle license specifically self.add_license_to_xml(xml) return xml
def test_unknown_video(self): with self.assertRaises(ValVideoNotFoundError): api.export_to_xml("unknown_video")
def definition_to_xml(self, resource_fs): """ Returns an xml string representing this module. """ xml = etree.Element('video') youtube_string = create_youtube_string(self) # Mild workaround to ensure that tests pass -- if a field # is set to its default value, we don't need to write it out. if youtube_string and youtube_string != '1.00:3_yD_cEKoCk': xml.set('youtube', six.text_type(youtube_string)) xml.set('url_name', self.url_name) attrs = { 'display_name': self.display_name, 'show_captions': json.dumps(self.show_captions), 'start_time': self.start_time, 'end_time': self.end_time, 'sub': self.sub, 'download_track': json.dumps(self.download_track), 'download_video': json.dumps(self.download_video), } for key, value in attrs.items(): # Mild workaround to ensure that tests pass -- if a field # is set to its default value, we don't write it out. if value: if key in self.fields and self.fields[key].is_set_on(self): try: xml.set(key, six.text_type(value)) except UnicodeDecodeError: exception_message = format_xml_exception_message(self.location, key, value) log.exception(exception_message) # If exception is UnicodeDecodeError set value using unicode 'utf-8' scheme. log.info("Setting xml value using 'utf-8' scheme.") xml.set(key, six.text_type(value, 'utf-8')) except ValueError: exception_message = format_xml_exception_message(self.location, key, value) log.exception(exception_message) raise for source in self.html5_sources: ele = etree.Element('source') ele.set('src', source) xml.append(ele) if self.track: ele = etree.Element('track') ele.set('src', self.track) xml.append(ele) if self.handout: ele = etree.Element('handout') ele.set('src', self.handout) xml.append(ele) transcripts = {} if self.transcripts is not None: transcripts.update(self.transcripts) edx_video_id = clean_video_id(self.edx_video_id) if edxval_api and edx_video_id: try: # Create static dir if not created earlier. resource_fs.makedirs(EXPORT_IMPORT_STATIC_DIR, recreate=True) # Backward compatible exports # edxval exports new transcripts into the course OLX and returns a transcript # files map so that it can also be rewritten in old transcript metadata fields # (i.e. `self.transcripts`) on import and older open-releases (<= ginkgo), # who do not have deprecated contentstore yet, can also import and use new-style # transcripts into their openedX instances. exported_metadata = edxval_api.export_to_xml( video_id=edx_video_id, resource_fs=resource_fs, static_dir=EXPORT_IMPORT_STATIC_DIR, course_id=six.text_type(self.runtime.course_id.for_branch(None)) ) # Update xml with edxval metadata xml.append(exported_metadata['xml']) # we don't need sub if english transcript # is also in new transcripts. new_transcripts = exported_metadata['transcripts'] transcripts.update(new_transcripts) if new_transcripts.get('en'): xml.set('sub', '') # Update `transcripts` attribute in the xml xml.set('transcripts', json.dumps(transcripts)) except edxval_api.ValVideoNotFoundError: pass # Sorting transcripts for easy testing of resulting xml for transcript_language in sorted(transcripts.keys()): ele = etree.Element('transcript') ele.set('language', transcript_language) ele.set('src', transcripts[transcript_language]) xml.append(ele) # handle license specifically self.add_license_to_xml(xml) return xml
def definition_to_xml(self, resource_fs): """ Returns an xml string representing this module. """ xml = etree.Element('video') youtube_string = create_youtube_string(self) # Mild workaround to ensure that tests pass -- if a field # is set to its default value, we don't need to write it out. if youtube_string and youtube_string != '1.00:3_yD_cEKoCk': xml.set('youtube', unicode(youtube_string)) xml.set('url_name', self.url_name) attrs = { 'display_name': self.display_name, 'show_captions': json.dumps(self.show_captions), 'start_time': self.start_time, 'end_time': self.end_time, 'sub': self.sub, 'download_track': json.dumps(self.download_track), 'download_video': json.dumps(self.download_video), } for key, value in attrs.items(): # Mild workaround to ensure that tests pass -- if a field # is set to its default value, we don't write it out. if value: if key in self.fields and self.fields[key].is_set_on(self): try: xml.set(key, unicode(value)) except UnicodeDecodeError: exception_message = format_xml_exception_message(self.location, key, value) log.exception(exception_message) # If exception is UnicodeDecodeError set value using unicode 'utf-8' scheme. log.info("Setting xml value using 'utf-8' scheme.") xml.set(key, unicode(value, 'utf-8')) except ValueError: exception_message = format_xml_exception_message(self.location, key, value) log.exception(exception_message) raise for source in self.html5_sources: ele = etree.Element('source') ele.set('src', source) xml.append(ele) if self.track: ele = etree.Element('track') ele.set('src', self.track) xml.append(ele) if self.handout: ele = etree.Element('handout') ele.set('src', self.handout) xml.append(ele) if self.transcripts is not None: # sorting for easy testing of resulting xml for transcript_language in sorted(self.transcripts.keys()): ele = etree.Element('transcript') ele.set('language', transcript_language) ele.set('src', self.transcripts[transcript_language]) xml.append(ele) if edxval_api: external, video_ids = get_video_ids_info(self.edx_video_id, self.youtube_id_1_0, self.html5_sources) if video_ids: try: xml.append( edxval_api.export_to_xml( video_ids, unicode(self.runtime.course_id.for_branch(None)), external=external ) ) except edxval_api.ValVideoNotFoundError: pass # handle license specifically self.add_license_to_xml(xml) return xml