3 # This file is part of DisOrder.
4 # Copyright (C) 2007, 2008 Richard Kettlewell
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 """Test user database"""
25 print " checking user creation"
27 c
.adduser("bob", "bobpass")
29 assert dtest
.lists_have_same_contents(users
,
30 ["fred", "bob", "root"])
31 rights
= c
.userinfo("bob", "rights")
32 print " new user rights are: %s" % rights
33 print " checking new user can log in"
34 c
= disorder
.client(user
="bob", password
="bobpass")
36 print " checking bob can set their email address"
37 c
.edituser("bob", "email", "foo@bar")
38 email
= c
.userinfo("bob", "email")
39 assert email
== "foo@bar", "checking bob's email address"
40 print " checking user deletion"
43 print " checking new user can no longer log in"
44 c
= disorder
.client(user
="bob", password
="bobpass")
47 print "*** should not be able to log in after deletion ***"
49 except disorder
.operationError
:
51 print " deleted user could no longer log in."
54 assert dtest
.lists_have_same_contents(users
,
56 print " creating the guest user"
57 dtest
.command(["disorder",
58 "--config", disorder
._configfile
, "--no-per-user-config",
59 "--user", "root", "setup-guest"])
60 print " logging in as guest user"
61 gc
= disorder
.client(user
="guest", password
="")
63 print " testing user registration"
64 cs
= gc
.register("joe", "joepass", "joe@nowhere.invalid")
65 print " confirmation string is %s" % cs
66 print " checking unconfirmed user cannot log in"
67 jc
= disorder
.client(user
="joe", password
="joepass")
70 print "*** should not be able to log in before confirmation ***"
72 except disorder
.operationError
:
74 print " confirming user"
75 gc
= disorder
.client(user
="guest", password
="")
77 print " checking confirmed user can log in"
78 jc
= disorder
.client(user
="joe", password
="joepass")
80 print " checking new user's email address"
81 assert c
.userinfo("joe", "email") == "joe@nowhere.invalid"
82 print " checking can change user email address"
83 c
.edituser("joe", "email", "joe@another.invalid")
84 assert c
.userinfo("joe", "email") == "joe@another.invalid"
85 print " checking bad email address rejected"
87 c
.edituser("joe", "email", "invalid")
88 print "*** should not be able to set invalid email address ***"
90 except disorder
.operationError
:
92 assert c
.userinfo("joe", "email") == "joe@another.invalid"
93 print " checking removal of email address"
94 c
.edituser("joe", "email", "")
95 assert c
.userinfo("joe", "email") == None
97 if __name__
== '__main__':