[Zope-Checkins] SVN: Products.Five/branches/1.4/browser/tests/ Add
an ftest that demonstrates
zope.security.management.checkPermission() works in Zope 2.
Philipp von Weitershausen
philikon at philikon.de
Mon Jan 8 10:27:42 EST 2007
Log message for revision 71811:
Add an ftest that demonstrates zope.security.management.checkPermission() works in Zope 2.
This is the reproduceability test case for http://www.zope.org/Collectors/Zope/2190.
Changed:
A Products.Five/branches/1.4/browser/tests/test_zope3security.py
A Products.Five/branches/1.4/browser/tests/zope3security.py
-=-
Added: Products.Five/branches/1.4/browser/tests/test_zope3security.py
===================================================================
--- Products.Five/branches/1.4/browser/tests/test_zope3security.py 2007-01-08 15:26:52 UTC (rev 71810)
+++ Products.Five/branches/1.4/browser/tests/test_zope3security.py 2007-01-08 15:27:41 UTC (rev 71811)
@@ -0,0 +1,60 @@
+import os, sys
+if __name__ == '__main__':
+ execfile(os.path.join(sys.path[0], 'framework.py'))
+
+def test_check_permission():
+ """Code (in Zope 3) often uses
+ zope.security.management.checkPermission to determine whether the
+ current user has a certain permission in a given context. Five
+ inserts its own interaction that assures that such calls still
+ work.
+
+ >>> configure_zcml = '''
+ ... <configure
+ ... xmlns="http://namespaces.zope.org/zope"
+ ... xmlns:browser="http://namespaces.zope.org/browser">
+ ... <configure package="Products.Five.browser.tests">
+ ... <browser:page
+ ... for="OFS.interfaces.IFolder"
+ ... class=".zope3security.Zope3SecurityView"
+ ... name="zope3security.html"
+ ... permission="zope2.View"
+ ... />
+ ... </configure>
+ ... </configure>'''
+
+ >>> import Products.Five
+ >>> from Products.Five import zcml
+ >>> zcml.load_config("configure.zcml", Products.Five)
+ >>> zcml.load_string(configure_zcml)
+
+ In order to be able to traverse to the PageTemplate view, we need
+ a traversable object:
+
+ >>> from Products.Five.tests.testing import manage_addFiveTraversableFolder
+ >>> manage_addFiveTraversableFolder(self.folder, 'testoid', 'Testoid')
+
+ Now we access a page that uses
+ zope.security.management.checkPermission(). We see it works as
+ expected:
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.open('http://localhost/test_folder_1_/testoid/@@zope3security.html')
+ >>> print browser.contents
+ Yes, you have the zope2.View permission.
+
+ Clean up:
+
+ >>> from zope.app.testing.placelesssetup import tearDown
+ >>> tearDown()
+
+ """
+
+def test_suite():
+ from Testing.ZopeTestCase import FunctionalDocTestSuite
+ from zope.testing.doctest import ELLIPSIS
+ return FunctionalDocTestSuite(optionflags=ELLIPSIS)
+
+if __name__ == '__main__':
+ framework()
Property changes on: Products.Five/branches/1.4/browser/tests/test_zope3security.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Products.Five/branches/1.4/browser/tests/zope3security.py
===================================================================
--- Products.Five/branches/1.4/browser/tests/zope3security.py 2007-01-08 15:26:52 UTC (rev 71810)
+++ Products.Five/branches/1.4/browser/tests/zope3security.py 2007-01-08 15:27:41 UTC (rev 71811)
@@ -0,0 +1,10 @@
+from Products.Five import BrowserView
+from zope.security.management import checkPermission
+
+class Zope3SecurityView(BrowserView):
+
+ def __call__(self):
+ if checkPermission('zope2.View', self.context):
+ return "Yes, you have the zope2.View permission."
+ else:
+ return "No, you don't have the zope2.View permission."
Property changes on: Products.Five/branches/1.4/browser/tests/zope3security.py
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Zope-Checkins
mailing list