def test_fetch_missing_media(self): image_path = 'jr://file/commcare/case_list_image.jpg' self.master_app_with_report_modules.get_module(0).set_icon( 'en', image_path) self.master_app_with_report_modules.create_mapping(self.image, image_path, save=False) remote_details = RemoteLinkDetails('http://localhost:8000', 'user', 'key') data = b'this is a test: \255' # Real data will be a binary multimedia file, so mock it with bytes, not unicode media_details = list( self.master_app_with_report_modules.multimedia_map.values())[0] media_details['multimedia_id'] = uuid.uuid4().hex media_details['media_type'] = 'CommCareMultimedia' with patch( 'corehq.apps.linked_domain.remote_accessors._fetch_remote_media_content' ) as mock: mock.return_value = data fetch_remote_media('domain', [('case_list_image.jpg', media_details)], remote_details) media = CommCareMultimedia.get(media_details['multimedia_id']) self.addCleanup(media.delete) content = media.fetch_attachment(list(media.blobs.keys())[0]) self.assertEqual(data, content)
def _get_missing_multimedia(app): missing = [] for path, media_info in app.multimedia_map.items(): try: local_media = CommCareMultimedia.get(media_info['multimedia_id']) except ResourceNotFound: filename = path.split('/')[-1] missing.append((filename, media_info)) else: _check_domain_access(app.domain, local_media) return missing
def _get_missing_multimedia(app, old_multimedia_ids=None): missing = [] for path, media_info in app.multimedia_map.items(): if old_multimedia_ids and media_info['multimedia_id'] in old_multimedia_ids: continue try: local_media = CommCareMultimedia.get(media_info['multimedia_id']) except ResourceNotFound: filename = path.split('/')[-1] missing.append((filename, media_info)) else: _add_domain_access(app.domain, local_media) return missing
def template_width(self): ''' Set column width to accommodate widest image. ''' width = 0 if self.app.enable_case_list_icon_dynamic_width: for i, item in enumerate(self.column.enum): for path in item.value.values(): map_item = self.app.multimedia_map[path] if map_item is not None: image = CommCareMultimedia.get(map_item.multimedia_id) if image is not None: for media in image.aux_media: width = max(width, media.media_meta['size']['width']) if width == 0: return '13%' return str(width)
def template_width(self): """ Set column width to accommodate widest image. """ width = 0 if self.app.enable_case_list_icon_dynamic_width: for i, item in enumerate(self.column.enum): for path in item.value.values(): map_item = self.app.multimedia_map[path] if map_item is not None: image = CommCareMultimedia.get(map_item.multimedia_id) if image is not None: for media in image.aux_media: width = max(width, media.media_meta["size"]["width"]) if width == 0: return "13%" return str(width)
def test_fetch_missing_media(self): image_path = 'jr://file/commcare/case_list_image.jpg' self.master_app_with_report_modules.get_module(0).set_icon('en', image_path) self.master_app_with_report_modules.create_mapping(self.image, image_path, save=False) remote_details = RemoteLinkDetails( 'http://localhost:8000', 'user', 'key' ) data = b'this is a test: \255' # Real data will be a binary multimedia file, so mock it with bytes, not unicode media_details = list(self.master_app_with_report_modules.multimedia_map.values())[0] media_details['multimedia_id'] = uuid.uuid4().hex media_details['media_type'] = 'CommCareMultimedia' with patch('corehq.apps.linked_domain.remote_accessors._fetch_remote_media_content') as mock: mock.return_value = data _fetch_remote_media('domain', [('case_list_image.jpg', media_details)], remote_details) media = CommCareMultimedia.get(media_details['multimedia_id']) self.addCleanup(media.delete) content = media.fetch_attachment(list(media.blobs.keys())[0]) self.assertEqual(data, content)
def test_fetch_missing_media(self): image_path = 'jr://file/commcare/case_list_image.jpg' self.master_app_with_report_modules.get_module(0).set_icon('en', image_path) self.master_app_with_report_modules.create_mapping(self.image, image_path, save=False) remote_app_details = RemoteAppDetails( 'http://localhost:8000', 'test_domain', 'user', 'key', self.master_app_with_report_modules._id ) data = 'this is a test' media_details = self.master_app_with_report_modules.multimedia_map.values()[0] media_details['multimedia_id'] = uuid.uuid4().hex media_details['media_type'] = 'CommCareMultimedia' with patch('corehq.apps.app_manager.remote_link_accessors._fetch_remote_media_content') as mock: mock.return_value = data _fetch_remote_media('domain', [('case_list_image.jpg', media_details)], remote_app_details) media = CommCareMultimedia.get(media_details['multimedia_id']) self.addCleanup(media.delete) content = media.fetch_attachment(media.blobs.keys()[0]) self.assertEqual(data, content)