[FIX] Fixed imcompatiblity with Windows
[odoo/odoo.git] / doc / tests / check_profile_l10n_all.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 ##############################################################################
4 #    
5 #    OpenERP, Open Source Management Solution
6 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU Affero General Public License as
10 #    published by the Free Software Foundation, either version 3 of the
11 #    License, or (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU Affero General Public License for more details.
17 #
18 #    You should have received a copy of the GNU Affero General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
20 #
21 ##############################################################################
22
23 #
24 # This script will automatically test all profiles, localisations and language
25 # packs You must start the OpenERP server and not have a test database. You
26 # may also have to change some data in the top of this file.
27 #
28
29 import xmlrpclib
30 import time
31 import base64
32
33 url = 'http://localhost:8069/xmlrpc'
34 profiles = [
35     'profile_accounting',
36     'profile_service',
37     'profile_manufacturing'
38 ]
39 l10n_charts = [
40     'l10n_uk',
41     False,
42     'l10n_be',
43     'l10n_fr'
44 ]
45 dbname = 'test'
46 admin_passwd = 'admin'
47 lang = False          # List of langs of False for all
48
49
50 sock = xmlrpclib.ServerProxy(url+'/object')
51 sock2 = xmlrpclib.ServerProxy(url+'/db')
52 sock3 = xmlrpclib.ServerProxy(url+'/common')
53 sock4 = xmlrpclib.ServerProxy(url+'/wizard')
54 demos =  [True]
55
56 langs = lang or (map(lambda x: x[0], sock2.list_lang()) + ['en_US'])
57
58 def wait(id):
59     progress=0.0
60     while not progress==1.0:
61         time.sleep(3)
62         progress,users = sock2.get_progress(admin_passwd, id)
63         time.sleep(3)
64     return True
65
66 def wizard_run(wizname, fieldvalues={}, endstate='end'):
67     wiz_id = sock4.create(dbname, uid, 'admin', wizname)
68     state = 'init'
69     datas = {'form':{}}
70     while state!=endstate:
71         res = sock4.execute(dbname, uid, 'admin', wiz_id, datas, state, {})
72         if 'datas' in res:
73             datas['form'].update( res['datas'] )
74         if res['type']=='form':
75             for field in res['fields'].keys():
76                 datas['form'][field] = res['fields'][field].get('value', False)
77             state = res['state'][-1][0]
78             datas['form'].update(fieldvalues)
79         elif res['type']=='state':
80             state = res['state']
81     return True
82
83 for demo in demos:
84     for l10n in l10n_charts:
85         print 'Testing localisation', l10n, '...'
86         for prof in profiles:
87             print '\tTesting profile', prof, '...'
88             id = sock2.create(admin_passwd, dbname, demo, lang)
89             wait(id)
90             uid = sock3.login(dbname, 'admin','admin')
91
92             idprof = sock.execute(dbname, uid, 'admin', 'ir.module.module', 'search', [('name','=',prof)])
93             if l10n:
94                 idl10n = sock.execute(dbname, uid, 'admin', 'ir.module.module', 'search', [('name','=',l10n)])
95             else:
96                 idl10n = [-1]
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
118
119 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
120