paula.pasplugins: pas plugins communicate with pau, next login
[paula.git] / paula.pasplugins / src / paula / pasplugins / integration.txt
blobfb521ffd3a0f63fb53b40a52773c416b91357b1e
1 paula.pasplugins integration test
2 =================================
4 Supposed to test integration with Plone and PAU.
7 PAU is up and running with our real and fake plugins
8 ----------------------------------------------------
10 First of all, there should be a PAU and it should know about the credentials
11 plugin:
13     >>> from zope.app.authentication.interfaces import \
14     ...         IPluggableAuthentication
15     >>> from zope.app.authentication.interfaces import \
16     ...         ICredentialsPlugin
17     >>> from paula.pasplugins.plugins.paucred import CREDPLUG_NAME
19     >>> pau = getUtility(IPluggableAuthentication)
20     >>> CREDPLUG_NAME in pau.credentialsPlugins
21     True
23     >>> credplug = getUtility(ICredentialsPlugin, name=CREDPLUG_NAME)
24     >>> credplugs = list( pau.getCredentialsPlugins() )
25     >>> len(credplugs)
26     1
27     >>> credplugs[0][0] == CREDPLUG_NAME
28     True
29     >>> credplugs[0][1] is credplug
30     True
33 For further testing we use a fake authenticator plugin:
35     >>> from zope.app.authentication.interfaces import \
36     ...         IAuthenticatorPlugin
37     >>> from paula.pasplugins.tests.fake_pau_ap import AUTHPLUG_NAME
38     >>> from paula.pasplugins.tests.fake_pau_ap import AuthenticatorPlugin
40     >>> len(pau.authenticatorPlugins)
41     0
43     >>> authplug = getUtility(IAuthenticatorPlugin, name=AUTHPLUG_NAME)
44     >>> pau.authenticatorPlugins = (AUTHPLUG_NAME,)
45     >>> authplugs = list( pau.getAuthenticatorPlugins() )
46     >>> len(authplugs)
47     1
48     >>> authplugs[0][0] == AUTHPLUG_NAME
49     True
50     >>> authplugs[0][1] is authplug
51     True
54 Ok, it should be possible to authenticate with PAU, using the credentials
55 for the fake user:
57     >>> pau.authenticate(None)
58     Traceback (most recent call last):
59     ...
60     AttributeError: ...
62     >>> pau.authenticate(UserDict(login='foo',password='foo')) is None
63     True
65     >>> from paula.pasplugins.tests.fake_pau_ap import FAKE_REQUEST
66     >>> principal = pau.authenticate(FAKE_REQUEST)
67     >>> principal.id is 'fakelogin'
68     True
70 The user carries groups and properties provided by our fake testing
71 subscribers:
73     >>> principal.email
74     u'foo@bar.com'
75     >>> principal.realname
76     u'fake user'
77     >>> principal.foo
78     u'foo value'
79     >>> principal.groups
80     ['fakegroup1', 'fakegroup2']
83 The user should also be returned for a getPrincipal call:
85     >>> principal2 = pau.getPrincipal('fakelogin')
86     >>> principal2.id
87     'fakelogin'
88     >>> principal2.email
89     u'foo@bar.com'
90     >>> principal2.realname
91     u'fake user'
92     >>> principal2.foo
93     u'foo value'
94     >>> principal2.groups
95     ['fakegroup1', 'fakegroup2']
98 PAU is working as expected.
101 The PAS plugins
102 ---------------
104     >>> from paula.pasplugins.tests.fake_pau_ap import FAKE_CREDS
106 Paula PAS auth plugin
108     >>> p = portal.acl_users.paula_auth.authenticateCredentials(FAKE_CREDS)
109     >>> p
110     ('fakelogin', 'fakelogin')
112 make a plone user
114     >>> from Products.PlonePAS.plugins.ufactory import PloneUser
115     >>> pu = PloneUser(p[1])
116     >>> pu
117     <PloneUser 'fakelogin'>
119 Paula PAS properties plugin - the order might be unstable
121     >>> psheet = portal.acl_users.paula_properties.getPropertiesForUser(pu)
122     >>> psheet.propertyItems()[0]
123     ('foo', u'foo value')
124     >>> psheet.propertyItems()[1]
125     ('email', u'foo@bar.com')
126     >>> psheet.propertyItems()[2]
127     ('realname', u'fake user')
128     
129 Paula PAS group plugin
131     >>> portal.acl_users.paula_groups.getGroupsForPrincipal(pu)
132     ('fakegroup1', 'fakegroup2')
135 A login should be possible
136 --------------------------
144 #Set things up (thx optilux)
145 #---------------------------
147 #    >>> from Products.Five.testbrowser import Browser
148 #    >>> browser = Browser()
149 #    >>> portal_url = self.portal.absolute_url()
151 #The following is useful when writing and debugging testbrowser tests. It lets
152 #us see error messages properly.
154 #    >>> browser.handleErrors = False
155 #    >>> self.portal.error_log._ignored_exceptions = ()
157 #We then turn off the various portlets, because they sometimes duplicate links
158 #and text (e.g. the navtree, the recent recent items listing) that we wish to
159 #test for in our own views. Having no portlets makes things easier.
161 #    >>> from zope.component import getMultiAdapter, getUtility
162 #    >>> from plone.portlets.interfaces import IPortletManager
163 #    >>> from plone.portlets.interfaces import IPortletAssignmentMapping
165 #    >>> left_column = getUtility(IPortletManager, name=u"plone.leftcolumn")
166 #    >>> left_assignable = getMultiAdapter((self.portal, left_column), IPortletAssignmentMapping)
167 #    >>> for name in left_assignable.keys():
168 #    ...     del left_assignable[name]
170 #    >>> right_column = getUtility(IPortletManager, name=u"plone.rightcolumn")
171 #    >>> right_assignable = getMultiAdapter((self.portal, right_column), IPortletAssignmentMapping)
172 #    >>> for name in right_assignable.keys():
173 #    ...     del right_assignable[name]
176 #Start testing
177 #-------------
181 #try to authenticate
183 #    >>> browser.open(portal_url + '/login_form?came_from=' + portal_url)
184 #    >>> browser.getControl(name='__ac_name').value = u"user"
185 #    >>> browser.getControl(name='__ac_password').value = u"wrong"
186 #    >>> browser.getControl(name='submit').click()
187 #    >>> 'Login failed' in browser.contents
188 #    True
190 #    >>> browser.open(portal_url + '/login_form?came_from=' + portal_url)
191 #    >>> browser.getControl(name='__ac_name').value = u"user"
192 #    >>> browser.getControl(name='__ac_password').value = u"password"
193 #    >>> browser.getControl(name='submit').click()
194 #    >>> 'Login failed' in browser.contents
195 #    False