chiark / gitweb /
Hands-off reading for FLAC.
[disorder] / tests / user.py
CommitLineData
abf54aca 1#! /usr/bin/env python
f0feb22e
RK
2#
3# This file is part of DisOrder.
3ece470d 4# Copyright (C) 2007, 2008 Richard Kettlewell
f0feb22e 5#
e7eb3a27 6# This program is free software: you can redistribute it and/or modify
f0feb22e 7# it under the terms of the GNU General Public License as published by
e7eb3a27 8# the Free Software Foundation, either version 3 of the License, or
f0feb22e
RK
9# (at your option) any later version.
10#
e7eb3a27
RK
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.
15#
f0feb22e 16# You should have received a copy of the GNU General Public License
e7eb3a27 17# along with this program. If not, see <http://www.gnu.org/licenses/>.
f0feb22e
RK
18#
19import dtest,disorder
20
21def test():
22 """Test user database"""
23 dtest.start_daemon()
24 dtest.create_user()
25 print " checking user creation"
26 c = disorder.client()
27 c.adduser("bob", "bobpass")
c3be4f19
RK
28 users = c.users()
29 assert dtest.lists_have_same_contents(users,
30 ["fred", "bob", "root"])
eb5dc014
RK
31 rights = c.userinfo("bob", "rights")
32 print " new user rights are: %s" % rights
f0feb22e
RK
33 print " checking new user can log in"
34 c = disorder.client(user="bob", password="bobpass")
35 c.version()
5df73aeb
RK
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"
f0feb22e
RK
40 print " checking user deletion"
41 c = disorder.client()
42 c.deluser("bob")
43 print " checking new user can no longer log in"
44 c = disorder.client(user="bob", password="bobpass")
45 try:
46 c.version()
47 print "*** should not be able to log in after deletion ***"
48 assert False
49 except disorder.operationError:
50 pass # good
51 print " deleted user could no longer log in."
c3be4f19
RK
52 c = disorder.client()
53 users = c.users()
54 assert dtest.lists_have_same_contents(users,
55 ["fred", "root"])
0f55e905
RK
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="")
62 gc.version()
ba39faf6 63 print " testing user registration"
0f55e905 64 cs = gc.register("joe", "joepass", "joe@nowhere.invalid")
ba39faf6
RK
65 print " confirmation string is %s" % cs
66 print " checking unconfirmed user cannot log in"
67 jc = disorder.client(user="joe", password="joepass")
68 try:
69 jc.version()
70 print "*** should not be able to log in before confirmation ***"
71 assert False
72 except disorder.operationError:
73 pass # good
74 print " confirming user"
0f55e905
RK
75 gc = disorder.client(user="guest", password="")
76 gc.confirm(cs)
ba39faf6
RK
77 print " checking confirmed user can log in"
78 jc = disorder.client(user="joe", password="joepass")
79 jc.version()
0517868c
RK
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"
86 try:
87 c.edituser("joe", "email", "invalid")
88 print "*** should not be able to set invalid email address ***"
89 assert False
90 except disorder.operationError:
91 pass # good
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
f0feb22e
RK
96
97if __name__ == '__main__':
98 dtest.run()