[Zodb-checkins] SVN: ZODB/branches/pycon-multidb/src/ZODB/tests/test - Ok. Fixed a failing test (StubDatabase) and checked in a doctest i forgot to add.

Christian Theune ct at gocept.com
Sat Mar 19 17:21:26 EST 2005


Log message for revision 29583:
   - Ok. Fixed a failing test (StubDatabase) and checked in a doctest i forgot to add.
  
  

Changed:
  U   ZODB/branches/pycon-multidb/src/ZODB/tests/testConnection.py
  A   ZODB/branches/pycon-multidb/src/ZODB/tests/testmultidb.py

-=-
Modified: ZODB/branches/pycon-multidb/src/ZODB/tests/testConnection.py
===================================================================
--- ZODB/branches/pycon-multidb/src/ZODB/tests/testConnection.py	2005-03-19 22:09:14 UTC (rev 29582)
+++ ZODB/branches/pycon-multidb/src/ZODB/tests/testConnection.py	2005-03-19 22:21:26 UTC (rev 29583)
@@ -647,6 +647,8 @@
         self._storage = StubStorage()
 
     classFactory = None
+    database_name = 'stubdatabase'
+    databases = {'stubdatabase': database_name}
 
     def invalidate(self, transaction, dict_with_oid_keys, connection):
         pass

Added: ZODB/branches/pycon-multidb/src/ZODB/tests/testmultidb.py
===================================================================
--- ZODB/branches/pycon-multidb/src/ZODB/tests/testmultidb.py	2005-03-19 22:09:14 UTC (rev 29582)
+++ ZODB/branches/pycon-multidb/src/ZODB/tests/testmultidb.py	2005-03-19 22:21:26 UTC (rev 29583)
@@ -0,0 +1,87 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+r"""
+Multi-database tests
+====================
+
+Multi-database support adds the ability to tie multiple database into a
+collection.
+
+Creating a multi-database starts with creating a named DB:
+
+>>> from ZODB.tests.test_storage import MinimalMemoryStorage
+>>> from ZODB import DB
+>>> db = DB(MinimalMemoryStorage(), database_name='root')
+
+The database name is accessible afterwards and in a newly created collection:
+
+>>> db.database_name
+'root'
+>>> db.databases        # doctest: +ELLIPSIS
+{'root': <ZODB.DB.DB object at ...>}
+
+Adding a new database works like this:
+
+>>> db2 = DB(MinimalMemoryStorage(), 
+...     database_name='notroot', 
+...     databases=db.databases)
+
+The new db2 now shares the 'databases' dictionary with db and has two entries:
+
+>>> db2.databases is db.databases
+True
+>>> len(db2.databases)
+2
+
+Trying to insert a database with a name that is already in use will not work:
+
+>>> db3 = DB(MinimalMemoryStorage(), 
+...     database_name='root', 
+...     databases=db.databases)
+Traceback (most recent call last):
+    ... fancy traceback here ...
+ValueError: database_name 'root' already in databases
+
+You can (still) get a connection to a database this way:
+
+>>> cn = db.open()
+>>> cn                  # doctest: +ELLIPSIS
+<Connection at ...>
+
+This is the only connection in this collection right now:
+
+>>> cn.connections      # doctest: +ELLIPSIS
+{'root': <Connection at ...>}
+
+Getting a connection to a different database from an existing connection in the
+same database collection (this enables 'connection binding' within a given
+thread/transaction/context ...):
+
+>>> cn2 = cn.get_connection('notroot')
+>>> cn2                  # doctest: +ELLIPSIS
+<Connection at ...>
+
+Now there are two connections in that collection:
+
+>>> cn2.connections is cn.connections
+True
+>>> len(cn2.connections)
+2
+
+"""
+
+from zope.testing import doctest
+
+def test_suite():
+    return doctest.DocTestSuite()



More information about the Zodb-checkins mailing list