1
from sys import stdout, stderr, exit
3
from xmlrpclib import Fault
6
from tests.openerplib import db
10
server, client = None, None
12
stdout.write("Establishing connections to the server... ")
15
server = openerplib.get_connection(hostname=config.server_host, port=config.server_port)
16
server.get_service('db').list()
18
stdout.write("failed!\n")
19
stderr.write("Unable to connect to OpenERP Sync Server at %s:%s\n" % (config.server_host, config.server_port,))
22
client = openerplib.get_connection(hostname=config.client_host, port=config.client_port)
23
client.get_service('db').list()
25
stdout.write("failed!\n")
26
stderr.write("Unable to connect to OpenERP Sync Client at %s:%s\n" % (config.client_host, config.client_port,))
28
stdout.write("done.\n")
31
if not db.get('sync.client.entity').sync():
32
test.failed('Synchronization process of database "%s" failed!' % (db.db_name,))
33
monitor = db.get('sync.monitor')
34
ids = monitor.search([], 0, 1, '"end" desc')
35
test.traceback = monitor.read(ids, ['error'])[0]['error']
40
class db_instance(type):
43
def connect(cls, login=None, password=None, reconnect=False):
44
if not cls.instance or reconnect:
45
#stderr.write("\n!! Initialization required "+cls.__name__+" !!\n")
46
u = login if login else config.user_login
47
p = password if password else (config.admin_password if login == 'admin' else config.user_password)
48
cls.instance = db(cls.server, cls.__name__, user=u, password=p)
50
if hasattr(cls, 'synchro') and cls.synchro:
51
synchro_serv = cls.instance.get('sync.client.sync_server_connection')
52
## Remove all previous connection
53
ids = synchro_serv.search([])
55
if ids: synchro_serv.write(ids, cls.synchro)
56
else: ids = [synchro_serv.create(cls.synchro)]
57
synchro_serv.connect(ids)
62
def __getattr__(cls, attr):
63
if not cls.instance: raise AttributeError("Class %s is not connected!" % (cls.__name__,))
64
real_attr = getattr(cls.instance, attr)
68
__metaclass__ = db_instance
73
raise Exception, 'This class must not be instanced'
76
__metaclass__ = db_instance
80
'protocol' : 'netrpc',
81
'host' : config.server_host,
82
#'port' : config.server_port, ## XMLRPC port
84
'database' : 'Synchro',
90
raise Exception, 'This class must not be instanced'
93
__metaclass__ = db_instance
97
'protocol' : 'netrpc',
98
'host' : config.server_host,
99
#'port' : config.server_port, ## XMLRPC port
101
'database' : 'Synchro',
103
'password' : 'Coordo',
108
raise Exception, 'This class must not be instanced'
111
__metaclass__ = db_instance
115
'protocol' : 'netrpc',
116
'host' : config.server_host,
117
#'port' : config.server_port, ## XMLRPC port
119
'database' : 'Synchro',
121
'password' : 'Project',
126
raise Exception, 'This class must not be instanced'
129
__metaclass__ = db_instance
133
'protocol' : 'netrpc',
134
'host' : config.server_host,
135
#'port' : config.server_port, ## XMLRPC port
137
'database' : 'Synchro',
138
'login' : 'Project2',
139
'password' : 'Project2',
144
raise Exception, 'This class must not be instanced'