Skip to content

Commit

Permalink
- adding tests that cover the changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed May 18, 2019
1 parent cee3ef4 commit 555adeb
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/OFS/PropertySheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +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) is not None and \
propset.xml_namespace() == 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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 555adeb

Please sign in to comment.