[Checkins] SVN: z3c.zalchemy/branches/ctheune-automatic-session/ Fixed the last failing test by making the ZCML directive code use

Christian Theune ct at gocept.com
Thu Jun 28 02:01:13 EDT 2007


Log message for revision 77164:
  Fixed the last failing test by making the ZCML directive code use
  configuration actions properly.
  --This line, and those below, will be ignored--
  
  M    CHANGES.txt
  M    src/z3c/zalchemy/metaconfigure.py
  M    src/z3c/zalchemy/datamanager.py
  M    src/z3c/zalchemy/tests/test_zalchemy.py
  M    src/z3c/zalchemy/tests/test_directives.py
  

Changed:
  U   z3c.zalchemy/branches/ctheune-automatic-session/CHANGES.txt
  U   z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/datamanager.py
  U   z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/metaconfigure.py
  U   z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/tests/test_directives.py
  U   z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/tests/test_zalchemy.py

-=-
Modified: z3c.zalchemy/branches/ctheune-automatic-session/CHANGES.txt
===================================================================
--- z3c.zalchemy/branches/ctheune-automatic-session/CHANGES.txt	2007-06-28 05:31:10 UTC (rev 77163)
+++ z3c.zalchemy/branches/ctheune-automatic-session/CHANGES.txt	2007-06-28 06:01:13 UTC (rev 77164)
@@ -10,6 +10,11 @@
     SessionContext object which hands out a session for each thread. Your code
     rarely should never have to call `session.save(object)` now.
 
+    One incompatible change was introduced: You can not call `getSession`
+    before registering an (unnamed) engine utility first. Doing so will raise
+    a ValueError.
+
+
 0.1.1 - 2007-06-27
 ==================
 

Modified: z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/datamanager.py
===================================================================
--- z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/datamanager.py	2007-06-28 05:31:10 UTC (rev 77163)
+++ z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/datamanager.py	2007-06-28 06:01:13 UTC (rev 77164)
@@ -126,14 +126,28 @@
     return True
 
 
-def assignTable(table, engine):
+def assignTable(table, engine, immediate=True):
+    """Assign a table to an engine and propagate the binding to the current
+    session.
+
+    The binding is not applied to the current session if `immediate` is False.
+
+    """
     _tableToEngine[table]=engine
-    _assignTable(table, engine)
+    if immediate:
+        _assignTable(table, engine)
 
 
-def assignClass(class_, engine):
+def assignClass(class_, engine, immediate=True):
+    """Assign a class to an engine and propagate the binding to the current
+    session.
+
+    The binding is not applied to the current session if `immediate` is False.
+
+    """
     _classToEngine[class_]=engine
-    _assignClass(class_, engine)
+    if immediate:
+        _assignClass(class_, engine)
 
 
 def createTable(table, engine):
@@ -145,7 +159,7 @@
     t = metadata.getTable(engine, table, True)
     util = getUtility(IAlchemyEngineUtility, name=engine)
     if session is None:
-        session = ctx.current
+            session = ctx.current
     session.bind_table(t, util.getEngine())
 
 

Modified: z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/metaconfigure.py
===================================================================
--- z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/metaconfigure.py	2007-06-28 05:31:10 UTC (rev 77163)
+++ z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/metaconfigure.py	2007-06-28 06:01:13 UTC (rev 77164)
@@ -19,6 +19,7 @@
 
 import z3c.zalchemy
 
+
 def engine(_context, url, name='', echo=False, **kwargs):
     engine = AlchemyEngineUtility(name, url, echo=echo, **kwargs)
     utility(_context,
@@ -27,12 +28,26 @@
             permission=PublicPermission,
             name=name)
 
+
 def connectTable(_context, table, engine):
-    z3c.zalchemy.assignTable(table, engine)
+    _context.action(
+        discriminator=('zalchemy.table', table),
+        callable=z3c.zalchemy.assignTable,
+        args=(table, engine, False)
+    )
 
+
 def connectClass(_context, class_, engine):
-    z3c.zalchemy.assignClass(class_, engine)
+    _context.action(
+        discriminator=('zalchemy.class', class_),
+        callable=z3c.zalchemy.assignClass,
+        args=(class_, engine, False)
+    )
 
+
 def createTable(_context, table, engine):
-    z3c.zalchemy.createTable(table, engine)
-
+    _context.action(
+        discriminator=('zalchemy.create-table', table),
+        callable=z3c.zalchemy.createTable,
+        args=(table, engine)
+    )

Modified: z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/tests/test_directives.py
===================================================================
--- z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/tests/test_directives.py	2007-06-28 05:31:10 UTC (rev 77163)
+++ z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/tests/test_directives.py	2007-06-28 06:01:13 UTC (rev 77164)
@@ -85,7 +85,7 @@
                 />
             '''
             )))
-        util = component.getUtility(IAlchemyEngineUtility,'sqlite-in-memory')
+        util = component.getUtility(IAlchemyEngineUtility, 'sqlite-in-memory')
         self.assert_(len(z3c.zalchemy.datamanager._tableToEngine)==1)
         self.assert_('testTable' in z3c.zalchemy.datamanager._tableToEngine)
         self.assert_(mappedTestClass in z3c.zalchemy.datamanager._classToEngine)

Modified: z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/tests/test_zalchemy.py
===================================================================
--- z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/tests/test_zalchemy.py	2007-06-28 05:31:10 UTC (rev 77163)
+++ z3c.zalchemy/branches/ctheune-automatic-session/src/z3c/zalchemy/tests/test_zalchemy.py	2007-06-28 06:01:13 UTC (rev 77164)
@@ -56,9 +56,9 @@
         z3c.zalchemy.testing.tearDown(self)
 
     def testNoDefaultEngine(self):
-        session = z3c.zalchemy.getSession()
-        self.assertNotEqual(session, None)
-        self.assertEqual(session.get_bind(None), None)
+        # Our session can't work without an engine. If we did not 
+        # register an IAlchemyEngineUtility, we can't access the session
+        self.assertRaises(ValueError, z3c.zalchemy.getSession)
 
     def testDefaultEngine(self):
         from zope.component import provideUtility



More information about the Checkins mailing list