[Checkins] SVN: z3ext.preferences/trunk/ tests updated
Nikolay Kim
fafhrd at datacom.kz
Thu Jan 8 21:45:53 EST 2009
Log message for revision 94666:
tests updated
Changed:
U z3ext.preferences/trunk/CHANGES.txt
U z3ext.preferences/trunk/setup.py
U z3ext.preferences/trunk/src/z3ext/preferences/browser/navigation.pt
A z3ext.preferences/trunk/src/z3ext/preferences/tests/configure.zcml
A z3ext.preferences/trunk/src/z3ext/preferences/tests/ftesting.zcml
A z3ext.preferences/trunk/src/z3ext/preferences/tests/interfaces.py
A z3ext.preferences/trunk/src/z3ext/preferences/tests/overrides.zcml
A z3ext.preferences/trunk/src/z3ext/preferences/tests/test.pt
A z3ext.preferences/trunk/src/z3ext/preferences/tests/testbrowser.txt
A z3ext.preferences/trunk/src/z3ext/preferences/tests/testlayout.pt
U z3ext.preferences/trunk/src/z3ext/preferences/tests/tests.py
U z3ext.preferences/trunk/src/z3ext/preferences/zcml.py
-=-
Modified: z3ext.preferences/trunk/CHANGES.txt
===================================================================
--- z3ext.preferences/trunk/CHANGES.txt 2009-01-08 21:24:27 UTC (rev 94665)
+++ z3ext.preferences/trunk/CHANGES.txt 2009-01-09 02:45:52 UTC (rev 94666)
@@ -2,9 +2,11 @@
CHANGES
=======
-1.4.5 (Unreleased)
+1.4.5 (2009-01-09)
------------------
+- Added 'accesspremission' attribute for preferenceGroup directive
+
- Fixed security for preference group
Modified: z3ext.preferences/trunk/setup.py
===================================================================
--- z3ext.preferences/trunk/setup.py 2009-01-08 21:24:27 UTC (rev 94665)
+++ z3ext.preferences/trunk/setup.py 2009-01-09 02:45:52 UTC (rev 94666)
@@ -76,13 +76,14 @@
'zope.app.principalannotation',
'z3c.traverser',
'z3c.autoinclude',
- 'z3ext.layout >= 1.5.1',
- 'z3ext.layoutform >= 1.2.3',
+ 'z3ext.layout',
+ 'z3ext.layoutform',
'z3ext.statusmessage',
'z3ext.resourcepackage',
],
extras_require = dict(test=['zope.app.testing',
'zope.testing',
+ 'zope.testbrowser',
]),
include_package_data = True,
zip_safe = False
Modified: z3ext.preferences/trunk/src/z3ext/preferences/browser/navigation.pt
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/browser/navigation.pt 2009-01-08 21:24:27 UTC (rev 94665)
+++ z3ext.preferences/trunk/src/z3ext/preferences/browser/navigation.pt 2009-01-09 02:45:52 UTC (rev 94666)
@@ -12,7 +12,7 @@
<a tal:attributes="href string:${item/prefs/@@absolute_url}/;
title item/description"
tal:omit-tag="not:item/editable">
- <al:block tal:content="structure item/icon" />
+ <tal:block tal:content="structure item/icon" />
<tal:block tal:content="item/title" />
</a>
</div>
Added: z3ext.preferences/trunk/src/z3ext/preferences/tests/configure.zcml
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/tests/configure.zcml (rev 0)
+++ z3ext.preferences/trunk/src/z3ext/preferences/tests/configure.zcml 2009-01-09 02:45:52 UTC (rev 94666)
@@ -0,0 +1,49 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:z3ext="http://namespaces.zope.org/z3ext"
+ i18n_domain="zope">
+
+ <interface
+ name="DefaultSkin"
+ interface=".tests.IDefaultSkin"
+ type="zope.publisher.interfaces.browser.IBrowserSkinType" />
+
+ <z3ext:pagelet
+ name="test.html"
+ for="*"
+ template="test.pt"
+ permission="zope.Public" />
+
+ <z3ext:preferenceGroup
+ id="category"
+ schema=".interfaces.ICategory"
+ title="Category"
+ accesspermission="zope.Public"
+ provides="z3ext.preferences.interfaces.IPreferenceCategory" />
+
+ <z3ext:preferenceGroup
+ id="category.prefs1"
+ schema=".interfaces.IPrefs1"
+ title="Preferences 1"
+ accesspermission="zope.Public" />
+
+ <z3ext:preferenceGroup
+ id="category.prefs2"
+ schema=".interfaces.IPrefs2"
+ title="Preferences 2"
+ accesspermission="zope.Public" />
+
+ <z3ext:preferenceGroup
+ id="category.prefs3"
+ schema=".interfaces.IPrefs3"
+ title="Preferences 3"
+ accesspermission="zope.Public"
+ tests="z3ext.preferences.tests.tests.notAvailable" />
+
+ <z3ext:preferenceGroup
+ id="portal.prefs4"
+ schema=".interfaces.IPrefs4"
+ title="Preferences 4"
+ accesspermission="zope.Public" />
+
+</configure>
Added: z3ext.preferences/trunk/src/z3ext/preferences/tests/ftesting.zcml
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/tests/ftesting.zcml (rev 0)
+++ z3ext.preferences/trunk/src/z3ext/preferences/tests/ftesting.zcml 2009-01-09 02:45:52 UTC (rev 94666)
@@ -0,0 +1,68 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:z3ext="http://namespaces.zope.org/z3ext"
+ xmlns:browser="http://namespaces.zope.org/browser"
+ i18n_domain="zope">
+
+ <!-- This file is the equivalent of site.zcml and it is -->
+ <!-- used for functional testing setup -->
+
+ <include package="zope.component" file="meta.zcml" />
+ <include package="zope.securitypolicy" file="meta.zcml" />
+ <include package="zope.viewlet" file="meta.zcml" />
+ <include package="zope.app.component" file="meta.zcml" />
+ <include package="zope.app.security" file="meta.zcml" />
+ <include package="zope.app.pagetemplate" file="meta.zcml" />
+
+ <include package="zope.securitypolicy" />
+ <include package="zope.contentprovider" />
+ <include package="zope.app.security" />
+ <include package="zope.app.zcmlfiles" />
+ <include package="zope.app.authentication" />
+
+ <include package="z3c.autoinclude" file="meta.zcml" />
+ <include package="z3ext.preferences" file="meta.zcml" />
+ <include package="z3ext.preferences" />
+ <include package="z3ext.preferences.tests" />
+ <includeOverrides package="z3ext.preferences.tests" file="overrides.zcml" />
+
+ <browser:defaultSkin name="DefaultSkin" />
+
+ <securityPolicy
+ component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
+
+ <role id="zope.Anonymous" title="Everybody" />
+ <role id="zope.Manager" title="Site Manager" />
+
+ <!-- Replace the following directive if you don't want public access -->
+ <grant permission="zope.View" role="zope.Anonymous" />
+
+ <!-- Principals -->
+ <unauthenticatedPrincipal
+ id="zope.anybody"
+ title="Unauthenticated User" />
+
+ <!-- Principal that tests generally run as -->
+ <principal
+ id="zope.mgr"
+ title="Manager"
+ login="mgr"
+ password="mgrpw" />
+
+ <principal
+ id="zope.user"
+ title="User"
+ login="user"
+ password="userpw" />
+
+ <principal
+ id="zope.user2"
+ title="User2"
+ login="user2"
+ password="userpw" />
+
+ <grant role="zope.Manager" principal="zope.mgr" />
+
+ <grantAll role="zope.Manager" />
+
+</configure>
Added: z3ext.preferences/trunk/src/z3ext/preferences/tests/interfaces.py
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/tests/interfaces.py (rev 0)
+++ z3ext.preferences/trunk/src/z3ext/preferences/tests/interfaces.py 2009-01-09 02:45:52 UTC (rev 94666)
@@ -0,0 +1,56 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id: 2007-12-12 12:27:02Z fafhrd $
+"""
+from zope import interface, schema
+
+
+class ICategory(interface.Interface):
+
+ category = schema.TextLine(
+ title = u'Category',
+ required = False)
+
+
+class IPrefs1(interface.Interface):
+
+ name = schema.TextLine(
+ title = u'Name',
+ required = True)
+
+
+class IPrefs2(interface.Interface):
+
+ location = schema.TextLine(
+ title = u'Location',
+ default = u'',
+ required = False)
+
+
+class IPrefs3(interface.Interface):
+
+ location = schema.TextLine(
+ title = u'Location',
+ default = u'',
+ required = False)
+
+
+class IPrefs4(interface.Interface):
+
+ prefs4 = schema.TextLine(
+ title = u'Prefs4',
+ default = u'',
+ required = False)
Added: z3ext.preferences/trunk/src/z3ext/preferences/tests/overrides.zcml
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/tests/overrides.zcml (rev 0)
+++ z3ext.preferences/trunk/src/z3ext/preferences/tests/overrides.zcml 2009-01-09 02:45:52 UTC (rev 94666)
@@ -0,0 +1,12 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:z3ext="http://namespaces.zope.org/z3ext"
+ i18n_domain="zope">
+
+ <z3ext:layout
+ name="portal"
+ title="Test layout"
+ for="zope.app.component.interfaces.ISite"
+ template="testlayout.pt" />
+
+</configure>
Added: z3ext.preferences/trunk/src/z3ext/preferences/tests/test.pt
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/tests/test.pt (rev 0)
+++ z3ext.preferences/trunk/src/z3ext/preferences/tests/test.pt 2009-01-09 02:45:52 UTC (rev 94666)
@@ -0,0 +1,3 @@
+
+<div tal:content="request/principal/id"></div>
+<div tal:content="request/principal/title"></div>
Added: z3ext.preferences/trunk/src/z3ext/preferences/tests/testbrowser.txt
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/tests/testbrowser.txt (rev 0)
+++ z3ext.preferences/trunk/src/z3ext/preferences/tests/testbrowser.txt 2009-01-09 02:45:52 UTC (rev 94666)
@@ -0,0 +1,178 @@
+====================
+Personal preferences
+====================
+
+ >>> from zope import component, interface, event
+ >>> from zope.app.component.hooks import setSite
+ >>> from zope.security.management import newInteraction, endInteraction
+ >>> from zope.app.security.interfaces import IAuthentication
+ >>> from zope.securitypolicy.interfaces import IPrincipalRoleMap
+ >>> from z3ext.preferences.tests.interfaces import IPrefs1
+
+ >>> root = getRootFolder()
+ >>> setSite(root)
+ >>> auth = component.getUtility(IAuthentication)
+ >>> principal = auth.getPrincipal('zope.user')
+
+ >>> class Participation:
+ ... interaction = None
+ ... def __init__(self, principal):
+ ... self.principal = principal
+
+ >>> newInteraction(Participation(principal))
+
+ >>> prefs = IPrefs1(principal)
+
+ >>> roles = IPrincipalRoleMap(prefs)
+ >>> roles.getPrincipalsForRole('preference.Owner')
+ (('zope.user', PermissionSetting: Allow),)
+ >>> roles.getPrincipalsForRole('content.Owner')
+ ()
+
+ >>> roles.getRolesForPrincipal('zope.user')
+ (('preference.Owner', PermissionSetting: Allow),)
+ >>> roles.getRolesForPrincipal('zope.manager')
+ ()
+
+ >>> roles.getSetting('preference.Owner', 'zope.user')
+ PermissionSetting: Allow
+
+ >>> roles.getSetting('content.Owner', 'zope.manager')
+ PermissionSetting: Unset
+
+ >>> roles.getPrincipalsAndRoles()
+ ()
+
+ >>> from z3ext.preferences.utils import hasEditableFields
+ >>> hasEditableFields(prefs)
+ True
+
+ >>> endInteraction()
+
+Browser
+
+ >>> from zope.testbrowser.testing import Browser
+
+ >>> user = Browser()
+ >>> user.handleErrors = False
+ >>> user.open("http://localhost/preferences/")
+ Traceback (most recent call last):
+ ...
+ Unauthorized: preferences
+
+ >>> user.addHeader("Authorization", "Basic user:userpw")
+
+ >>> user.open("http://localhost/preferences/")
+ >>> print user.contents
+ <html>
+ ...
+ <h1 class="z-prefs-title">Personal preferences</h1>
+ <div class="z-page-description">This area allows you to change personal preferences.</div>
+ <div class="z-prefs-content"><div class="z-form">
+ <ul class="z-listing">
+ <li>
+ <div class="z-listing-details">
+ <a href="category/">
+ Category</a>
+ <div> </div>
+ <ul class="z-listing">
+ <li>
+ <div class="z-listing-details">
+ <a href="category/prefs1/">
+ Preferences 1</a>
+ <div>
+ </div>
+ </div>
+ </li>
+ <li>
+ <div class="z-listing-details">
+ <a href="category/prefs2/">
+ Preferences 2</a>
+ <div>
+ </div>
+ </div>
+ </li>
+ </ul>
+ </div>
+ </li>
+ <li>
+ <div class="z-listing-details">
+ <a href="portal/">
+ Portal preferences</a>
+ <div>These are all the preferences related to common portal settings. </div>
+ </div>
+ </li>
+ </ul>
+ ...
+ </html>
+
+ >>> user.open("http://localhost/preferences/category/")
+ >>> print user.contents
+ <html>
+ ...
+ <div class="z-prefs-nav">
+ <div class="z-prefs-nav-item-selected">
+ <div class="z-level1">
+ <a href="http://localhost/preferences/category/" title="">
+ Category
+ </a>
+ </div>
+ </div>
+ <div class="z-prefs-nav-item">
+ <div class="z-level1">
+ <a href="http://localhost/preferences/portal/"
+ title="These are all the preferences related to common portal settings.">
+ Portal preferences
+ </a>
+ </div>
+ </div>
+ </div>
+ ...
+ ...<h1 class="z-prefs-title">Category</h1>
+ <div class="z-page-description"></div>
+ <div class="z-prefs-content"><div class="z-form z-form-edit"><form action="http://localhost/preferences/category/index.html"
+ method="post" enctype="multipart/form-data"
+ name="category" id="category">
+ <h1 class="z-form-label">Category</h1>
+ <div class="z-form-fieldset">
+ <div class="z-form-field">
+ <label for="category-widgets-category" title="">Category</label>
+ <div class="z-form-help"></div>
+ <div><input type="text" id="category-widgets-category"
+ name="category.widgets.category"
+ class="text-widget textline-field" value="" />
+ </div>
+ </div>
+ </div>
+ <div class="z-form-controls">
+ <span>
+ <hr />
+ <input type="submit" id="category-buttons-save"
+ name="category.buttons.save"
+ class="z-form-savebutton button-field" value="Save" />
+ </span>
+ </div>
+ </form>
+ </div>
+ <div class="z-form">
+ <h2><a href="http://localhost/preferences/category/prefs1/">Preferences 1</a></h2>
+ <div class="discreet"></div>
+ <br />
+ <h2><a href="http://localhost/preferences/category/prefs2/">Preferences 2</a></h2>
+ <div class="discreet"></div>
+ <br />
+ </div>
+ </div>
+ ...
+ </html>
+
+ >>> user.getLink('Preferences 1').click()
+ >>> user.getControl('Name').value = 'Nikolay'
+ >>> user.getControl(name="category.prefs1.buttons.save").click()
+ >>> 'Data successfully updated.' in user.contents
+ True
+
+ >>> user.open("http://localhost/preferences/category/unknown/")
+ Traceback (most recent call last):
+ ...
+ NotFound: Object: ... name: u'unknown'
Added: z3ext.preferences/trunk/src/z3ext/preferences/tests/testlayout.pt
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/tests/testlayout.pt (rev 0)
+++ z3ext.preferences/trunk/src/z3ext/preferences/tests/testlayout.pt 2009-01-09 02:45:52 UTC (rev 94666)
@@ -0,0 +1,7 @@
+<html>
+ <body>
+ <div tal:content="structure provider:statusMessage"></div>
+
+ <div tal:content="structure view/render"></div>
+ </body>
+</html>
Modified: z3ext.preferences/trunk/src/z3ext/preferences/tests/tests.py
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/tests/tests.py 2009-01-08 21:24:27 UTC (rev 94665)
+++ z3ext.preferences/trunk/src/z3ext/preferences/tests/tests.py 2009-01-09 02:45:52 UTC (rev 94666)
@@ -15,11 +15,64 @@
$Id$
"""
-import unittest, doctest
+import os.path, unittest, doctest
+
+from zope.component import testing
from zope.testing import doctestunit
-from zope.component import testing
-from zope.app.testing import setup
+from zope.app.testing import setup, functional
+from zope.app.rotterdam import Rotterdam
+from zope.app.principalannotation import PrincipalAnnotationUtility
+from zope.app.principalannotation.interfaces import IPrincipalAnnotationUtility
+from z3ext.layoutform.interfaces import ILayoutFormLayer
+
+
+class IDefaultSkin(ILayoutFormLayer, Rotterdam):
+ """ skin """
+
+
+z3extPreferences = functional.ZCMLLayer(
+ os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
+ __name__, 'z3extPreferences', allow_teardown=True)
+
+
+def FunctionalDocFileSuite(*paths, **kw):
+ globs = kw.setdefault('globs', {})
+ globs['sync'] = functional.sync
+ globs['http'] = functional.HTTPCaller()
+ globs['getRootFolder'] = functional.getRootFolder
+
+ kw['package'] = doctest._normalize_module(kw.get('package'))
+
+ kwsetUp = kw.get('setUp')
+ def setUp(test):
+ functional.FunctionalTestSetup().setUp()
+
+ root = functional.getRootFolder()
+ root['principalannotation'] = PrincipalAnnotationUtility()
+ root.getSiteManager().registerUtility(
+ root['principalannotation'], IPrincipalAnnotationUtility)
+
+ kw['setUp'] = setUp
+
+ kwtearDown = kw.get('tearDown')
+ def tearDown(test):
+ functional.FunctionalTestSetup().tearDown()
+
+ kw['tearDown'] = tearDown
+
+ if 'optionflags' not in kw:
+ old = doctest.set_unittest_reportflags(0)
+ doctest.set_unittest_reportflags(old)
+ kw['optionflags'] = (old
+ | doctest.ELLIPSIS
+ | doctest.NORMALIZE_WHITESPACE)
+
+ suite = doctest.DocFileSuite(*paths, **kw)
+ suite.layer = z3extPreferences
+ return suite
+
+
def setUp(test):
testing.setUp(test)
setup.setUpTestAsModule(test, 'z3ext.preferences.README')
@@ -28,17 +81,23 @@
testing.tearDown(test)
setup.tearDownTestAsModule(test)
+def notAvailable(*args):
+ return None
+
def test_suite():
+ testbrowser = FunctionalDocFileSuite("testbrowser.txt")
+
return unittest.TestSuite((
- doctest.DocFileSuite(
- '../README.txt',
- setUp=setUp, tearDown=tearDown,
- globs={'pprint': doctestunit.pprint},
- optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
- doctest.DocTestSuite(
- '../z3ext.preferences.utils',
- optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
- doctest.DocTestSuite(
- '../z3ext.preferences.preferencetype',
- optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
- ))
+ testbrowser,
+ doctest.DocFileSuite(
+ '../README.txt',
+ setUp=setUp, tearDown=tearDown,
+ globs={'pprint': doctestunit.pprint},
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
+ doctest.DocTestSuite(
+ 'z3ext.preferences.utils',
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
+ doctest.DocTestSuite(
+ 'z3ext.preferences.preferencetype',
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
+ ))
Modified: z3ext.preferences/trunk/src/z3ext/preferences/zcml.py
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/zcml.py 2009-01-08 21:24:27 UTC (rev 94665)
+++ z3ext.preferences/trunk/src/z3ext/preferences/zcml.py 2009-01-09 02:45:52 UTC (rev 94666)
@@ -119,8 +119,8 @@
def __init__(self, _context, id, schema, title,
for_=None, description=u'', class_=None, provides=[],
- permission='z3ext.ModifyPreference', accesspermission='',
- tests=(), order = 9999):
+ permission='z3ext.ModifyPreference',
+ accesspermission='z3ext.ModifyPreference', tests=(), order = 9999):
if not accesspermission:
accesspermission = permission
More information about the Checkins
mailing list