Re: [Zope-dev] SVN: Zope/trunk/ Let the <permission /> directive auto-register permissions that don't exist already
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Martin Aspeli wrote:
Log message for revision 99146: Let the <permission /> directive auto-register permissions that don't exist already
This kind of test is a "poster child" for why doctests with lots of output are fragile: even though it uses pprint, it *still* fails on different Python versions (i.e., it is breaking on Python 2.4). This test needs to be rewritten either as a traditional unittest (my preference), or the assertions about the state need to be rewritten in "fine grained" form.
+def test_register_permission(): + """This test demonstrates that if the <permission /> directive is used + to create a permission that does not already exist, it is created on + startup, with roles defaulting to Manager. + + >>> from zope.app.testing.placelesssetup import setUp, tearDown + >>> setUp() + + First, we need to configure the relevant parts of Five. + + >>> import Products.Five + >>> from Products.Five import zcml + >>> zcml.load_config('meta.zcml', Products.Five) + >>> zcml.load_config('permissions.zcml', Products.Five) + + We can now register a permission in ZCML: + + >>> configure_zcml = ''' + ... <configure xmlns="http://namespaces.zope.org/zope"> + ... + ... <permission + ... id="Products.Five.tests.DummyPermission" + ... title="Five: Dummy permission" + ... /> + ... + ... </configure> + ... ''' + >>> zcml.load_string(configure_zcml) + + The permission will be made available globally, with default role set + of ('Manager',). + + >>> from pprint import pprint + >>> pprint(self.app.rolesOfPermission('Five: Dummy permission')) + [{'name': 'Anonymous', 'selected': ''}, + {'name': 'Authenticated', 'selected': ''}, + {'name': 'Manager', 'selected': 'SELECTED'}, + {'name': 'Owner', 'selected': ''}] + + Let's also ensure that permissions are not overwritten if they exist + already: + + >>> from AccessControl.Permission import _registeredPermissions + >>> import Products + >>> _registeredPermissions['Five: Other dummy'] = 1 + >>> Products.__ac_permissions__ += (('Five: Other dummy', (), (),),) + >>> self.app.manage_permission('Five: Other dummy', roles=['Anonymous']) + + >>> configure_zcml = ''' + ... <configure xmlns="http://namespaces.zope.org/zope"> + ... + ... <permission + ... id="Products.Five.tests.OtherDummy" + ... title="Five: Other dummy" + ... /> + ... + ... </configure> + ... ''' + >>> zcml.load_string(configure_zcml) + + >>> from pprint import pprint + >>> pprint(self.app.rolesOfPermission('Five: Other dummy')) + [{'name': 'Anonymous', 'selected': 'SELECTED'}, + {'name': 'Authenticated', 'selected': ''}, + {'name': 'Manager', 'selected': ''}, + {'name': 'Owner', 'selected': ''}] + + >>> tearDown() + """ + def test_suite(): from Testing.ZopeTestCase import ZopeDocTestSuite return ZopeDocTestSuite()
Tres. - -- =================================================================== Tres Seaver +1 540-429-0999 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFJ5fc7+gerLs4ltQ4RAsPyAJ4jmnMes8zQ4z3Kwu41YPYJkJWCqgCeNwOj Afe708/o+B4wQjzz4j/w2Xw= =Qvq/ -----END PGP SIGNATURE-----
Tres Seaver wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Martin Aspeli wrote:
Log message for revision 99146: Let the <permission /> directive auto-register permissions that don't exist already
This kind of test is a "poster child" for why doctests with lots of output are fragile: even though it uses pprint, it *still* fails on different Python versions (i.e., it is breaking on Python 2.4).
Sigh... sorry. I didn't even realise Zope 2.12 was meant to run with Python 2.4. I thought it was 2.5/2.6 only. Guess I was wrong.
This test needs to be rewritten either as a traditional unittest (my preference), or the assertions about the state need to be rewritten in "fine grained" form.
I just copied the tests that were already there, so I'd prefer to keep them in the same place. Can you show me the failure you get? Martin -- Author of `Professional Plone Development`, a book for developers who want to work with Plone. See http://martinaspeli.net/plone-book
On Wed, Apr 15, 2009 at 17:09, Martin Aspeli <optilude+lists@gmail.com> wrote:
I didn't even realise Zope 2.12 was meant to run with Python 2.4. I thought it was 2.5/2.6 only. Guess I was wrong.
I thought the same, and I'm sure at least Jim said that 2.4 support is dropped. If not I suggest it gets dropped now. :) Just change the docs. 2.5 has been out for two and a half years, I see no reason to have 2.4 support. -- Lennart Regebro: Python, Zope, Plone, Grok http://regebro.wordpress.com/ +33 661 58 14 64
Lennart Regebro wrote:
On Wed, Apr 15, 2009 at 17:09, Martin Aspeli <optilude+lists@gmail.com> wrote:
I didn't even realise Zope 2.12 was meant to run with Python 2.4. I thought it was 2.5/2.6 only. Guess I was wrong.
I thought the same, and I'm sure at least Jim said that 2.4 support is dropped.
Andreas is the release manager for Zope2. So far the story was that Python 2.4 is not officially supported (as Python 2.4 is not maintained any longer by the Python folks) but we will try to keep it running. Hanno
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Martin Aspeli wrote:
Tres Seaver wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Martin Aspeli wrote:
Log message for revision 99146: Let the <permission /> directive auto-register permissions that don't exist already This kind of test is a "poster child" for why doctests with lots of output are fragile: even though it uses pprint, it *still* fails on different Python versions (i.e., it is breaking on Python 2.4).
Sigh... sorry.
I didn't even realise Zope 2.12 was meant to run with Python 2.4. I thought it was 2.5/2.6 only. Guess I was wrong.
This test needs to be rewritten either as a traditional unittest (my preference), or the assertions about the state need to be rewritten in "fine grained" form.
I just copied the tests that were already there, so I'd prefer to keep them in the same place.
I meant to make assertions which didn't rely on the repr / pprint output format, not to break up the test into multiple cases.
Can you show me the failure you get?
http://mail.zope.org/pipermail/zope-tests/2009-April/011469.html Tres. - -- =================================================================== Tres Seaver +1 540-429-0999 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFJ5hnw+gerLs4ltQ4RAodpAKCBj5WXH7JXy6AXy7Pjh+3eJVIGuACgltPz vuhjlMG080AZS09S5i0S3kA= =kNrl -----END PGP SIGNATURE-----
participants (4)
-
Hanno Schlichting -
Lennart Regebro -
Martin Aspeli -
Tres Seaver