Esempio n. 1
0
    def test_get_zodb_resources_filter(self):
        app = self.layer['app']

        foo = FilesystemResourceDirectory(
            os.path.join(test_dir_path, 'demo', 'foo'))
        provideUtility(foo, provides=IResourceDirectory, name=u'++demo++foo')

        manifestTest = FilesystemResourceDirectory(
            os.path.join(test_dir_path, 'demo', 'manifest-test'))
        provideUtility(manifestTest,
                       provides=IResourceDirectory,
                       name=u'++demo++manifest-test')

        root = BTreeFolder2('portal_resources')
        app._setOb('portal_resources', root)
        root._setOb('demo', BTreeFolder2('demo'))
        root['demo']._setOb('bar', BTreeFolder2('bar'))
        root['demo']._setOb('baz', BTreeFolder2('baz'))

        persistentDir = PersistentResourceDirectory(root)
        provideUtility(persistentDir,
                       provides=IResourceDirectory,
                       name=u'persistent')

        resources = getZODBResources(TEST_FORMAT,
                                     filter=lambda dir: dir.__name__ != 'baz')

        self.assertEqual(resources, {'bar': None})
Esempio n. 2
0
    def test_get_all_resources(self):
        app = self.layer['app']

        foo = FilesystemResourceDirectory(
            os.path.join(test_dir_path, 'demo', 'foo'))
        provideUtility(foo, provides=IResourceDirectory, name=u'++demo++foo')

        manifestTest = FilesystemResourceDirectory(
            os.path.join(test_dir_path, 'demo', 'manifest-test'))
        provideUtility(manifestTest,
                       provides=IResourceDirectory,
                       name=u'++demo++manifest-test')

        root = BTreeFolder2('portal_resources')
        app._setOb('portal_resources', root)
        root._setOb('demo', BTreeFolder2('demo'))
        root['demo']._setOb('bar', BTreeFolder2('bar'))

        persistentDir = PersistentResourceDirectory(root)
        provideUtility(persistentDir,
                       provides=IResourceDirectory,
                       name=u'persistent')

        resources = getAllResources(TEST_FORMAT)

        self.assertEqual(
            resources, {
                'bar': None,
                'foo': None,
                'manifest-test': {
                    'bar': 'baz',
                    'description': None,
                    'title': 'Manifest test'
                }
            })
Esempio n. 3
0
    def __call__(self):
        filedata = self.request.form.get("file", None)

        if filedata is None:
            return json.dumps({'failure':'error'})
        
        directory = PersistentResourceDirectory(self.context)
        name = filedata.filename.encode('utf-8')
        data = filedata.read()

        try:
            directory.writeFile(name, data)
            self.request.response.setHeader('Content-Type', 'application/json')
        except:
            return json.dumps({'failure':'error'})

        return json.dumps({'success':'create'})
Esempio n. 4
0
    def __call__(self):
        filedata = self.request.form.get("file", None)

        if filedata is None:
            return json.dumps({'failure': 'error'})

        directory = PersistentResourceDirectory(self.context)
        name = filedata.filename.encode('utf-8')
        data = filedata.read()

        try:
            directory.writeFile(name, data)
            self.request.response.setHeader('Content-Type', 'application/json')
        except:
            return json.dumps({'failure': 'error'})

        return json.dumps({'success': 'create'})
Esempio n. 5
0
    def _makeOne(self):
        root = BTreeFolder2('portal_resources')
        root._setOb('demo', BTreeFolder2('demo'))
        root.demo._setOb('foo', BTreeFolder2('foo'))

        from StringIO import StringIO
        from OFS.Image import File
        file = File('test.html', 'test.html', StringIO('asdf'))
        root.demo.foo._setOb('test.html', file)

        from plone.resource.directory import PersistentResourceDirectory
        return PersistentResourceDirectory(root)
Esempio n. 6
0
    def test_traverse_persistent_directory(self):
        root = BTreeFolder2('portal_resources')
        self.app._setOb('portal_resources', root)
        root._setOb('demo', BTreeFolder2('demo'))
        root.demo._setOb('foo', BTreeFolder2('foo'))

        dir = PersistentResourceDirectory(root)
        provideUtility(dir, provides=IResourceDirectory, name=u'persistent')

        res = self.app.restrictedTraverse('++demo++foo')
        self.assertEqual('portal_resources/demo/foo',
                         '/'.join(res.context.getPhysicalPath()))

        self.assertRaises(NotFound, self.app.restrictedTraverse, '++demo++bar')
Esempio n. 7
0
    def test_ctor_implicit_context(self):
        from zope.site.testing import siteSetUp, createSiteManager, siteTearDown
        siteSetUp()

        site = BTreeFolder2('site')
        createSiteManager(site, setsite=True)
        root = self._makeOne().context
        site._setOb('portal_resources', root)

        from plone.resource.directory import PersistentResourceDirectory
        try:
            dir = PersistentResourceDirectory()
            # context should be stored unwrapped
            self.assertTrue(aq_base(root) is dir.context)

            # but re-wrapped during traversal
            traversed = dir['demo']
            self.assertTrue(site in traversed.context.aq_chain)
        finally:
            siteTearDown()
Esempio n. 8
0
    def setUp(self):
        self.app = self.layer.get('app')
        zca.pushGlobalRegistry()

        # set up all three types of directory
        package_dir_path = os.path.join(test_dir_path, 'demo', 'foo')
        self.package_dir = dir = FilesystemResourceDirectory(package_dir_path)
        provideUtility(dir, provides=IResourceDirectory, name=u'++demo++foo')

        self.global_dir = dir = FilesystemResourceDirectory(test_dir_path)
        provideUtility(dir, provides=IResourceDirectory, name=u'')

        root = BTreeFolder2('portal_resources')
        self.app._setOb('portal_resources', root)
        root._setOb('demo', BTreeFolder2('demo'))
        root.demo._setOb('foo', BTreeFolder2('foo'))
        self.zodb_dir = dir = PersistentResourceDirectory(root)
        provideUtility(dir, provides=IResourceDirectory, name=u'persistent')

        # We don't want a false positive for the following.
        provideUtility(dir, provides=IResourceDirectory, name=u'++bogus++foo')
    def test_traverse_persistent_directory(self):
        root = BTreeFolder2('portal_resources')
        self.app._setOb('portal_resources', root)
        root._setOb('demo', BTreeFolder2('demo'))
        root['demo']._setOb('foo', BTreeFolder2('foo'))
        root['demo']['foo']._setOb('test.html', File('test.html', 'test.html', 'asdf'))

        dir = PersistentResourceDirectory(root)
        provideUtility(dir, provides=IResourceDirectory, name=u'persistent')

        out = StringIO()
        request = self.layer['request']
        response = request.response
        response.stdout = out

        zipview = self.app.unrestrictedTraverse('++demo++foo/@@download-zip')
        zipview()

        zf = zipfile.ZipFile(out)

        self.assertTrue('foo/test.html' in zf.namelist())
        self.assertEqual('asdf', zf.open('foo/test.html').read())
Esempio n. 10
0
    def test_cloneDirectory(self):
        from plone.resource.directory import PersistentResourceDirectory
        from plone.resource.utils import cloneResourceDirectory

        root = BTreeFolder2('portal_resources')
        root._setOb('demo', BTreeFolder2('demo'))
        root['demo']._setOb('foo', BTreeFolder2('foo'))
        root['demo']._setOb('bar', BTreeFolder2('bar'))

        source = PersistentResourceDirectory(root['demo']['foo'])
        target = PersistentResourceDirectory(root['demo']['bar'])

        source.writeFile('file1.txt', 'file1')
        source.writeFile('subdir1/file2.txt', 'file2')
        source.makeDirectory('subdir2')

        cloneResourceDirectory(source, target)

        self.assertEqual(source.listDirectory(), target.listDirectory())
        self.assertEqual(source['subdir1'].listDirectory(), target['subdir1'].listDirectory())
        self.assertEqual(source['subdir2'].listDirectory(), target['subdir2'].listDirectory())
        self.assertEqual(source.readFile('file1.txt'), target.readFile('file1.txt'))
        self.assertEqual(source.readFile('subdir1/file2.txt'), target.readFile('subdir1/file2.txt'))
def contentTypeZip(ctype_name):
    ctype_folder = getContentTypeFolder(ctype_name)
    ctype_folder = PersistentResourceDirectory(ctype_folder)
    archive_stream = StringIO()
    ctype_folder.exportZip(archive_stream)
    return archive_stream.getvalue()
Esempio n. 12
0
    def test_cloneDirectory(self):
        from plone.resource.directory import PersistentResourceDirectory
        from plone.resource.utils import cloneResourceDirectory

        root = BTreeFolder2('portal_resources')
        root._setOb('demo', BTreeFolder2('demo'))
        root['demo']._setOb('foo', BTreeFolder2('foo'))
        root['demo']._setOb('bar', BTreeFolder2('bar'))

        source = PersistentResourceDirectory(root['demo']['foo'])
        target = PersistentResourceDirectory(root['demo']['bar'])

        source.writeFile('file1.txt', 'file1')
        source.writeFile('subdir1/file2.txt', 'file2')
        source.makeDirectory('subdir2')

        cloneResourceDirectory(source, target)

        self.assertEqual(source.listDirectory(), target.listDirectory())
        self.assertEqual(source['subdir1'].listDirectory(), target['subdir1'].listDirectory())
        self.assertEqual(source['subdir2'].listDirectory(), target['subdir2'].listDirectory())
        self.assertEqual(source.readFile('file1.txt'), target.readFile('file1.txt'))
        self.assertEqual(source.readFile('subdir1/file2.txt'), target.readFile('subdir1/file2.txt'))