[Zope-CMF] how can I fake authentication in a unit test case

Stefan H. Holek stefan@epy.co.at
Mon, 28 Oct 2002 12:42:02 +0100


Robert!

You may want to take a look at the ZopeTestCase package.
<http://www.zope.org/Members/shh/ZopeTestCase>

ZTC has support for playing with roles and permissions in your unit tests. 
If you want to do things manually you can log in a user by calling 
newSecurityManager().

from AccessControl.SecurityManagement import \
newSecurityManager, noSecurityManager

uf = self.acl_users
user = uf.getUser('herbert').__of__(uf)
newSecurityManager(None, user)
# herbert is now logged in

noSecurityManager()
# herbert is now logged out

HTH,
Stefan



--On Montag, 28. Oktober 2002 07:20 +0100 robert <robert@redcor.ch> wrote:

> Hi there,
>
> in a complex environment with a bunch of groups , rules and folders I
> would like to programmatically test that every combination of
> user/role/document is properly handled permission wise.
>
> To do this I would like to have a unit test with a testusers that tries
> to handle documents according to his roles.
>
> Now my question:
> how can a testuser authenticate itself in a unit test?
>
> Or is there some other way to achieve this goal?
>
> thanks for your tips
>
> Robert
>
>
> _______________________________________________
> Zope-CMF maillist  -  Zope-CMF@zope.org
> http://lists.zope.org/mailman/listinfo/zope-cmf
>
> See http://collector.zope.org/CMF for bug reports and feature requests

--
Those who write software only for pay should go hurt some other field.
/Erik Naggum/