コード例 #1
0
ファイル: entry.py プロジェクト: bluedynamics/cone.zodb
def zodb_entry_for(node):
    while node:
        if IZODBEntryNode.providedBy(node):
            return node._v_parent
        if node.parent is None or not IZODBNode.providedBy(node):
            return None
        node = node.parent
コード例 #2
0
def combined_title(node):
    titles = list()
    while True:
        titles.append(node.attrs.get('title', node.name))
        if node.parent is None or IZODBEntryNode.providedBy(node):
            break
        node = node.parent
    titles.reverse()
    return ' - '.join(titles)
コード例 #3
0
 def __call__(_next, self):
     _next(self)
     if not IZODBEntryNode.providedBy(self):
         self.catalog_indexer.index_doc(self)
コード例 #4
0
ファイル: test_entry.py プロジェクト: bluedynamics/cone.zodb
    def test_entry(self):
        self.layer.new_request()

        # Create node containing ZODBEntry
        root = BaseNode(name='root')
        root['myentry'] = ZODBEntry()
        entry = root['myentry']
        self.assertTrue(isinstance(entry, ZODBEntry))

        # ZODB entry node of entry is looked up by db_name from db root
        self.assertTrue(isinstance(entry.storage, ZODBEntryNode))
        self.assertEqual(entry.storage.name, 'myentry')

        # ``metadata`` and ``properties`` are returned from entry
        self.assertTrue(isinstance(entry.storage.metadata, Metadata))
        self.assertTrue(isinstance(entry.storage.properties, Properties))

        # Create children
        foo = ZODBDummyNode()
        entry['foo'] = foo
        bar = ZODBDummyNode()
        bar.attrs['title'] = 'bar'
        entry['bar'] = bar

        # ``__iter__``
        self.assertEqual([k for k in entry], ['foo', 'bar'])

        # ``__getitem__``
        self.assertTrue(entry['foo'] is foo)

        # ``keys``
        self.assertEqual(foo.attrs.keys(), ['title', 'uuid'])

        # IZODBEntry and IZODBEntryNode
        self.assertTrue(IZODBEntry.providedBy(entry))
        self.assertTrue(IZODBEntryNode.providedBy(entry.storage))

        # ZODBDummyNode is UUIDAware
        self.assertTrue(IUUIDAware.providedBy(foo))
        self.assertTrue(isinstance(foo.uuid, uuid.UUID))

        # Entry and entry node result in the same tree
        self.check_output("""
        <class 'cone.zodb.entry.ZODBEntry'>: myentry
          <class 'cone.zodb.testing.ZODBDummyNode'>: foo
          <class 'cone.zodb.testing.ZODBDummyNode'>: bar
        """, entry.treerepr())

        self.check_output("""
        <class 'cone.zodb.entry.ZODBEntryNode'>: myentry
          <class 'cone.zodb.testing.ZODBDummyNode'>: foo
          <class 'cone.zodb.testing.ZODBDummyNode'>: bar
        """, entry.storage.treerepr())

        # ``__parent__``
        self.assertTrue(foo.parent is entry.storage)
        self.assertTrue(foo.parent.parent is root)

        # ``__delitem__``
        del entry['foo']
        self.check_output("""
        <class 'cone.zodb.entry.ZODBEntry'>: myentry
          <class 'cone.zodb.testing.ZODBDummyNode'>: bar
        """, entry.treerepr())

        # ``__call__`` delegates to storage, which is the ZODB entry node
        entry()

        # ``zodb_entry_for``
        self.assertTrue(zodb_entry_for(entry['bar']) is entry)
        self.assertTrue(zodb_entry_for(entry.storage) is entry)
        self.assertTrue(zodb_entry_for(root) is None)

        # DB name
        class CustomZODBEntry(ZODBEntry):
            @property
            def db_name(self):
                return 'custom_entry_storage'

            @property
            def name(self):
                return 'entry_storage'

        root['custom_entry_storage'] = CustomZODBEntry(name='custom_entry')
        entry = root['custom_entry_storage']
        self.assertEqual(entry.name, 'entry_storage')

        child = ZODBDummyNode()
        entry['child'] = child
        child = entry['child']
        self.assertEqual(child.path, ['root', 'entry_storage', 'child'])
        self.assertEqual(entry.db_name, 'custom_entry_storage')

        transaction.commit()