7fb08c5d7642c769c07c523737d85009fb8e034e
[tests.git] / system / TestUserSfa.py
1 # Thierry Parmentelat <thierry.parmentelat@inria.fr>
2 # Copyright (C) 2010 INRIA 
3 #
4 import os, sys, time
5 import xmlrpc.client
6
7 import utils
8
9 class TestUserSfa:
10
11     def __init__ (self, test_auth_sfa, user_spec):
12         self.test_auth_sfa = test_auth_sfa
13         self.user_spec = user_spec
14         # shortcuts
15         self.test_plc = self.test_auth_sfa.test_plc
16         self.login_base = self.test_auth_sfa.login_base
17
18     def sfi_path(self):
19         return self.test_auth_sfa.sfi_path()
20     def hrn(self):
21         return self.test_auth_sfa.obj_hrn(self.user_spec['name'])
22     def sfi_pi(self, *args, **kwds):
23         return self.test_auth_sfa.sfi_pi(*args, **kwds)
24     def sfi_user(self, *args, **kwds):
25         return self.test_auth_sfa.sfi_user(*args, **kwds)
26
27     # xxx todo - not the right place any longer - or is it ?
28     def sfa_register_user (self, options):
29         "add a regular user using sfi register"
30         user_hrn = self.hrn()
31         command = "register"
32         command += " --type user"
33         command += " --xrn {}".format(user_hrn)
34         command += " --email {}".format(self.user_spec['email'])
35         command += " " + " ".join(self.user_spec['register_options'])
36         # handle key separately because of embedded whitespace
37         # hack - the user's pubkey is avail from his hrn
38         command += " -k {}/{}.pub".format(self.sfi_path(), user_hrn)
39         return self.test_plc.run_in_guest(self.sfi_pi(command)) == 0
40
41     def sfa_update_user (self,options):
42         "update a user record using sfi update"
43         user_hrn = self.hrn()
44         command="update"
45         command += " --type user"
46         command += " --xrn {}".format(user_hrn)
47         command += " " + " ".join(self.user_spec['update_options'])
48         return self.test_plc.run_in_guest(self.sfi_pi(command)) == 0
49
50     def sfa_delete_user(self,options):
51         "run sfi delete on user record"
52         user_hrn = self.hrn()
53         command = "remove -t user {}".format(user_hrn)
54         return self.test_plc.run_in_guest(self.sfi_pi(command)) == 0