[Zope-dev] SVN: Zope/trunk/ Let the <permission /> directive auto-register permissions that don't exist already

Tres Seaver tseaver at palladion.com
Wed Apr 15 11:03:23 EDT 2009


-----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 at 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-----



More information about the Zope-Dev mailing list