Exemplo n.º 1
0
 def test_fetch_docconv_data(self):
     fetchPreviews(self.testfile,
                   virtual_url_parts=['dummy', ],
                   vr_path='/plone')
     docconv = IDocconv(self.testfile)
     self.assertTrue(docconv.has_pdf())
     self.assertTrue(docconv.has_previews())
     self.assertTrue(docconv.has_thumbs())
Exemplo n.º 2
0
 def test_empty_document_skipped(self):
     testdoc = api.content.create(
         type='Document',
         id='test-doc',
         title=u"Test Document",
         container=self.workspace)
     with patch.object(BasePreviewFetcher, '__call__') as mock_call:
         fetchPreviews(testdoc,
                       virtual_url_parts=['dummy', ],
                       vr_path='/plone')
         self.assertFalse(mock_call.called)
Exemplo n.º 3
0
 def test_document(self):
     testdoc = api.content.create(
         type='Document',
         id='test-doc',
         title=u"Test Document",
         text=u'The main text',
         container=self.workspace)
     fetchPreviews(testdoc,
                   virtual_url_parts=['dummy', ],
                   vr_path='/plone')
     docconv = IDocconv(testdoc)
     self.assertTrue(docconv.has_pdf())
     self.assertTrue(docconv.has_previews())
     self.assertTrue(docconv.has_thumbs())
Exemplo n.º 4
0
    def test_docconv_pdf_views(self):
        pdf_view = self.testfile.restrictedTraverse(
            'pdf')
        pdf_data = pdf_view()
        self.assertEquals(pdf_view.request.RESPONSE.getStatus(), 302)
        self.assertIn('pdf-not-available', pdf_data)

        # mock our way around the async call
        fetch_call = lambda: fetchPreviews(
            self.testfile,
            virtual_url_parts=['dummy', ],
            vr_path='/plone')
        DocconvAdapter.generate_all = Mock(
            return_value=True,
            side_effect=fetch_call)

        self.request.RESPONSE.setStatus(200)
        self.request['ACTUAL_URL'] = (
            self.testfile.absolute_url() + '/request-pdf')
        pdf_request_view = self.testfile.restrictedTraverse(
            'request-pdf')
        pdf_data = pdf_request_view()
        DocconvAdapter.generate_all.assert_called_with()
        self.assertIn('requested', pdf_data)
        self.assertEquals(pdf_request_view.request.RESPONSE.getStatus(), 200)

        self.request.RESPONSE.setStatus(200)
        pdf_view = self.testfile.restrictedTraverse(
            'pdf')
        pdf_data = pdf_view()
        self.assertIsNotNone(pdf_data)
        self.assertNotIn('not generated yet', pdf_data)
        self.assertEquals(pdf_view.request.RESPONSE.getStatus(), 200)
Exemplo n.º 5
0
 def _test_image_skipped(self, convert_method_name):
     imagedata = (
         'GIF87a\x01\x00\x01\x00\x80\x01\x00\x00\x00\x00\xff\xff'
         '\xff,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;')
     testdoc = api.content.create(
         type='Image',
         id='test-image',
         title=u"Test Image",
         image=NamedBlobImage(data=imagedata, filename=u'testimage.gif'),
         container=self.workspace)
     with patch.object(
             BasePreviewFetcher, convert_method_name) as mock_convert:
         fetchPreviews(testdoc,
                       virtual_url_parts=['dummy', ],
                       vr_path='/plone')
         self.assertFalse(mock_convert.called)
Exemplo n.º 6
0
def _update_preview_images(obj, event):
    annotations = IAnnotations(obj)
    if PREVIEW_IMAGES_KEY in annotations:
        del annotations[PREVIEW_IMAGES_KEY]
    if THUMBNAIL_KEY in annotations:
        del annotations[THUMBNAIL_KEY]
    if PDF_VERSION_KEY in annotations:
        del annotations[PDF_VERSION_KEY]
    if PREVIEW_MESSAGE_KEY in annotations:
        del annotations[PREVIEW_MESSAGE_KEY]
    success = queueDelayedConversionJob(obj, obj.REQUEST)
    if not success:
        try:
            fetchPreviews(obj)
        except ConfigError as e:
            log.error('ConfigError: %s' % e)
    generate_attachment_preview_images(obj)
Exemplo n.º 7
0
    def test_docconv_image_views(self):
        preview_view = self.testfile.restrictedTraverse(
            'docconv_image_preview.jpg')
        self.assertFalse(preview_view.available())
        self.assertEquals(preview_view.pages_count(), 0)
        preview_img = preview_view()
        self.assertEquals(preview_view.request.RESPONSE.getStatus(), 404)
        self.assertIs(preview_img, None)

        fetchPreviews(self.testfile,
                      virtual_url_parts=['dummy', ],
                      vr_path='/plone')

        for view_name in ['docconv_image_preview.jpg',
                          'docconv_image_thumb.jpg']:
            self.request.RESPONSE.setStatus(200)
            preview_view = self.testfile.restrictedTraverse(view_name)
            self.assertTrue(preview_view.available())
            self.assertEquals(preview_view.pages_count(), 1)
            preview_img = preview_view()
            self.assertIsNot(preview_img, None)
            self.assertNotEquals(preview_view.request.RESPONSE.getStatus(),
                                 404)