Example #1
0
 def test_set_storage_version(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     fi = self.createFile('test.pdf')
     settings = Settings(fi)
     self.assertEquals(settings.storage_version, STORAGE_VERSION)
 def test_filesystem_storage_works(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     fi = self.createFile('test.pdf')
     notify(ObjectInitializedEvent(fi))
     uid = fi.UID()
     fi.reindexObject()  # for pc
     fiobj = self.portal.unrestrictedTraverse(
         '@@dvpdffiles/%s/%s/%s/small/dump_1.gif' % (
             uid[0], uid[1], uid))
     self.assertEquals(fiobj.context.path,
         join(_dir, uid[0], uid[1], uid, 'small', 'dump_1.gif'))
     fiobj = self.portal.unrestrictedTraverse(
         '@@dvpdffiles/%s/%s/%s/normal/dump_1.gif' % (
             uid[0], uid[1], uid))
     self.assertEquals(fiobj.context.path,
         join(_dir, uid[0], uid[1], uid, 'normal', 'dump_1.gif'))
     fiobj = self.portal.unrestrictedTraverse(
         '@@dvpdffiles/%s/%s/%s/large/dump_1.gif' % (
             uid[0], uid[1], uid))
     self.assertEquals(fiobj.context.path,
         join(_dir, uid[0], uid[1], uid, 'large', 'dump_1.gif'))
     fiobj = self.portal.unrestrictedTraverse(
         '@@dvpdffiles/%s/%s/%s/text/dump_1.txt' % (
             uid[0], uid[1], uid))
     self.assertEquals(fiobj.context.path,
         join(_dir, uid[0], uid[1], uid, 'text', 'dump_1.txt'))
    def setUp(self):
        """ """
        portal = makerequest(self.layer['portal'])
        self.request = portal.REQUEST
        alsoProvides(self.request, IPloneintranetDocconvClientLayer)
        setRoles(portal, TEST_USER_ID, ('Manager',))

        gsettings = GlobalSettings(portal)
        self.storage_dir = mkdtemp()
        gsettings.storage_location = self.storage_dir

        # temporarily disable event handler so that we can test objects without
        # previews
        from ploneintranet.docconv.client import handlers
        _update_preview_images = handlers._update_preview_images
        handlers._update_preview_images = lambda obj, event: None

        self.workspace = api.content.create(
            type='Folder',
            title=u"Docconv Workspace",
            container=portal)
        ff = open(os.path.join(os.path.dirname(__file__), TEST_FILENAME), 'r')
        self.filedata = ff.read()
        ff.close()
        self.testfile = api.content.create(
            type='File',
            id='test-file',
            title=u"Test File",
            file=NamedBlobFile(data=self.filedata, filename=TEST_FILENAME),
            container=self.workspace)

        handlers._update_preview_images = _update_preview_images

        event.notify(BeforeTraverseEvent(portal, portal.REQUEST))
 def test_filesystem_storage_works(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     fi = self.createFile('test.pdf')
     notify(ObjectInitializedEvent(fi))
     uid = fi.UID()
     fi.reindexObject()  # for pc
     fiobj = self.portal.unrestrictedTraverse(
         '@@dvpdffiles/%s/%s/%s/small/dump_1.gif' % (uid[0], uid[1], uid))
     self.assertEquals(
         fiobj.context.path,
         join(_dir, uid[0], uid[1], uid, 'small', 'dump_1.gif'))
     fiobj = self.portal.unrestrictedTraverse(
         '@@dvpdffiles/%s/%s/%s/normal/dump_1.gif' % (uid[0], uid[1], uid))
     self.assertEquals(
         fiobj.context.path,
         join(_dir, uid[0], uid[1], uid, 'normal', 'dump_1.gif'))
     fiobj = self.portal.unrestrictedTraverse(
         '@@dvpdffiles/%s/%s/%s/large/dump_1.gif' % (uid[0], uid[1], uid))
     self.assertEquals(
         fiobj.context.path,
         join(_dir, uid[0], uid[1], uid, 'large', 'dump_1.gif'))
     fiobj = self.portal.unrestrictedTraverse(
         '@@dvpdffiles/%s/%s/%s/text/dump_1.txt' % (uid[0], uid[1], uid))
     self.assertEquals(
         fiobj.context.path,
         join(_dir, uid[0], uid[1], uid, 'text', 'dump_1.txt'))
Example #5
0
 def test_publish_unpublish_again_works_with_obfuscation(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     gsettings.storage_obfuscate = True
     fi = self.createFile('test.pdf')
     uid = fi.UID()
     fi.reindexObject()
     notify(ObjectInitializedEvent(fi))
     settings = Settings(fi)
     self.assertTrue(
         exists(join(_dir, uid[0], uid[1], uid, settings.obfuscate_secret)))
     self.assertTrue(
         listdir(join(_dir, uid[0], uid[1], uid, settings.obfuscate_secret))
         > 3)
     # publish now
     workflowTool = getToolByName(fi, 'portal_workflow')
     workflowTool.doActionFor(fi, 'publish')
     self.assertTrue(not exists(
         join(_dir, uid[0], uid[1], uid, settings.obfuscate_secret)))
     workflowTool.doActionFor(fi, 'retract')
     self.assertTrue(
         exists(join(_dir, uid[0], uid[1], uid, settings.obfuscate_secret)))
     self.assertTrue(
         listdir(join(_dir, uid[0], uid[1], uid, settings.obfuscate_secret))
         > 3)
 def test_publish_unpublish_again_works_with_obfuscation(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     gsettings.storage_obfuscate = True
     fi = self.createFile('test.pdf')
     uid = fi.UID()
     fi.reindexObject()
     notify(ObjectInitializedEvent(fi))
     settings = Settings(fi)
     self.assertTrue(exists(join(_dir, uid[0], uid[1], uid,
         settings.obfuscate_secret)))
     self.assertTrue(listdir(join(_dir, uid[0], uid[1], uid,
         settings.obfuscate_secret)) > 3)
     # publish now
     workflowTool = getToolByName(fi, 'portal_workflow')
     workflowTool.doActionFor(fi, 'publish')
     self.assertTrue(not exists(join(_dir, uid[0], uid[1], uid,
         settings.obfuscate_secret)))
     workflowTool.doActionFor(fi, 'retract')
     self.assertTrue(exists(join(_dir, uid[0], uid[1], uid,
         settings.obfuscate_secret)))
     self.assertTrue(listdir(join(_dir, uid[0], uid[1], uid,
         settings.obfuscate_secret)) > 3)
 def test_set_storage_version(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     fi = self.createFile('test.pdf')
     settings = Settings(fi)
     self.assertEquals(settings.storage_version,
                       STORAGE_VERSION)
 def test_retrieve_correct_resource_location_new_storage(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     fi = self.createFile('test.pdf')
     notify(ObjectInitializedEvent(fi))
     uid = fi.UID()
     self.assertEquals(storage.getResourceDirectory(obj=fi),
                       join(_dir, uid[0], uid[1], uid))
Example #9
0
 def test_retrieve_correct_resource_location_new_storage(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     fi = self.createFile('test.pdf')
     notify(ObjectInitializedEvent(fi))
     uid = fi.UID()
     self.assertEquals(storage.getResourceDirectory(obj=fi),
                       join(_dir, uid[0], uid[1], uid))
 def test_retrieve_correct_resource_location_old_storage(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     fi = self.createFile('test.pdf')
     settings = Settings(fi)
     del settings._metadata['storage_version']
     self.assertEquals(storage.getResourceDirectory(obj=fi),
                       join(_dir, fi.UID()))
Example #11
0
 def test_retrieve_correct_resource_location_old_storage(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     fi = self.createFile('test.pdf')
     settings = Settings(fi)
     del settings._metadata['storage_version']
     self.assertEquals(storage.getResourceDirectory(obj=fi),
                       join(_dir, fi.UID()))
 def test_cleanup_file_storage(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     fi = self.createFile('test.pdf')
     uid = fi.UID()
     self.assertTrue(exists(join(_dir, uid[0], uid[1], uid)))
     self.portal.manage_delObjects([fi.getId()])
     self.assertTrue(not exists(join(_dir, uid[0], uid[1], uid)))
 def test_filesystem_missing_gives_404(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     fi = self.createFile('test.pdf')
     notify(ObjectInitializedEvent(fi))
     uid = fi.UID()
     self.assertRaises(
         KeyError, self.portal.unrestrictedTraverse,
         '@@dvpdffiles/%s/%s/%s/small/foobar.gif' % (uid[0], uid[1], uid))
 def test_filesystem_missing_gives_404(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     fi = self.createFile('test.pdf')
     notify(ObjectInitializedEvent(fi))
     uid = fi.UID()
     self.assertRaises(KeyError,
         self.portal.unrestrictedTraverse,
             '@@dvpdffiles/%s/%s/%s/small/foobar.gif' % (
                 uid[0], uid[1], uid))
 def test_cleanup_file_storage_does_not_delete_good_files(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     fi = self.createFile('test.pdf')
     uid = fi.UID()
     fi.reindexObject()
     notify(ObjectInitializedEvent(fi))
     self.assertTrue(exists(join(_dir, uid[0], uid[1], uid)))
     self.portal.unrestrictedTraverse('@@dvcleanup-filestorage')()
     self.assertTrue(exists(join(_dir, uid[0], uid[1], uid)))
 def test_cleanup_file_storage_does_not_delete_good_files(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     fi = self.createFile('test.pdf')
     uid = fi.UID()
     fi.reindexObject()
     notify(ObjectInitializedEvent(fi))
     self.assertTrue(exists(join(_dir, uid[0], uid[1], uid)))
     self.portal.unrestrictedTraverse('@@dvcleanup-filestorage')()
     self.assertTrue(exists(join(_dir, uid[0], uid[1], uid)))
Example #17
0
 def test_filesystem_old_storage_works(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     fi = self.createFile('test.pdf')
     uid = fi.UID()
     fiobj = self.portal.unrestrictedTraverse(
         '@@dvpdffiles/{}/{}/{}/small/dump_1.gif'.format(
             uid[0], uid[1], uid))
     self.assertEqual(
         fiobj.context.path,
         join(_dir, uid[0], uid[1], uid, 'small', 'dump_1.gif'))
 def test_filesystem_old_storage_works(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     fi = self.createFile('test.pdf')
     settings = Settings(fi)
     del settings._metadata['storage_version']
     notify(ObjectInitializedEvent(fi))
     uid = fi.UID()
     fi.reindexObject()  # for pc
     fiobj = self.portal.unrestrictedTraverse(
         '@@dvpdffiles/%s/small/dump_1.gif' % uid)
     self.assertEquals(fiobj.context.path,
                       join(_dir, uid, 'small', 'dump_1.gif'))
 def test_storage_obsfucates_dir(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     gsettings.storage_obfuscate = True
     fi = self.createFile('test.pdf')
     uid = fi.UID()
     fi.reindexObject()
     notify(ObjectInitializedEvent(fi))
     settings = Settings(fi)
     self.assertTrue(exists(join(_dir, uid[0], uid[1], uid,
         settings.obfuscate_secret)))
     self.assertTrue(listdir(join(_dir, uid[0], uid[1], uid,
         settings.obfuscate_secret)) > 3)
 def test_filesystem_old_storage_works(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     fi = self.createFile('test.pdf')
     settings = Settings(fi)
     del settings._metadata['storage_version']
     notify(ObjectInitializedEvent(fi))
     uid = fi.UID()
     fi.reindexObject()  # for pc
     fiobj = self.portal.unrestrictedTraverse(
         '@@dvpdffiles/%s/small/dump_1.gif' % uid)
     self.assertEquals(fiobj.context.path,
         join(_dir, uid, 'small', 'dump_1.gif'))
Example #21
0
 def test_storage_obsfucates_dir(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     gsettings.storage_obfuscate = True
     fi = self.createFile('test.pdf')
     uid = fi.UID()
     fi.reindexObject()
     notify(ObjectInitializedEvent(fi))
     settings = Settings(fi)
     self.assertTrue(
         exists(join(_dir, uid[0], uid[1], uid, settings.obfuscate_secret)))
     self.assertTrue(
         listdir(join(_dir, uid[0], uid[1], uid, settings.obfuscate_secret))
         > 3)
Example #22
0
    def test_saves_with_file_storage(self):
        fi = self.createFile('test.odp')
        gsettings = GlobalSettings(self.portal)
        gsettings.auto_select_layout = True
        gsettings.auto_layout_file_types = ['ppt']
        gsettings.storage_type = 'File'
        _dir = mkdtemp()
        gsettings.storage_location = _dir
        notify(ObjectInitializedEvent(fi))

        fi_dir = storage.getResourceDirectory(obj=fi)
        self.assertEqual(len(listdir(fi_dir)), 4)
        self.assertEqual(len(listdir(join(fi_dir, 'normal'))), 1)
        self.assertEqual(len(listdir(join(fi_dir, 'small'))), 1)
        self.assertEqual(len(listdir(join(fi_dir, 'large'))), 1)
        self.assertEqual(len(listdir(join(fi_dir, 'text'))), 1)
        shutil.rmtree(fi_dir)
Example #23
0
    def test_saves_with_file_storage(self):
        fi = self.createFile('test.odp')
        gsettings = GlobalSettings(self.portal)
        gsettings.auto_select_layout = True
        gsettings.auto_layout_file_types = ['ppt']
        gsettings.storage_type = 'File'
        _dir = mkdtemp()
        gsettings.storage_location = _dir
        notify(ObjectInitializedEvent(fi))

        fi_dir = storage.getResourceDirectory(obj=fi)
        self.assertEqual(len(listdir(fi_dir)), 4)
        self.assertEqual(len(listdir(join(fi_dir, 'normal'))), 1)
        self.assertEqual(len(listdir(join(fi_dir, 'small'))), 1)
        self.assertEqual(len(listdir(join(fi_dir, 'large'))), 1)
        self.assertEqual(len(listdir(join(fi_dir, 'text'))), 1)
        shutil.rmtree(fi_dir)
 def test_migrate_old_storage(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     fi = self.createFile('test.pdf')
     settings = Settings(fi)
     del settings._metadata['storage_version']
     fi.reindexObject()
     notify(ObjectInitializedEvent(fi))
     self.assertEquals(settings.storage_version, 1)
     old_path = storage.getResourceDirectory(obj=fi)
     self.assertTrue(exists(old_path))
     from collective.documentviewer.upgrades import migrate_old_storage
     migrate_old_storage(self.portal)
     self.assertTrue(not exists(old_path))
     self.assertEquals(settings.storage_version, STORAGE_VERSION)
     new_path = storage.getResourceDirectory(obj=fi)
     self.assertTrue(exists(new_path))
     self.assertEquals(len(listdir(new_path)), 4)
 def test_migrate_old_storage(self):
     gsettings = GlobalSettings(self.portal)
     _dir = mkdtemp()
     gsettings.storage_location = _dir
     gsettings.storage_type = 'File'
     fi = self.createFile('test.pdf')
     settings = Settings(fi)
     del settings._metadata['storage_version']
     fi.reindexObject()
     notify(ObjectInitializedEvent(fi))
     self.assertEquals(settings.storage_version, 1)
     old_path = storage.getResourceDirectory(obj=fi)
     self.assertTrue(exists(old_path))
     from collective.documentviewer.upgrades import migrate_old_storage
     migrate_old_storage(self.portal)
     self.assertTrue(not exists(old_path))
     self.assertEquals(settings.storage_version, STORAGE_VERSION)
     new_path = storage.getResourceDirectory(obj=fi)
     self.assertTrue(exists(new_path))
     self.assertEquals(len(listdir(new_path)), 6)
Example #26
0
def documentviewer_settings(context):
    if context.readDataFile('slc.docconv.txt') is None:
        return
    portal = api.portal.get()
    gsettings = GlobalSettings(portal)
    gsettings.storage_location = '/tmp'