[Zope3-checkins] CVS: Zope3/src/zope/security/tests - test_simpleinteraction.py:1.1.2.2

Marius Gedminas marius at pov.lt
Fri Mar 19 13:51:28 EST 2004


Update of /cvs-repository/Zope3/src/zope/security/tests
In directory cvs.zope.org:/tmp/cvs-serv26650/src/zope/security/tests

Modified Files:
      Tag: mgedmin-events2-branch
	test_simpleinteraction.py 
Log Message:
Added IParticipation and replaced the lists of principals in IInteraction with
a list of participations.  Made BaseRequest an IParticipation and replaced
request.user with request.principal everywhere.



=== Zope3/src/zope/security/tests/test_simpleinteraction.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/security/tests/test_simpleinteraction.py:1.1.2.1	Mon Mar  8 13:43:45 2004
+++ Zope3/src/zope/security/tests/test_simpleinteraction.py	Fri Mar 19 13:50:57 2004
@@ -19,8 +19,10 @@
 
 
 class RequestStub:
-    def __init__(self, user):
-        self.user = user
+
+    def __init__(self, principal=None):
+        self.principal = principal
+        self.interaction = None
 
 
 class TestInteraction(unittest.TestCase):
@@ -31,17 +33,45 @@
         interaction = Interaction()
         verifyObject(IInteraction, interaction)
 
+    def test_add(self):
+        from zope.security.simpleinteraction import Interaction
+        rq = RequestStub()
+        interaction = Interaction()
+        interaction.add(rq)
+        self.assert_(rq in interaction.participations)
+        self.assert_(rq.interaction is interaction)
+
+        # rq already added
+        self.assertRaises(ValueError, interaction.add, rq)
+
+        interaction2 = Interaction()
+        self.assertRaises(ValueError, interaction2.add, rq)
+
+    def test_remove(self):
+        from zope.security.simpleinteraction import Interaction
+        rq = RequestStub()
+        interaction = Interaction()
+
+        self.assertRaises(ValueError, interaction.remove, rq)
+
+        interaction.add(rq)
+
+        interaction.remove(rq)
+        self.assert_(rq not in interaction.participations)
+        self.assert_(rq.interaction is None)
+
     def testCreateInteraction(self):
         from zope.security.interfaces import IInteraction
         from zope.security.simpleinteraction import createInteraction
-        i1 = createInteraction(None)
+        i1 = createInteraction()
         verifyObject(IInteraction, i1)
-        self.assertEquals(list(i1.principals), [])
+        self.assertEquals(list(i1.participations), [])
 
         user = object()
-        i2 = createInteraction(RequestStub(user))
+        request = RequestStub(user)
+        i2 = createInteraction(request)
         verifyObject(IInteraction, i2)
-        self.assertEquals(list(i2.principals), [user])
+        self.assertEquals(list(i2.participations), [request])
 
 
 def test_suite():




More information about the Zope3-Checkins mailing list