[Zope3-checkins] CVS: Zope3/src/zope/security/tests - test_management.py:1.2.58.2

Marius Gedminas marius at pov.lt
Mon Mar 8 16:50:59 EST 2004


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

Modified Files:
      Tag: mgedmin-events2-branch
	test_management.py 
Log Message:
Added a checkPermission method to zope.security.



=== Zope3/src/zope/security/tests/test_management.py 1.2.58.1 => 1.2.58.2 ===
--- Zope3/src/zope/security/tests/test_management.py:1.2.58.1	Mon Mar  8 13:43:45 2004
+++ Zope3/src/zope/security/tests/test_management.py	Mon Mar  8 16:50:58 2004
@@ -21,6 +21,8 @@
 from zope.interface.verify import verifyObject
 from zope.testing.cleanup import CleanUp
 
+__metaclass__ = type
+
 
 class TestSecurityManagement(CleanUp, unittest.TestCase):
 
@@ -84,6 +86,34 @@
         self.assert_(thread.__zope3_thread_globals__.interaction is None)
 
         self.assertRaises(AssertionError, endInteraction, _thread=thread)
+
+    def test_checkPermission(self):
+        from zope.security import checkPermission
+        from zope.security.management import setSecurityPolicy
+        from zope.security.management import getInteraction
+        from zope.security.management import newInteraction
+
+        permission = 'zope.Test'
+        obj = object()
+        interaction = object()
+
+        class InteractionStub:
+            pass
+
+        class PolicyStub:
+            def createInteraction(s, r):
+                return InteractionStub()
+
+            def checkPermission(s, p, o, i):
+                self.assert_(p is permission)
+                self.assert_(o is obj)
+                self.assert_(i is getInteraction() or i is interaction)
+                return i is interaction
+
+        setSecurityPolicy(PolicyStub())
+        newInteraction(None)
+        self.assertEquals(checkPermission(permission, obj), False)
+        self.assertEquals(checkPermission(permission, obj, interaction), True)
 
 
 def test_suite():




More information about the Zope3-Checkins mailing list