define PLC_MAIL_FROM_ADDRESS
[tests.git] / system / TestSite.py
1 # Thierry Parmentelat <thierry.parmentelat@inria.fr>
2 # Copyright (C) 2010 INRIA 
3 #
4 import os.path
5 import datetime
6 import time
7 import traceback
8
9 import utils
10 from TestNode import TestNode
11 from TestUser import TestUser
12 from TestKey import TestKey
13
14 class TestSite:
15
16     def __init__ (self, test_plc, site_spec):
17         self.test_plc = test_plc
18         self.site_spec = site_spec
19         
20     def name(self):
21         return self.site_spec['site_fields']['login_base']
22
23     def create_site (self):
24         print(self.test_plc.auth_root())
25         self.test_plc.apiserver.AddSite(self.test_plc.auth_root(),
26                                         self.site_spec['site_fields'])
27         self.test_plc.apiserver.AddSiteAddress(self.test_plc.auth_root(),
28                                                self.name(),
29                                                self.site_spec['address_fields'])
30             
31     def create_users (self):
32         for user_spec in self.site_spec['users']:
33             test_user = TestUser(self.test_plc, self, user_spec)
34             test_user.create_user()
35             test_user.add_keys()            
36
37     def delete_site (self):
38         print(self.test_plc.auth_root())
39         self.test_plc.apiserver.DeleteSite(self.test_plc.auth_root(), self.name())
40         return True
41             
42     def delete_users(self):
43         for user_spec in self.site_spec['users']:
44             test_user = TestUser(self.test_plc, self, user_spec)
45             test_user.delete_user()
46
47     def locate_user (self, username):
48         for user in self.site_spec['users']:
49             if user['name'] == username:
50                 return user
51             if user['user_fields']['email'] == username:
52                 return user
53         raise Exception("Cannot locate user {}".format(username))
54         
55     def locate_node (self, nodename):
56         for node in self.site_spec['nodes']:
57             if node['name'] == nodename:
58                 return node
59         raise Exception("Cannot locate node {}".format(nodename))
60         
61            
62