Added timeout for postgresql
[odoo/odoo.git] / doc / tests / check_profile_l10n_all.py
1 #!/usr/bin/python
2 ##############################################################################
3 #
4 # Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
5 #                    Fabien Pinckaers <fp@tiny.Be>
6 #
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
12 # Service Company
13 #
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27 #
28 ##############################################################################
29
30 #
31 # This script will automatically test all profiles, localisations and language
32 # packs You must start the Tiny ERP server and not have a test database. You
33 # may also have to change some data in the top of this file.
34 #
35
36 import xmlrpclib
37 import time
38 import base64
39
40 url = 'http://localhost:8069/xmlrpc'
41 profiles = [
42         'profile_accounting',
43         'profile_manufacturing',
44         'profile_service'
45 ]
46 l10n_charts = [
47         'l10n_be',
48         'l10n_fr',
49         'l10n_chart_uk_minimal'
50 ]
51 dbname = 'test'
52 admin_passwd = 'admin'
53 lang = False          # List of langs of False for all
54
55 sock = xmlrpclib.ServerProxy(url+'/object')
56 sock2 = xmlrpclib.ServerProxy(url+'/db')
57 sock3 = xmlrpclib.ServerProxy(url+'/common')
58 sock4 = xmlrpclib.ServerProxy(url+'/wizard')
59 demos =  [True]
60
61 langs = lang or (map(lambda x: x[0], sock2.list_lang()) + ['en_US'])
62
63 def wait(id):
64         progress=0.0
65         while not progress==1.0:
66                 progress,users = sock2.get_progress(admin_passwd, id)
67         return True
68
69 def wizard_run(wizname, fieldvalues={}, endstate='end'):
70         wiz_id = sock4.create(dbname, uid, 'admin', wizname)
71         state = 'init'
72         datas = {'form':{}}
73         while state!=endstate:
74                 res = sock4.execute(dbname, uid, 'admin', wiz_id, datas, state, {})
75                 if 'datas' in res:
76                         datas['form'].update( res['datas'] )
77                 if res['type']=='form':
78                         for field in res['fields'].keys():
79                                 datas['form'][field] = res['fields'][field].get('value', False)
80                         state = res['state'][-1][0]
81                         datas['form'].update(fieldvalues)
82                 elif res['type']=='state':
83                         state = res['state']
84         return True
85
86 for demo in demos:
87                 for l10n in l10n_charts:
88                         print 'Testing localisation', l10n, '...'
89                         for prof in profiles:
90                                 print '\tTesting profile', prof, '...'
91                                 id = sock2.create(admin_passwd, dbname, demo, lang)
92                                 wait(id)
93                                 uid = sock3.login(dbname, 'admin','admin')
94
95                                 idprof = sock.execute(dbname, uid, 'admin', 'ir.module.module', 'search', [('name','=',prof)])
96                                 idl10n = sock.execute(dbname, uid, 'admin', 'ir.module.module', 'search', [('name','=',l10n)])
97                                 wizard_run('base_setup.base_setup', {
98                                         'profile': idprof[0],
99                                         'charts': idl10n[0],
100                                 }, 'menu')
101                                 for lang in langs:
102                                         print '\t\tTesting Language', lang, '...'
103                                         wizard_run('module.lang.install', {'lang': lang})
104
105                                 ok = False
106                                 range = 4
107                                 while (not ok) and range:
108                                         try:
109                                                 time.sleep(2)
110                                                 id = sock2.drop(admin_passwd, dbname)
111                                                 ok = True
112                                         except:
113                                                 range -= 1
114                                 time.sleep(2)
115
116
117