[Checkins] SVN: zope.pluggableauth/trunk/s Cleaning the tests. Removed the useless zcml layer.

Souheil CHELFOUH souheil at chelfouh.com
Sun Jan 24 14:08:00 EST 2010


Log message for revision 108448:
  Cleaning the tests. Removed the useless zcml layer.
  All tests pass. The factories/authentication modules now are pretty much slimed down.
  We need to figure what to do with that queriable thing. This can be retained and used in zope.app.authentication.
  We need now to create a branch in zope.app.auth to use our new package.
  

Changed:
  U   zope.pluggableauth/trunk/setup.py
  U   zope.pluggableauth/trunk/src/zope/pluggableauth/README.txt
  U   zope.pluggableauth/trunk/src/zope/pluggableauth/authentication.py
  U   zope.pluggableauth/trunk/src/zope/pluggableauth/factories.py
  D   zope.pluggableauth/trunk/src/zope/pluggableauth/ftesting.zcml
  U   zope.pluggableauth/trunk/src/zope/pluggableauth/interfaces.py
  U   zope.pluggableauth/trunk/src/zope/pluggableauth/tests.py

-=-
Modified: zope.pluggableauth/trunk/setup.py
===================================================================
--- zope.pluggableauth/trunk/setup.py	2010-01-24 19:02:37 UTC (rev 108447)
+++ zope.pluggableauth/trunk/setup.py	2010-01-24 19:07:59 UTC (rev 108448)
@@ -16,19 +16,37 @@
       author='Zope Corporation and Contributors',
       author_email='zope-dev at zope.org',
       description='Pluggable Authentication Utility',
-      long_description=(
-        read('README.txt')
-        + '\n\n' +
-        'Detailed Documentation\n' +
-        '----------------------\n'
-        + '\n' +
-        read('src', 'zope', 'pluggableauth', 'README.txt')
-        + '\n\n' +
-        read('CHANGES.txt')
-        ),
+      long_description= "%s\n\n%s\n\n%s" % (
+        read('README.txt'), 
+        read('src', 'zope', 'pluggableauth', 'README.txt'),
+        read('CHANGES.txt')),
       url='http://pypi.python.org/pypi/zope.pluggableauth',
       license='ZPL 2.1',
-      classifiers = [
+      keywords='zope3 ztk authentication pluggable',
+      packages=find_packages('src'),
+      package_dir = {'': 'src'},
+      namespace_packages=['zope'],
+      include_package_data = True,
+      zip_safe = False,
+      extras_require=dict(test=['zope.app.testing']),
+      install_requires=[
+          'ZODB3',
+          'setuptools',
+          'zope.authentication',
+          'zope.component',
+          'zope.container',
+          'zope.event',
+          'zope.i18n',
+          'zope.i18nmessageid',
+          'zope.interface',
+          'zope.location',
+          'zope.publisher>=3.12',
+          'zope.schema',
+          'zope.security',
+          'zope.session',
+          'zope.site',
+          'zope.traversing'],
+     classifiers = [
           'Development Status :: 5 - Production/Stable',
           'Environment :: Web Environment',
           'Intended Audience :: Developers',
@@ -38,31 +56,4 @@
           'Operating System :: OS Independent',
           'Topic :: Internet :: WWW/HTTP',
           'Framework :: Zope3'],
-      keywords='zope3 ztk authentication pluggable',
-      packages=find_packages('src'),
-      package_dir = {'': 'src'},
-      extras_require=dict(test=['zope.app.testing',
-                                'zope.app.securitypolicy',
-                                'zope.securitypolicy',
-                                'zope.login',]),
-      namespace_packages=['zope'],
-      install_requires=['setuptools',
-                        'zope.component',
-                        'zope.container',
-                        'zope.authentication',
-                        'zope.i18n',
-                        'zope.i18nmessageid',
-                        'zope.interface',
-                        'zope.location',
-                        'zope.password>=3.5.1',
-                        'zope.publisher>=3.12',
-                        'zope.schema',
-                        'zope.security',
-                        'zope.session',
-                        'zope.site',
-                        'zope.traversing',
-                        'ZODB3',
-                        ],
-      include_package_data = True,
-      zip_safe = False,
       )

Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/README.txt
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/README.txt	2010-01-24 19:02:37 UTC (rev 108447)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/README.txt	2010-01-24 19:07:59 UTC (rev 108448)
@@ -121,7 +121,7 @@
 Using the PAU to Authenticate
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-  >>> from zope.pluggableauth.factory import AuthenticatedPrincipalFactory
+  >>> from zope.pluggableauth.factories import AuthenticatedPrincipalFactory
   >>> provideAdapter(AuthenticatedPrincipalFactory)
 
 We can now use the PAU to authenticate a sample request::
@@ -330,9 +330,11 @@
   >>> authenticator2 = AnotherAuthenticatorPlugin()
   >>> provideUtility(authenticator2, name='Authentication Plugin 2')
 
-and add a principal to it::
+and add a principal to them::
 
-  >>> authenticator1.add('black', 'Black Spy', 'Also sneaky', 'deathtowhite')
+  >>> authenticator1.add('bob', 'Bob', 'A nice guy', 'b0b')
+  >>> authenticator1.add('white', 'White Spy', 'Sneaky', 'deathtoblack')
+  >>> authenticator2.add('black', 'Black Spy', 'Also sneaky', 'deathtowhite')
 
 When we configure the PAU to use both searchable authenticators (note the
 order)::
@@ -341,6 +343,11 @@
   ...     'Authentication Plugin 2',
   ...     'Authentication Plugin 1')
 
+we register the factories for our principals::
+
+  >>> from zope.pluggableauth.factories import FoundPrincipalFactory
+  >>> provideAdapter(FoundPrincipalFactory)
+
 we see how the PAU uses both plugins::
 
   >>> pau.getPrincipal('xyz_white')
@@ -537,140 +544,3 @@
 
   >> pau.getPrincipal('mypas_41')
   OddPrincipal('mypas_41', "{'int': 41}")
-
-
-Searching
----------
-
-PAU implements ISourceQueriables::
-
-  >>> from zope.schema.interfaces import ISourceQueriables
-  >>> ISourceQueriables.providedBy(pau)
-  True
-
-This means a PAU can be used in a principal source vocabulary (Zope provides a
-sophisticated searching UI for principal sources).
-
-As we've seen, a PAU uses each of its authenticator plugins to locate a
-principal with a given ID. However, plugins may also provide the interface
-IQuerySchemaSearch to indicate they can be used in the PAU's principal search
-scheme.
-
-Currently, our list of authenticators::
-
-  >>> pau.authenticatorPlugins
-  ('My Authenticator Plugin',)
-
-does not include a queriable authenticator. PAU cannot therefore provide any
-queriables::
-
-  >>> list(pau.getQueriables())
-  []
-
-Before we illustrate how an authenticator is used by the PAU to search for
-principals, we need to setup an adapter used by PAU::
-
-  >>> provideAdapter(
-  ...     authentication.authentication.QuerySchemaSearchAdapter,
-  ...     provides=interfaces.IQueriableAuthenticator)
-
-This adapter delegates search responsibility to an authenticator, but prepends
-the PAU prefix to any principal IDs returned in a search.
-
-Next, we'll create a plugin that provides a search interface::
-
-  >>> class QueriableAuthenticatorPlugin(MyAuthenticatorPlugin):
-  ...
-  ...     interface.implements(interfaces.IQuerySchemaSearch)
-  ...
-  ...     schema = None
-  ...
-  ...     def search(self, query, start=None, batch_size=None):
-  ...         yield 'foo'
-  ...
-
-and install it as a plugin::
-
-  >>> plugin = QueriableAuthenticatorPlugin()
-  >>> provideUtility(plugin,
-  ...                provides=interfaces.IAuthenticatorPlugin,
-  ...                name='Queriable')
-  >>> pau.authenticatorPlugins += ('Queriable',)
-
-Now, the PAU provides a single queriable::
-
-  >>> list(pau.getQueriables()) # doctest: +ELLIPSIS
-  [('Queriable', ...QuerySchemaSearchAdapter object...)]
-
-We can use this queriable to search for our principal::
-
-  >>> queriable = list(pau.getQueriables())[0][1]
-  >>> list(queriable.search('not-used'))
-  ['mypau_foo']
-
-Note that the resulting principal ID includes the PAU prefix. Were we to search
-the plugin directly::
-
-  >>> list(plugin.search('not-used'))
-  ['foo']
-
-The result does not include the PAU prefix. The prepending of the prefix is
-handled by the PluggableAuthenticationQueriable.
-
-
-Queryiable plugins can provide the ILocation interface. In this case the
-QuerySchemaSearchAdapter's __parent__ is the same as the __parent__ of the
-plugin::
-
-  >>> import zope.location.interfaces
-  >>> class LocatedQueriableAuthenticatorPlugin(QueriableAuthenticatorPlugin):
-  ...
-  ...     interface.implements(zope.location.interfaces.ILocation)
-  ...
-  ...     __parent__ = __name__ = None
-  ...
-  >>> import zope.site.hooks
-  >>> site = zope.site.hooks.getSite()
-  >>> plugin = LocatedQueriableAuthenticatorPlugin()
-  >>> plugin.__parent__ = site
-  >>> plugin.__name__ = 'localname'
-  >>> provideUtility(plugin,
-  ...                provides=interfaces.IAuthenticatorPlugin,
-  ...                name='location-queriable')
-  >>> pau.authenticatorPlugins = ('location-queriable',)
-
-We have one queriable again::
-
-  >>> queriables = list(pau.getQueriables())
-  >>> queriables  # doctest: +ELLIPSIS
-  [('location-queriable', ...QuerySchemaSearchAdapter object...)]
-
-The queriable's __parent__ is the site as set above::
-
-  >>> queriable = queriables[0][1]
-  >>> queriable.__parent__ is site
-  True
-
-If the queriable provides ILocation but is not actually locatable (i.e. the
-parent is None) the pau itself becomes the parent::
-
-
-  >>> plugin = LocatedQueriableAuthenticatorPlugin()
-  >>> provideUtility(plugin,
-  ...                provides=interfaces.IAuthenticatorPlugin,
-  ...                name='location-queriable-wo-parent')
-  >>> pau.authenticatorPlugins = ('location-queriable-wo-parent',)
-
-We have one queriable again::
-
-  >>> queriables = list(pau.getQueriables())
-  >>> queriables  # doctest: +ELLIPSIS
-  [('location-queriable-wo-parent', ...QuerySchemaSearchAdapter object...)]
-
-And the parent is the pau::
-
-  >>> queriable = queriables[0][1]
-  >>> queriable.__parent__  # doctest: +ELLIPSIS
-  <zope.app.authentication.authentication.PluggableAuthentication object ...>
-  >>> queriable.__parent__ is pau
-  True

Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/authentication.py
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/authentication.py	2010-01-24 19:02:37 UTC (rev 108447)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/authentication.py	2010-01-24 19:07:59 UTC (rev 108448)
@@ -20,7 +20,6 @@
 from zope.schema.interfaces import ISourceQueriables
 from zope.location.interfaces import ILocation
 from zope.site.next import queryNextUtility
-from zope.annotation.interfaces import IAttributeAnnotatable
 
 from zope.authentication.interfaces import IAuthentication, PrincipalLookupError
 from zope.container.btree import BTreeContainer
@@ -32,7 +31,6 @@
 
     implements(
         IAuthentication,
-        IAttributeAnnotatable,
         interfaces.IPluggableAuthentication,
         ISourceQueriables)
 

Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/factories.py
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/factories.py	2010-01-24 19:02:37 UTC (rev 108447)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/factories.py	2010-01-24 19:07:59 UTC (rev 108448)
@@ -20,6 +20,7 @@
 from zope import component
 from zope import interface
 from zope.authentication.interfaces import IAuthentication
+from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal
 from zope.event import notify
 from zope.pluggableauth import interfaces
 from zope.publisher.interfaces import IRequest
@@ -148,7 +149,7 @@
        'user_managers', 'zope_3_project', 'list_administrators',
        'zope_3_list_admin', 'zpug']
     """
-    interface.implements(interfaces.IPrincipal)
+    interface.implements(IPrincipal)
 
     def __init__(self, id, title=u'', description=u''):
         self.id = id

Deleted: zope.pluggableauth/trunk/src/zope/pluggableauth/ftesting.zcml
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/ftesting.zcml	2010-01-24 19:02:37 UTC (rev 108447)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/ftesting.zcml	2010-01-24 19:07:59 UTC (rev 108448)
@@ -1,71 +0,0 @@
-<configure
-   xmlns="http://namespaces.zope.org/zope"
-   i18n_domain="zope"
-   package="zope.pluggableauth"
-   >
-
-  <!-- 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.security" file="meta.zcml" />
-  <include package="zope.securitypolicy" file="meta.zcml" />
-  <include package="zope.principalregistry" file="meta.zcml" />
-
-  <include package="zope.security" />
-  <include package="zope.principalregistry" />
-  <include package="zope.session" />
-  <include package="zope.pluggableauth" />
-  <include package="zope.login" />
-
-  <securityPolicy
-    component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
-
-  <role id="zope.Anonymous" title="Everybody"
-                 description="All users have this role implicitly" />
-  <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" />
-
-  <grantAll role="zope.Manager" />
-
-  <!-- Principals -->
-
-  <unauthenticatedPrincipal
-      id="zope.anybody"
-      title="Unauthenticated User" />
-
-  <unauthenticatedGroup
-    id="zope.Anybody"
-    title="Unauthenticated Users"
-    />
-
-  <authenticatedGroup
-    id="zope.Authenticated"
-    title="Authenticated Users"
-    />
-
-  <everybodyGroup
-    id="zope.Everybody"
-    title="All Users"
-    />
-
-  <!-- Principal that tests generally run as -->
-  <principal
-      id="zope.mgr"
-      title="Manager"
-      login="mgr"
-      password="mgrpw" />
-
-  <!-- Bootstrap principal used to make local grant to the principal above -->
-  <principal
-      id="zope.globalmgr"
-      title="Manager"
-      login="globalmgr"
-      password="globalmgrpw" />
-
-  <grant role="zope.Manager" principal="zope.globalmgr" />
-
-</configure>

Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/interfaces.py
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/interfaces.py	2010-01-24 19:02:37 UTC (rev 108447)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/interfaces.py	2010-01-24 19:07:59 UTC (rev 108448)
@@ -226,5 +226,26 @@
         self.request = request
 
 
+class IFoundPrincipalCreated(IPrincipalCreated):
+    """A principal has been created by way of a search operation."""
+
+
+class FoundPrincipalCreated:
+    """
+    >>> from zope.interface.verify import verifyObject
+    >>> event = FoundPrincipalCreated("authentication", "principal",
+    ...     "info")
+    >>> verifyObject(IFoundPrincipalCreated, event)
+    True
+    """
+
+    zope.interface.implements(IFoundPrincipalCreated)
+
+    def __init__(self, authentication, principal, info):
+        self.authentication = authentication
+        self.principal = principal
+        self.info = info
+
+
 class IQueriableAuthenticator(zope.interface.Interface):
     """Indicates the authenticator provides a search UI for principals."""

Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/tests.py
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/tests.py	2010-01-24 19:02:37 UTC (rev 108447)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/tests.py	2010-01-24 19:07:59 UTC (rev 108448)
@@ -19,31 +19,21 @@
 
 import doctest, unittest
 
-from zope.interface import implements
+from zope.app.testing import placelesssetup
+from zope.app.testing.setup import placefulSetUp, placefulTearDown
 from zope.component import provideUtility, provideAdapter, provideHandler
 from zope.component.eventtesting import getEvents, clearEvents
+from zope.interface import implements
+from zope.pluggableauth.plugins.session import SessionCredentialsPlugin
+from zope.publisher import base
 from zope.publisher.interfaces import IRequest
-
-from zope.app.testing import placelesssetup
-from zope.app.testing.setup import placefulSetUp, placefulTearDown
-from zope.session.interfaces import \
-        IClientId, IClientIdManager, ISession, ISessionDataContainer
-from zope.session.session import \
-        ClientId, Session, PersistentSessionDataContainer
 from zope.session.http import CookieClientIdManager
+from zope.session.interfaces import (
+    IClientId, IClientIdManager, ISession, ISessionDataContainer)
+from zope.session.session import (
+    ClientId, Session, PersistentSessionDataContainer)
 
-from zope.publisher import base
-from zope.pluggableauth.plugins.session import SessionCredentialsPlugin
 
-import os
-from zope.app.testing.functional import ZCMLLayer
-
-AppAuthenticationLayer = ZCMLLayer(
-    os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
-    __name__, 'AppAuthenticationLayer', allow_teardown=True)
-
-
-
 class TestClientId(object):
     implements(IClientId)
     def __new__(cls, request):
@@ -103,32 +93,26 @@
 
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(doctest.DocTestSuite('zope.pluggableauth.interfaces'))
-    suite.addTest(doctest.DocTestSuite('zope.pluggableauth.plugins.generic'))
-    suite.addTest(doctest.DocTestSuite('zope.pluggableauth.plugins.ftpplugins'))
-    suite.addTest(doctest.DocTestSuite(
-        'zope.pluggableauth.plugins.httpplugins'))
-    
-    suite.addTest(doctest.DocTestSuite('zope.pluggableauth.plugins.session',
-                                       setUp=siteSetUp,
-                                       tearDown=siteTearDown))
-
-    suite.addTest(
+    suite = unittest.TestSuite((
+        unittest.makeSuite(NonHTTPSessionTestCase),
+        doctest.DocTestSuite('zope.pluggableauth.interfaces'),
+        doctest.DocTestSuite('zope.pluggableauth.plugins.generic'),
+        doctest.DocTestSuite('zope.pluggableauth.plugins.ftpplugins'),
+        doctest.DocTestSuite('zope.pluggableauth.plugins.httpplugins'),
+        doctest.DocTestSuite('zope.pluggableauth.plugins.session',
+                             setUp=siteSetUp,
+                             tearDown=siteTearDown),
         doctest.DocFileSuite('README.txt',
-                            setUp=siteSetUp,
+                             setUp=siteSetUp,
                              tearDown=siteTearDown,
                              globs={'provideUtility': provideUtility,
                                     'provideAdapter': provideAdapter,
                                     'provideHandler': provideHandler,
                                     'getEvents': getEvents,
                                     'clearEvents': clearEvents,
-                                    }))
-
-    suite.addTest(unittest.makeSuite(NonHTTPSessionTestCase))
+                                    })))
     return suite
 
- 
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')



More information about the checkins mailing list