def test_download_version_after_a_change(self, browser):
        doc = create(Builder('document')
                     .attach_file_containing(u'text', name=u'file.pdf')
                     .within(self.dossier))
        initial_checksum = IBumblebeeDocument(doc).get_checksum()

        # We store these parameters as they were sent to bumblebee with /store
        params = {'token': download_token_for(doc),
                  'uuid': IUUID(doc),
                  'checksum': initial_checksum}

        # then the file changes, a new version is created.
        doc.file = NamedBlobFile(data='some other text', filename=u'foo.pdf')
        doc.setModificationDate(datetime.now())
        notify(ObjectEditedEvent(doc))
        transaction.commit()

        self.assertNotEqual(
            initial_checksum, IBumblebeeDocument(doc).get_checksum(),
            'Expected the checksum to have changed when object was updated.')

        # when accessing the previous version, the LRU may trigger a refresh
        # and may want to download the file again.
        browser.open(view='bumblebee_download', data=params)
        self.assertEqual('text', browser.contents)
        self.assertEqual('application/pdf',
                         browser.headers.get('Content-Type'))
    def test_download_last_version_for_checked_out_docs(self, browser):
        content = bumblebee_asset('example.docx').bytes()
        document = create(Builder('document')
                          .attach_file_containing(
                              content,
                              u'example.docx')
                          .checked_out())

        document.update_file('foo',
                             content_type='text/plain',
                             filename=u'foo.txt')
        notify(ObjectModifiedEvent(document))
        transaction.commit()

        # checksum has not been updated
        self.assertEqual(
            DOCX_CHECKSUM, IBumblebeeDocument(document).get_checksum())

        # download first history version
        browser.open(view='bumblebee_download',
                     data={'token': download_token_for(document),
                           'uuid': IUUID(document),
                           'checksum': DOCX_CHECKSUM})
        self.assertEqual(content, browser.contents)
        self.assertEqual(
            'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
            browser.headers.get('Content-Type'))
Example #3
0
    def test_download_version_after_a_change(self, browser):
        doc = create(
            Builder('document').attach_file_containing(
                u'text', name=u'file.pdf').within(self.dossier))
        initial_checksum = IBumblebeeDocument(doc).get_checksum()

        # We store these parameters as they were sent to bumblebee with /store
        params = {
            'token': download_token_for(doc),
            'uuid': IUUID(doc),
            'checksum': initial_checksum
        }

        # then the file changes, a new version is created.
        doc.file = NamedBlobFile(data='some other text', filename=u'foo.pdf')
        doc.setModificationDate(datetime.now())
        notify(ObjectEditedEvent(doc))
        transaction.commit()

        self.assertNotEqual(
            initial_checksum,
            IBumblebeeDocument(doc).get_checksum(),
            'Expected the checksum to have changed when object was updated.')

        # when accessing the previous version, the LRU may trigger a refresh
        # and may want to download the file again.
        browser.open(view='bumblebee_download', data=params)
        self.assertEqual('text', browser.contents)
        self.assertEqual('application/pdf',
                         browser.headers.get('Content-Type'))
Example #4
0
    def test_download_last_version_for_checked_out_docs(self, browser):
        content = bumblebee_asset('example.docx').bytes()
        document = create(
            Builder('document').attach_file_containing(
                content, u'example.docx').checked_out())

        document.update_file(filename=u'foo.txt',
                             content_type='text/plain',
                             data='foo')
        notify(ObjectModifiedEvent(document))
        transaction.commit()

        # checksum has not been updated
        self.assertEqual(DOCX_CHECKSUM,
                         IBumblebeeDocument(document).get_checksum())

        # download first history version
        browser.open(view='bumblebee_download',
                     data={
                         'token': download_token_for(document),
                         'uuid': IUUID(document),
                         'checksum': DOCX_CHECKSUM
                     })
        self.assertEqual(content, browser.contents)
        self.assertEqual(
            'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
            browser.headers.get('Content-Type'))
    def test_notfound_when_we_have_no_version_with_this_checksum(self, browser):
        doc = create(Builder("document").attach_file_containing(u"The Content", name=u"file.pdf").within(self.dossier))

        with self.assertRaises(NotFound) as cm:
            browser.open(
                view="bumblebee_download",
                data={"token": download_token_for(doc), "uuid": IUUID(doc), "checksum": "wrong-checksum"},
            )

        self.assertEquals("Version not found by checksum.", str(cm.exception))
    def test_notfound_when_we_have_no_version_with_this_checksum(self, browser):
        doc = create(Builder('document')
                     .attach_file_containing(u'The Content', name=u'file.pdf')
                     .within(self.dossier))

        with browser.expect_http_error(reason='Not Found'):
            browser.open(view='bumblebee_download',
                         data={'token': download_token_for(doc),
                               'uuid': IUUID(doc),
                               'checksum': 'wrong-checksum'})
    def test_download_newest_version(self, browser):
        doc = create(Builder('document')
                     .attach_file_containing(u'The Content', name=u'file.pdf')
                     .within(self.dossier))

        browser.open(view='bumblebee_download',
                     data={'token': download_token_for(doc),
                           'uuid': IUUID(doc),
                           'checksum': IBumblebeeDocument(doc).get_checksum()})
        self.assertEqual('The Content', browser.contents)
        self.assertEqual('application/pdf',
                         browser.headers.get('Content-Type'))
    def test_sets_failed_temporary_state_when_conversion_has_not_succeeded_or_skipped(self):
        with freeze(datetime(2016, 4, 25, 10, 24)):
            body = {"status": "failed",
                    "error": "Some parts of the document could not be processed",
                    "token": download_token_for(self.document)}
            self.request.set('BODY', json.dumps(body))

            view = StoreArchivalFile(self.document, self.request)
            view()

        self.assertEquals(
            STATE_FAILED_TEMPORARILY,
            IDocumentMetadata(self.document).archival_file_state)
    def test_sets_failed_permanently_state_when_conversion_was_skipped(self):
        with freeze(datetime(2016, 4, 25, 10, 24)):
            body = {"status": "skipped",
                    "error": "File is password protected.",
                    "token": download_token_for(self.document)}
            self.request.set('BODY', json.dumps(body))

            view = StoreArchivalFile(self.document, self.request)
            view()

        self.assertEquals(
            STATE_FAILED_PERMANENTLY,
            IDocumentMetadata(self.document).archival_file_state)
Example #10
0
    def test_notfound_when_we_have_no_version_with_this_checksum(
            self, browser):
        doc = create(
            Builder('document').attach_file_containing(
                u'The Content', name=u'file.pdf').within(self.dossier))

        with browser.expect_http_error(reason='Not Found'):
            browser.open(view='bumblebee_download',
                         data={
                             'token': download_token_for(doc),
                             'uuid': IUUID(doc),
                             'checksum': 'wrong-checksum'
                         })
Example #11
0
    def test_download_newest_version(self, browser):
        doc = create(Builder("document").attach_file_containing(u"The Content", name=u"file.pdf").within(self.dossier))

        browser.open(
            view="bumblebee_download",
            data={
                "token": download_token_for(doc),
                "uuid": IUUID(doc),
                "checksum": IBumblebeeDocument(doc).get_checksum(),
            },
        )
        self.assertEqual("The Content", browser.contents)
        self.assertEqual("application/pdf", browser.headers.get("Content-Type"))
    def test_sets_failed_permanently_state_when_conversion_was_skipped(self):
        with freeze(datetime(2016, 4, 25, 10, 24)):
            body = {
                "status": "skipped",
                "error": "File is password protected.",
                "token": download_token_for(self.document)
            }
            self.request.set('BODY', json.dumps(body))

            view = StoreArchivalFile(self.document, self.request)
            view()

        self.assertEquals(STATE_FAILED_PERMANENTLY,
                          IDocumentMetadata(self.document).archival_file_state)
Example #13
0
    def test_download_newest_version(self, browser):
        doc = create(
            Builder('document').attach_file_containing(
                u'The Content', name=u'file.pdf').within(self.dossier))

        browser.open(view='bumblebee_download',
                     data={
                         'token': download_token_for(doc),
                         'uuid': IUUID(doc),
                         'checksum': IBumblebeeDocument(doc).get_checksum()
                     })
        self.assertEqual('The Content', browser.contents)
        self.assertEqual('application/pdf',
                         browser.headers.get('Content-Type'))
Example #14
0
    def test_updates_archival_file_when_conversion_succeeded(self):
        with freeze(datetime(2016, 4, 25, 10, 24)):
            body = {'status': "success",
                    'data': "data:application/pdf;base64,VGVzdCBTdHJpbmc=",
                    'token': download_token_for(self.document)}
            self.request.set('BODY', json.dumps(body))

            view = StoreArchivalFile(self.document, self.request)
            view()

        archival_file = IDocumentMetadata(self.document).archival_file
        self.assertEquals('Ueberpruefung XY.pdf', archival_file.filename)
        self.assertTrue(isinstance(archival_file, NamedBlobFile))
        self.assertEquals('application/pdf', archival_file.contentType)
        self.assertEquals('Test String', archival_file.data)
    def test_sets_failed_temporary_state_when_conversion_has_not_succeeded_or_skipped(
            self):
        with freeze(datetime(2016, 4, 25, 10, 24)):
            body = {
                "status": "failed",
                "error": "Some parts of the document could not be processed",
                "token": download_token_for(self.document)
            }
            self.request.set('BODY', json.dumps(body))

            view = StoreArchivalFile(self.document, self.request)
            view()

        self.assertEquals(STATE_FAILED_TEMPORARILY,
                          IDocumentMetadata(self.document).archival_file_state)
    def test_updates_archival_file_when_conversion_succeeded(self):
        with freeze(datetime(2016, 4, 25, 10, 24)):
            body = {
                'status': "success",
                'data': "data:application/pdf;base64,VGVzdCBTdHJpbmc=",
                'token': download_token_for(self.document)
            }
            self.request.set('BODY', json.dumps(body))

            view = StoreArchivalFile(self.document, self.request)
            view()

        archival_file = IDocumentMetadata(self.document).archival_file
        self.assertEquals('Ueberpruefung XY.pdf', archival_file.filename)
        self.assertTrue(isinstance(archival_file, NamedBlobFile))
        self.assertEquals('application/pdf', archival_file.contentType)
        self.assertEquals('Test String', archival_file.data)
Example #17
0
    def test_download_last_version_for_checked_out_docs(self, browser):
        content = bumblebee_asset("example.docx").bytes()
        document = create(Builder("document").attach_file_containing(content, u"example.docx").checked_out())

        document.update_file(filename=u"foo.txt", content_type="text/plain", data="foo")
        notify(ObjectModifiedEvent(document))
        transaction.commit()

        # checksum has not been updated
        self.assertEqual(DOCX_CHECKSUM, IBumblebeeDocument(document).get_checksum())

        # download first history version
        browser.open(
            view="bumblebee_download",
            data={"token": download_token_for(document), "uuid": IUUID(document), "checksum": DOCX_CHECKSUM},
        )
        self.assertEqual(content, browser.contents)
        self.assertEqual(
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
            browser.headers.get("Content-Type"),
        )