source: main/waeup.kofa/trunk/src/waeup/kofa/doctests/userscontainer.txt @ 17977

Last change on this file since 17977 was 12948, checked in by Henrik Bettermann, 10 years ago

Move doctests.

File size: 1.8 KB
RevLine 
[12920]1Users Container
2***************
[4090]3
[5140]4.. :doctest:
[7819]5.. :layer: waeup.kofa.testing.KofaUnitTestLayer
[4090]6
7Before we can start, we need some password managers available:
8
9    >>> from zope.app.authentication.placelesssetup import (
10    ...   PlacelessSetup)
11    >>> PlacelessSetup().setUp()
12
13We can create a user container which will hold the useraccounts for
14us:
15
[7811]16    >>> from waeup.kofa.userscontainer import UsersContainer
[7172]17    >>> myusers = UsersContainer()
[4090]18
19We can add users, just by passing a name, a password, and (optionally)
20a title and a description:
21
22    >>> myusers.addUser('bob', 'bobssecret')
23
24Now, Bob is in the container:
25
26    >>> list(myusers)
27    [u'bob']
28
29We can get Bob's account:
30
31    >>> bob = myusers['bob']
32    >>> bob
[7811]33    <waeup.kofa.authentication.Account object at 0x...>
[4090]34
35    >>> bob.name
36    'bob'
37
38    >>> bob.title
39    'bob'
40
41    >>> bob.description
42
43
[7197]44As we did not give a title, the name was taken instead
45for title (but not for description). The password, however, is stored encoded:
46
[4090]47    >>> bob.password
[8343]48    '{SSHA}...'
[4090]49
[8787]50We can export user accounts:
51
[12079]52    >>> from waeup.kofa.userscontainer import UserExporter
[8787]53    >>> import os
54    >>> import tempfile
55    >>> workdir = tempfile.mkdtemp()
56    >>> outfile = os.path.join(workdir, 'myoutput.csv')
[12079]57    >>> exporter = UserExporter()
[8787]58    >>> site = {'users':myusers}
59    >>> exporter.export_all(site, outfile)
60    >>> result = open(outfile, 'rb').read()
61    >>> 'name,title,public_name,description,email,phone,roles,local_roles,password' in result
62    True
63    >>> '{SSHA}' in result
64    True
65
[4090]66We can delete users:
67
68    >>> myusers.delUser('alice')
69
70The container won't complain, although there is no ``alice`` stored
71yet. But we can really delete users:
72
73    >>> myusers.delUser('bob')
74    >>> list(myusers)
75    []
[9283]76
77Clean up:
78
79    >>> import shutil
80    >>> shutil.rmtree(workdir)
Note: See TracBrowser for help on using the repository browser.