Beispiel #1
0
 def testIterItems(self):
     h = HBTreeFolder2()
     id_list = [
         'a-b', 'a-cd', 'b', 'd-a-b', 'd-c-d', 'd-f-a', 'e-cd', 'e-f', 'f'
     ]
     for i in id_list:
         h._setOb(i, tuple(i))
     while 1:
         for min in (None, 'a', 'a-a', 'a-b', 'a-b-a', 'a-c', 'a-cd',
                     'a-cde', 'a-d', 'aa', 'b', 'b-c-d', 'c', 'd'):
             if min:
                 m = min.split('-')
                 for i, id in enumerate(id_list):
                     if m <= id.split('-'):
                         break
                 else:
                     i += 1
             else:
                 i = 0
             expected = [(i, tuple(i)) for i in id_list[i:]]
             self.assertEqual(expected, list(h._htree_iteritems(min)))
         if not id_list:
             break
         i = random.choice(id_list)
         id_list.remove(i)
         h._delOb(i)
Beispiel #2
0
    def testObjectListing(self):
        f2 = HBTreeFolder2('somefolder')
        self.f._setObject(f2.id, f2)
        # Hack in an absolute_url() method that works without context.
        self.f.absolute_url = str
        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)
Beispiel #3
0
 def testObjectIds(self):
     self.assertEqual(list(self.f.objectIds()), ['item'])
     self.assertEqual(list(self.f.keys()), ['item'])
     self.assertEqual(list(self.ff.objectIds()), [])
     f3 = HBTreeFolder2('item3')
     self.f._setOb(f3.id, f3)
     lst = list(self.f.objectIds())
     lst.sort()
     self.assertEqual(lst, ['item', 'item3'])
Beispiel #4
0
 def testObjectListingWithSpaces(self):
     # The option list must use value attributes to preserve spaces.
     name = " some folder "
     f2 = HBTreeFolder2(name)
     self.f._setObject(f2.id, f2)
     self.f.absolute_url = str
     info = self.f.getBatchObjectListing()
     expect = '<option value="%s">%s</option>' % (name, name)
     self.assert_(info['formatted_list'].find(expect) > 0)
Beispiel #5
0
 def testReplace(self):
     old_f = Folder()
     old_f.id = 'item'
     inner_f = HBTreeFolder2('inner')
     old_f._setObject(inner_f.id, inner_f)
     self.ff._populateFromFolder(old_f)
     self.assertEqual(self.ff.objectCount(), 1)
     self.assert_(self.ff.has_key('inner'))
     self.assertEqual(self.getBase(self.ff._getOb('inner')), inner_f)
Beispiel #6
0
    def testRestrictedIteration(self):
        """
        Check content iterators can be used by restricted python code.
        """
        # To let restricted python access methods on folder
        marker = object()
        saved_class_attributes = {}
        for method_id in ('objectIds', 'objectValues', 'objectItems'):
            roles_id = method_id + '__roles__'
            saved_class_attributes[roles_id] = getattr(HBTreeFolder2, roles_id,
                                                       marker)
            setattr(HBTreeFolder2, roles_id, None)
        try:
            h = HBTreeFolder2()
            # whatever value, as long as it has an __of__
            h._setOb('foo', HBTreeFolder2())
            script = PythonScript('script')
            script.ZPythonScript_edit(
                'h',
                dedent("""
            for dummy in h.objectIds():
              pass
            for dummy in h.objectValues():
              pass
            for dummy in h.objectItems():
              pass
          """))

            class DummyRequest(object):
                # To make Shared.DC.Scripts.Bindings.Bindings._getTraverseSubpath
                # happy
                other = {}

            script.REQUEST = DummyRequest
            script(h)
        finally:
            for roles_id, orig in six.iteritems(saved_class_attributes):
                if orig is marker:
                    delattr(HBTreeFolder2, roles_id)
                else:
                    setattr(HBTreeFolder2, roles_id, orig)
Beispiel #7
0
 def setUp(self):
     self.f = HBTreeFolder2('root')
     ff = HBTreeFolder2('item')
     self.f._setOb(ff.id, ff)
     self.ff = self.f._getOb(ff.id)
Beispiel #8
0
 def testSetObject(self):
     f2 = HBTreeFolder2('item2')
     self.f._setObject(f2.id, f2)
     self.assert_(self.f.has_key('item2'))
     self.assertEqual(self.f.objectCount(), 2)