def test_multimedia(self): from corehq.apps.hqmedia.models import CommCareAudio, CommCareImage, CommCareVideo image_path = os.path.join('corehq', 'apps', 'hqwebapp', 'static', 'hqwebapp', 'img', 'commcare-hq-logo.png') with open(image_path, 'r') as f: image_data = f.read() image = CommCareImage.get_by_data(image_data) image.attach_data(image_data, original_filename='logo.png') image.add_domain(self.domain_name) self.assertEqual(image_data, image.get_display_file(False)) audio_data = 'fake audio data' audio = CommCareAudio.get_by_data(audio_data) audio.attach_data(audio_data, original_filename='tr-la-la.mp3') audio.add_domain(self.domain_name) self.assertEqual(audio_data, audio.get_display_file(False)) video_data = 'fake video data' video = CommCareVideo.get_by_data(video_data) video.attach_data(video_data, 'kittens.mp4') video.add_domain(self.domain_name) self.assertEqual(video_data, video.get_display_file(False)) fakedb = self._dump_and_load([image, audio, video]) copied_image = CommCareImage.wrap(fakedb.get(image._id)) copied_audio = CommCareAudio.wrap(fakedb.get(audio._id)) copied_video = CommCareVideo.wrap(fakedb.get(video._id)) self.assertEqual(image_data, copied_image.get_display_file(False)) self.assertEqual(audio_data, copied_audio.get_display_file(False)) self.assertEqual(video_data, copied_video.get_display_file(False))
def test_multimedia(self): from corehq.apps.hqmedia.models import CommCareAudio, CommCareImage, CommCareVideo image_path = os.path.join('corehq', 'apps', 'hqwebapp', 'static', 'hqwebapp', 'images', 'commcare-hq-logo.png') with open(image_path, 'r') as f: image_data = f.read() image = CommCareImage.get_by_data(image_data) image.attach_data(image_data, original_filename='logo.png') image.add_domain(self.domain_name) self.assertEqual(image_data, image.get_display_file(False)) audio_data = 'fake audio data' audio = CommCareAudio.get_by_data(audio_data) audio.attach_data(audio_data, original_filename='tr-la-la.mp3') audio.add_domain(self.domain_name) self.assertEqual(audio_data, audio.get_display_file(False)) video_data = 'fake video data' video = CommCareVideo.get_by_data(video_data) video.attach_data(video_data, 'kittens.mp4') video.add_domain(self.domain_name) self.assertEqual(video_data, video.get_display_file(False)) fakedb = self._dump_and_load([image, audio, video]) copied_image = CommCareImage.wrap(fakedb.get(image._id)) copied_audio = CommCareAudio.wrap(fakedb.get(audio._id)) copied_video = CommCareVideo.wrap(fakedb.get(video._id)) self.assertEqual(image_data, copied_image.get_display_file(False)) self.assertEqual(audio_data, copied_audio.get_display_file(False)) self.assertEqual(video_data, copied_video.get_display_file(False))
def test_media_suite_generator(self): app = Application.wrap(self.get_json('app_video_inline')) image_path = 'jr://file/commcare/image1.jpg' audio_path = 'jr://file/commcare/audio1.mp3' video_path = 'jr://file/commcare/video-inline/data/inline_video.mp4' app.create_mapping(CommCareImage(_id='123'), image_path, save=False) app.create_mapping(CommCareAudio(_id='456'), audio_path, save=False) app.create_mapping(CommCareVideo(_id='789'), video_path, save=False) app.get_module(0).case_list_form.set_icon('en', image_path) app.get_module(0).case_list_form.set_audio('en', audio_path) app.get_module(0).case_list_form.form_id = app.get_module(0).get_form( 0).unique_id app.profile["properties"] = {'lazy-load-video-files': 'true'} self.assertXmlEqual(self.get_xml('media-suite-lazy-true'), MediaSuiteGenerator(app).generate_suite()) app.profile["properties"] = {'lazy-load-video-files': 'false'} self.assertXmlEqual(self.get_xml('media-suite-lazy-false'), MediaSuiteGenerator(app).generate_suite())