Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
def pull_missing_multimedia_for_app(app, old_multimedia_ids=None):
    missing_media = _get_missing_multimedia(app, old_multimedia_ids)
    remote_details = app.domain_link.remote_details
    fetch_remote_media(app.domain, missing_media, remote_details)
    if toggles.CAUTIOUS_MULTIMEDIA.enabled(app.domain):
        still_missing_media = _get_missing_multimedia(app, old_multimedia_ids)
        if still_missing_media:
            raise MultimediaMissingError(_(
                'Application has missing multimedia even after an attempt to re-pull them. '
                'Please try re-pulling the app. If this persists, report an issue.'
            ))