From 88c853a07d936040970c41b568c83bad102d110b Mon Sep 17 00:00:00 2001 From: Philip Bauer Date: Sat, 18 May 2019 03:54:30 +0200 Subject: [PATCH] Fix bug when getting propertysheet and bugs in manage_FTPlist (#624) * Fix bug when getting propertysheet. Fixes bug introduced in https://github.com/zopefoundation/Zope/commit/b4495eb403c622300b02071a0904b3ad948cc4fe?diff=unified&w=1#diff-3bb20756c73e7cac2fb14728c89e578aR472 * I don't really know how this was broken but a change from https://github.com/zopefoundation/Zope/commit/b4495eb403c622300b02071a0904b3ad948cc4fe#diff-f7f065aa241603d275d21b8e191fa844 broke the test plone.app.testing.layers_zserver.rst * fix another failing test (plone.testing.zserver.rst) * - make flake8 happy * fix another bug in manage_FTPlist introduced in https://github.com/zopefoundation/Zope/commit/b4495eb403c622300b02071a0904b3ad948cc4fe#diff-f7f065aa241603d275d21b8e191fa844 * - adding tests that cover the changes --- src/OFS/ObjectManager.py | 9 +++++---- src/OFS/PropertySheets.py | 2 +- src/OFS/bbb.py | 2 +- src/OFS/tests/testObjectManager.py | 31 ++++++++++++++++++++++++++++++ src/OFS/tests/testProperties.py | 25 ++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 6 deletions(-) diff --git a/src/OFS/ObjectManager.py b/src/OFS/ObjectManager.py index ba6be85e45..f8225cb11d 100644 --- a/src/OFS/ObjectManager.py +++ b/src/OFS/ObjectManager.py @@ -769,8 +769,8 @@ def manage_FTPlist(self, REQUEST): files.sort() - if not hasattr(self, 'isTopLevelPrincipiaApplicationObject') and \ - self.isTopLevelPrincipiaApplicationObject: + if not (hasattr(self, 'isTopLevelPrincipiaApplicationObject') + and self.isTopLevelPrincipiaApplicationObject): files.insert(0, ('..', aq_parent(self))) files.insert(0, ('.', self)) for k, v in files: @@ -795,8 +795,9 @@ def manage_FTPstat(self, REQUEST): mode = 0o0040000 from AccessControl.User import nobody # check to see if we are acquiring our objectValues or not - if not len(REQUEST.PARENTS) > 1 and \ - self.objectValues() == REQUEST.PARENTS[1].objectValues(): + parents = REQUEST.PARENTS + if not (len(parents) > 1 + and self.objectValues() == parents[1].objectValues()): try: if getSecurityManager().validate( None, self, 'manage_FTPlist', self.manage_FTPlist): diff --git a/src/OFS/PropertySheets.py b/src/OFS/PropertySheets.py index 69854969ca..47f3812bf4 100644 --- a/src/OFS/PropertySheets.py +++ b/src/OFS/PropertySheets.py @@ -470,7 +470,7 @@ def items(self): def get(self, name, default=None): for propset in self.__propsets__(): if propset.id == name or \ - getattr(propset, 'xml_namespace', None) == name: + getattr(propset, 'xml_namespace', object)() == name: return propset.__of__(self) return default diff --git a/src/OFS/bbb.py b/src/OFS/bbb.py index 7f9bf188bf..6889f3718a 100644 --- a/src/OFS/bbb.py +++ b/src/OFS/bbb.py @@ -44,4 +44,4 @@ class DAVPropertySheetMixin(object): class DAVProperties(object): - pass + id = 'webdav' diff --git a/src/OFS/tests/testObjectManager.py b/src/OFS/tests/testObjectManager.py index c011b8a160..e7f392ba71 100644 --- a/src/OFS/tests/testObjectManager.py +++ b/src/OFS/tests/testObjectManager.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import marshal import os import unittest from logging import getLogger @@ -17,10 +18,12 @@ from Acquisition import Implicit from Acquisition import aq_self from App.config import getConfiguration +from OFS import bbb from OFS.interfaces import IItem from OFS.metaconfigure import setDeprecatedManageAddDelete from OFS.ObjectManager import ObjectManager from OFS.SimpleItem import SimpleItem +from Testing.makerequest import makerequest from zExceptions import BadRequest from Zope2.App import zcml from zope.component.testing import PlacelessSetup @@ -549,6 +552,34 @@ def test_getBookmarkableURLs(self): # Cleanup getConfiguration().zmi_bookmarkable_urls = saved_state + @unittest.skipUnless(bbb.HAS_ZSERVER, 'Test requires ZServer') + def test_FTPList(self): + from OFS.Folder import Folder + om = makerequest(self._makeOne()) + om.isTopLevelPrincipiaApplicationObject = True + om._setObject('sub', Folder('sub')) + om.sub._setObject('subsub', Folder('subsub')) + req = om.REQUEST + req.PARENTS = [om] + + # At the root we only see a single entry for the subfolder + data = marshal.loads(om.manage_FTPlist(req)) + self.assertEqual(len(data), 1) + self.assertEqual(data[0][0], 'sub') + + # In the subfolder, we see an entry for the current folder + # and the folder in it + data = marshal.loads(om.sub.manage_FTPlist(req)) + self.assertEqual(len(data), 2) + self.assertEqual(data[0][0], '.') + self.assertEqual(data[1][0], 'subsub') + + # In the leaf node we see entries for the parent and grandparent + data = marshal.loads(om.sub.subsub.manage_FTPlist(req)) + self.assertEqual(len(data), 2) + self.assertEqual(data[0][0], '.') + self.assertEqual(data[1][0], '..') + _marker = object() diff --git a/src/OFS/tests/testProperties.py b/src/OFS/tests/testProperties.py index 937b54e731..ee260af764 100644 --- a/src/OFS/tests/testProperties.py +++ b/src/OFS/tests/testProperties.py @@ -103,6 +103,31 @@ def test_updateProperty_transforms(self): self.assertEqual(pm.getProperty('test_lines'), (b'uni', b'code')) +class TestPropertySheets(unittest.TestCase): + + def _makePropSheet(self, *args, **kw): + from OFS.PropertySheets import PropertySheet + return PropertySheet(*args, **kw) + + def _makeFolder(self): + from OFS.Folder import Folder + fldr = Folder('testfolder') + return fldr + + def test_get(self): + parent = self._makeFolder() + pss = parent.propertysheets + sheet_w_name = self._makePropSheet(id='test1') + sheet_w_xml = self._makePropSheet(id='foobar', + md={'xmlns': 'test2'}) + parent.__propsets__ += (sheet_w_name, sheet_w_xml) + + self.assertIsNone(pss.get('unknown')) + self.assertEqual(pss.get('unknown', default='moep'), 'moep') + self.assertEqual(pss.get('test1').getId(), 'test1') + self.assertEqual(pss.get('test2').getId(), 'foobar') + + class TestPropertySheet(unittest.TestCase): def _makeOne(self, *args, **kw):