def testItems_keys_values_and_iterators(self):
        portal = self.layer['portal']
        setRoles(portal, TEST_USER_ID, ('Manager',))
        doc = self._makeOne()
        from collective.btrees.interfaces import IOOBTreeContainer
        container = IOOBTreeContainer(doc)
        self.assertEqual(len(container.keys()), 0)
        key = object()
        value = object()
        container.insert(key, value)
        self.assertEqual(container.get(key), value)
        self.assertEqual(len(container.items()), 1)
        self.assertEqual(len(container.keys()), 1)
        self.assertEqual(len(container.values()), 1)
        self.assertEqual(list(container.items()), [(key, value)])
        self.assertEqual(list(container.keys()), [key])
        self.assertEqual(list(container.values()), [value])

        # Test the iterators.
        item_iterator = container.iteritems()
        self.assertEqual(item_iterator.next(), (key, value))
        self.assertRaises(StopIteration, item_iterator.next)
        key_iterator = container.iterkeys()
        self.assertEqual(key_iterator.next(), key)
        self.assertRaises(StopIteration, key_iterator.next)
        value_iterator = container.itervalues()
        self.assertEqual(value_iterator.next(), value)
        self.assertRaises(StopIteration, value_iterator.next)
 def testOOBTree(self):
     portal = self.layer['portal']
     setRoles(portal, TEST_USER_ID, ('Manager',))
     doc = self._makeOne()
     from collective.btrees.interfaces import IOOBTreeContainer
     container = IOOBTreeContainer(doc)
     self.assertEqual(len(container.keys()), 0)
     key = object()
     value = object()
     self.assertEqual(container.get(key), None)
     container.insert(key, value)
     self.assertEqual(container.get(key), value)
     self.assertEqual(list(container.items()), [(key, value)])
     container.clear()
     self.assertEqual(list(container.keys()), [])
 def testClear(self):
     portal = self.layer['portal']
     setRoles(portal, TEST_USER_ID, ('Manager',))
     doc = self._makeOne()
     from collective.btrees.interfaces import IOOBTreeContainer
     container = IOOBTreeContainer(doc)
     container.insert(object(), object())
     container.insert(object(), object())
     container.insert(object(), object())
     self.assertEqual(len(container.items()), 3)
     # Remove all.
     container.clear()
     self.assertEqual(len(container.items()), 0)
     self.assertEqual(len(container.keys()), 0)
     self.assertEqual(len(container.values()), 0)
     self.assertRaises(StopIteration, container.iteritems().next)
     self.assertRaises(StopIteration, container.iterkeys().next)
     self.assertRaises(StopIteration, container.itervalues().next)
     # Clearing an empty container should work too of course.
     container.clear()