def __init__(self, id=None): """ return a SmurlFolder instance """ self.minlength_alpha = 1 self.minlength_numeric = 1 self.upper_and_lower = False self.avoid_duplicates = True BTreeFolder2.__init__(self, id)
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})
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 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' } })
def __call__(self, id, title): # The queue might get large, and we don't want it showing its # contents in navigation mqueue = BTreeFolder(id) mqueue.title = title directlyProvides(mqueue,IModerationQueue) return mqueue
def __init__(self, id, title, automatic=False): self.id = id self.title = title self.creation_date = DateTime() self.closing_date = None self.automatic = automatic self.last_msg_id = 0 BTreeFolder2.__init__(self)
def __call__(self, id, title, **kwargs): if kwargs.get('btree', None): folder = BTreeFolder(id) else: folder = Folder(id) folder.title = title directlyProvides(folder, IListArchiveSubFolder) return folder
def test_default_site_layout_cache(self): # Clear cache if there if hasattr(self.portal, ATTR): delattr(self.portal, ATTR) resources = getToolByName(self.portal, 'portal_resources') resources._setOb('sitelayout', BTreeFolder2('sitelayout')) resources['sitelayout']._setOb('testlayout3', BTreeFolder2('testlayout3')) resources['sitelayout']['testlayout3']._setOb( 'site.html', File( 'site.html', 'site.html', StringIO( '<html><head><title>ZODB test</title></head></html>'))) self.registry[DEFAULT_SITE_LAYOUT_REGISTRY_KEY] = \ '/++sitelayout++testlayout3/site.html' view = getMultiAdapter(( self.portal, self.request, ), name=u'default-site-layout') rendered = view() self.assertTrue(u"ZODB test" in rendered) resources['sitelayout']['testlayout3']._delOb('site.html') resources['sitelayout']['testlayout3']._setOb( 'site.html', File( 'site.html', 'site.html', StringIO( '<html><head><title>Cache test</title></head></html>'))) view = getMultiAdapter(( self.portal, self.request, ), name=u'default-site-layout') rendered = view() self.assertFalse(u"Cache test" in rendered) # hidden by cache self.assertTrue(u"ZODB test" in rendered) self.assertEqual('/++sitelayout++testlayout3/site.html', view.layout) # Test cache is set self.assertTrue(hasattr(self.portal, ATTR)) # Update cache for key in getattr(self.portal, ATTR): getattr(self.portal, ATTR)[key] = None self.assertIsNone(view.layout) # because of cache
def __init__(self): BTreeFolder2.__init__(self) # Defaults from CMFCore.MemberDataTool self._setProperty('email', '', 'string') self._setProperty('portal_skin', '', 'string') self._setProperty('listed', '', 'boolean') self._setProperty('login_time', '2000/01/01', 'date') self._setProperty('last_login_time', '2000/01/01', 'date') # Compatibility with Plone's MemberData tool self.portraits=BTreeFolder2(id='portraits')
def __init__(self): BTreeFolder2.__init__(self) # Defaults from CMFCore.MemberDataTool self._setProperty('email', '', 'string') self._setProperty('portal_skin', '', 'string') self._setProperty('listed', '', 'boolean') self._setProperty('login_time', '2000/01/01', 'date') self._setProperty('last_login_time', '2000/01/01', 'date') # Compatibility with Plone's MemberData tool self.portraits = BTreeFolder2(id='portraits')
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)
def __init__(self, id, title, description, sortorder, start_date, end_date, public_registration, allow_file, contributor, releasedate, lang): """ """ self.id = id NyValidation.__dict__['__init__'](self) NyCheckControl.__dict__['__init__'](self) NyContainer.__dict__['__init__'](self) BTreeFolder2.__init__(self) self.contributor = contributor try: del self.title except: pass self.save_properties(title, description, sortorder, start_date, end_date, public_registration, allow_file, releasedate, lang) NyProperties.__dict__['__init__'](self) self.submitted = 1
def __init__(self, id, admin_mail): """ Create Bitakora community """ BTreeFolder2.__init__(self, id) self.id = id self.admin_mail = admin_mail self.management_page_charset = 'UTF-8' self.title = u'blog community' self._addLocalizer() self._addCatalog() self._addMethods() self._addTemplates() self._addContent() self._addOthers() self._buildIndexes()
def __init__(self, id, title, author, body, tags=[], date=u'', publish=1, comment_allowed=1): """ """ BTreeFolder2.__init__(self, id) self.id = str(id) self.title = title self.author = author self.body = body self.tags = tags self.date = date self.comment_allowed = comment_allowed self.reference_allowed = comment_allowed self.published = publish self.reindex_object()
def test_default_site_layout_invalidate_mtime(self): # Clear cache if there if hasattr(self.portal, ATTR): delattr(self.portal, ATTR) resources = getToolByName(self.portal, 'portal_resources') resources._setOb('sitelayout', BTreeFolder2('sitelayout')) resources['sitelayout']._setOb('testlayout3', BTreeFolder2('testlayout3')) resources['sitelayout']['testlayout3']._setOb( 'site.html', File( 'site.html', 'site.html', StringIO( '<html><head><title>ZODB test</title></head></html>'))) self.registry[DEFAULT_SITE_LAYOUT_REGISTRY_KEY] =\ '/++sitelayout++testlayout3/site.html' view = getMultiAdapter(( self.portal, self.request, ), name=u'default-site-layout') rendered = view() self.assertTrue(u"ZODB test" in rendered) # Trigger invalidation by modifying the context and committing self.portal.title = u"New title" transaction.commit() # Modify the site layout resources['sitelayout']['testlayout3']._delOb('site.html') resources['sitelayout']['testlayout3']._setOb( 'site.html', File( 'site.html', 'site.html', StringIO( '<html><head><title>Cache test</title></head></html>'))) view = getMultiAdapter(( self.portal, self.request, ), name=u'default-site-layout') rendered = view() self.assertTrue(u"Cache test" in rendered) self.assertFalse(u"ZODB test" in rendered)
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')
def test_btreefolder2(self): from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2 conn = self.db.open() try: app = conn.root()['Application'] f = BTreeFolder2('Holidays') f.id = 'Holidays' app._setObject(f.id, f, set_owner=0) f2 = Folder() f2.id = 'Easter' app.Holidays._setObject(f2.id, f2) transaction.commit() # Verify serialize() found the unmanaged subobjects. self.assertEqual(app.Holidays._tree._p_oid, 'unmanaged') # Sanity check self.assertEqual(app.Holidays.objectCount(), 1) conn2 = self.db.open() try: app2 = conn2.root()['Application'] self.assert_(app2.Holidays._tree.has_key('Easter')) self.assert_(not app2.Holidays.__dict__.has_key('Easter')) # Verify deserialize() found the unmanaged subobjects. self.assertEqual(app2.Holidays._tree._p_oid, 'unmanaged') app2.Holidays._delObject('Easter') transaction.commit() finally: conn2.close() # The deletion should be seen by both connections. conn.sync() self.assertEqual(app.Holidays.objectCount(), 0) finally: conn.close()
def testObjectListing(self): f2 = BTreeFolder2('somefolder') self.f._setObject(f2.id, f2) # Hack in an absolute_url() method that works without context. self.f.absolute_url = lambda: '' info = self.f.getBatchObjectListing() self.assertEqual(info['b_start'], 1) self.assertEqual(info['b_end'], 2) self.assertEqual(info['prev_batch_url'], '') self.assertEqual(info['next_batch_url'], '') self.assert_(info['formatted_list'].find('</select>') > 0) self.assert_(info['formatted_list'].find('item') > 0) self.assert_(info['formatted_list'].find('somefolder') > 0) # Ensure batching is working. info = self.f.getBatchObjectListing({'b_count': 1}) self.assertEqual(info['b_start'], 1) self.assertEqual(info['b_end'], 1) self.assertEqual(info['prev_batch_url'], '') self.assert_(info['next_batch_url'] != '') self.assert_(info['formatted_list'].find('item') > 0) self.assert_(info['formatted_list'].find('somefolder') < 0) info = self.f.getBatchObjectListing({'b_start': 2}) self.assertEqual(info['b_start'], 2) self.assertEqual(info['b_end'], 2) self.assert_(info['prev_batch_url'] != '') self.assertEqual(info['next_batch_url'], '') self.assert_(info['formatted_list'].find('item') < 0) self.assert_(info['formatted_list'].find('somefolder') > 0)
def testKeys(self): self.assertEqual(list(self.f.keys()), ['item']) self.assertEqual(list(self.ff.keys()), []) f3 = BTreeFolder2('item3') self.f[f3.id] = f3 lst = list(self.f.keys()) lst.sort() self.assertEqual(lst, ['item', 'item3'])
def testObjectIds(self): self.assertEqual(list(self.f.objectIds()), ['item']) self.assertEqual(list(self.ff.objectIds()), []) f3 = BTreeFolder2('item3') self.f._setOb(f3.id, f3) lst = list(self.f.objectIds()) lst.sort() self.assertEqual(lst, ['item', 'item3'])
def testReplace(self): old_f = Folder() old_f.id = 'item' inner_f = BTreeFolder2('inner') old_f._setObject(inner_f.id, inner_f) self.ff._populateFromFolder(old_f) self.assertEqual(self.ff.objectCount(), 1) self.assert_('inner' in self.ff) self.assertEqual(self.getBase(self.ff._getOb('inner')), inner_f)
def testObjectListingWithSpaces(self): # The option list must use value attributes to preserve spaces. name = " some folder " f2 = BTreeFolder2(name) self.f._setObject(f2.id, f2) self.f.absolute_url = lambda: '' info = self.f.getBatchObjectListing() expect = '<option value="%s">%s</option>' % (name, name) self.assert_(info['formatted_list'].find(expect) > 0)
def makeDirectory(self, path): parent = self.context names = path.strip('/').split('/') for name in names: if name not in parent: if isinstance(name, unicode): name = name.encode('utf-8') f = BTreeFolder2(name) parent._setOb(name, f) parent = parent[name]
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 __init__(self, id, title, subtitle, description, contact_mail): """ Constructor """ BTreeFolder2.__init__(self, id) self.id = id self.title = title self.subtitle = subtitle self.description = description self.contact_mail = contact_mail self.management_page_charset = u'UTF-8' self.sidebar_html = u'' self._setObject('Catalog', ZCatalog.ZCatalog('Catalog', 'Catalog')) self._buildIndexes() self._addMethods() self._setObject('pingback', PingMethodContainer()) self.postcount = 0 self._links = IOBTree() # if 0 not allowed, 1 allowed, 2 allowed but moderated self.comment_allowed = 1 self.reference_allowed = 1 #self.imageUrl = None self.imagename = '' self.CAPTCHA_ENABLED = 1
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())
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()
def __init__(self, id, title): BTreeFolder2.__init__(self, id) self.title = title self.profiles_meta = {}
def testSetItem(self): self.f['ff2'] = BTreeFolder2('item2') self.assertEqual(self.f.ff2.id, 'item2')
def setUp(self): self.f = BTreeFolder2('root') ff = BTreeFolder2('item') self.f._setOb(ff.id, ff) self.ff = self.f._getOb(ff.id)
def __init__(self, *args, **kw): BTreeFolder2.__init__(self, *args, **kw) self._create_catalog() self._linkrange = (1, 3) # currently unused; just a marker
def __init__(self, objId): BTreeFolder2.__init__(self, objId) XWFFileStorage2.__init__(self, objId)
def __init__(self, id=None): BTreeFolder2.__init__(self, id) self._last_pin_index = -1
def testSetObject(self): f2 = BTreeFolder2('item2') self.f._setObject(f2.id, f2) self.assert_('item2' in self.f) self.assertEqual(self.f.objectCount(), 2)
def __init__(self, *args, **kw): BTreeFolder2.__init__(self, *args, **kw) self._create_catalog() self._linkrange = (1,3) # currently unused; just a marker
def __init__(self): BaseTool.__init__(self) self.portraits = BTreeFolder2(id='portraits')
def __init__(self): BTreeFolder2.__init__(self, id=self.id)
def __init__(self, id, title, vocab_id, extra): BTreeFolder2.__init__(self, id) ZCatalog.__init__(self, id, title, vocab_id, extra)
def test_listDirectory_filters_by_name(self): dir = self._makeOne() dir.context._setOb('.svn', BTreeFolder2('filtered')) self.assertEqual(['demo'], dir.listDirectory())
def __init__(self): super(MemberDataTool, self).__init__() self.thumbnails = BTreeFolder2(id='thumbnails')
def __init__(self, id): BTreeFolder2.__init__(self, id) self._default_storage = None self._storage_map = {} self._all_storages = []