[Checkins] SVN: zope.publisher/branches/3.13/ Backport r127219: Wrap ``with interaction()`` in try/finally.

Wolfgang Schnerring cvs-admin at zope.org
Mon Jul 2 12:16:37 UTC 2012


Log message for revision 127220:
  Backport r127219: Wrap ``with interaction()`` in try/finally.
  
  

Changed:
  U   zope.publisher/branches/3.13/CHANGES.txt
  U   zope.publisher/branches/3.13/src/zope/publisher/testing.py
  U   zope.publisher/branches/3.13/src/zope/publisher/tests/test_testing.py

-=-
Modified: zope.publisher/branches/3.13/CHANGES.txt
===================================================================
--- zope.publisher/branches/3.13/CHANGES.txt	2012-07-02 12:14:08 UTC (rev 127219)
+++ zope.publisher/branches/3.13/CHANGES.txt	2012-07-02 12:16:33 UTC (rev 127220)
@@ -1,6 +1,12 @@
 CHANGES
 =======
 
+3.13.1 (unreleased)
+-------------------
+
+- Wrap ``with interaction()`` in try/finally.
+
+
 3.13.0 (2011-11-17)
 -------------------
 

Modified: zope.publisher/branches/3.13/src/zope/publisher/testing.py
===================================================================
--- zope.publisher/branches/3.13/src/zope/publisher/testing.py	2012-07-02 12:14:08 UTC (rev 127219)
+++ zope.publisher/branches/3.13/src/zope/publisher/testing.py	2012-07-02 12:16:33 UTC (rev 127220)
@@ -36,6 +36,8 @@
         # There already is an interaction. Great. Leave it alone.
         yield
     else:
-        principal = create_interaction(principal_id)
-        yield principal
-        zope.security.management.endInteraction()
+        principal = create_interaction(principal_id, **kw)
+        try:
+            yield principal
+        finally:
+            zope.security.management.endInteraction()

Modified: zope.publisher/branches/3.13/src/zope/publisher/tests/test_testing.py
===================================================================
--- zope.publisher/branches/3.13/src/zope/publisher/tests/test_testing.py	2012-07-02 12:14:08 UTC (rev 127219)
+++ zope.publisher/branches/3.13/src/zope/publisher/tests/test_testing.py	2012-07-02 12:16:33 UTC (rev 127220)
@@ -20,6 +20,9 @@
 
 class InteractionHelperTest(unittest.TestCase):
 
+    def tearDown(self):
+        zope.security.management.endInteraction()
+
     def test_create_interaction_should_return_principal(self):
         principal = zope.publisher.testing.create_interaction(
             'foo', groups=['bar'], description='desc')
@@ -34,3 +37,12 @@
             interaction = zope.security.management.getInteraction()
             request = interaction.participations[0]
             self.assertEqual('foo', request.principal.id)
+        self.assertFalse(zope.security.management.queryInteraction())
+
+    def test_contextmanager_ends_interaction_on_exception(self):
+        try:
+            with zope.publisher.testing.interaction('foo'):
+                raise RuntimeError()
+        except RuntimeError:
+            pass
+        self.assertFalse(zope.security.management.queryInteraction())



More information about the checkins mailing list