Skip to content

Commit

Permalink
Fix bug when getting propertysheet and bugs in manage_FTPlist (#624)
Browse files Browse the repository at this point in the history
* Fix bug when getting propertysheet.
Fixes bug introduced in b4495eb?diff=unified&w=1#diff-3bb20756c73e7cac2fb14728c89e578aR472

* I don't really know how this was broken but a change from
b4495eb#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 b4495eb#diff-f7f065aa241603d275d21b8e191fa844

* - adding tests that cover the changes
  • Loading branch information
pbauer authored and dataflake committed May 18, 2019
1 parent 474cd53 commit 88c853a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/OFS/ObjectManager.py
Expand Up @@ -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:
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/OFS/PropertySheets.py
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/OFS/bbb.py
Expand Up @@ -44,4 +44,4 @@ class DAVPropertySheetMixin(object):


class DAVProperties(object):
pass
id = 'webdav'
31 changes: 31 additions & 0 deletions src/OFS/tests/testObjectManager.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import marshal
import os
import unittest
from logging import getLogger
Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand Down
25 changes: 25 additions & 0 deletions src/OFS/tests/testProperties.py
Expand Up @@ -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):
Expand Down

0 comments on commit 88c853a

Please sign in to comment.