1 # -*- coding: utf-8 -*-
10 # The openerp library is supposed already configured.
11 ADDONS_PATH = openerp.tools.config['addons_path']
12 PORT = openerp.tools.config['xmlrpc_port']
13 DB = openerp.tools.config['db_name']
15 # If the database name is not provided on the command-line,
16 # use the one on the thread (which means if it is provided on
17 # the command-line, this will break when installing another
18 # database from XML-RPC).
19 if not DB and hasattr(threading.current_thread(), 'dbname'):
20 DB = threading.current_thread().dbname
26 ADMIN_PASSWORD = 'admin'
30 Start the OpenERP server similary to the openerp-server script.
32 openerp.service.start_services()
34 # Ugly way to ensure the server is listening.
39 Shutdown the OpenERP server similarly to a single ctrl-c.
41 openerp.service.stop_services()
43 class TransactionCase(unittest2.TestCase):
45 Subclass of TestCase with a single transaction, rolled-back at the end of
50 self.cr = self.cursor()
51 self.uid = openerp.SUPERUSER_ID
58 return openerp.modules.registry.RegistryManager.get(DB).db.cursor()
60 def registry(self, model):
61 return openerp.modules.registry.RegistryManager.get(DB)[model]
63 class RpcCase(unittest2.TestCase):
65 Subclass of TestCase with a few XML-RPC proxies.
68 def __init__(self, name):
69 super(RpcCase, self).__init__(name)
75 # Use the old (pre 6.1) API.
76 self.proxy.url_60 = url_60 = 'http://%s:%d/xmlrpc/' % (HOST, PORT)
77 self.proxy.common_60 = xmlrpclib.ServerProxy(url_60 + 'common')
78 self.proxy.db_60 = xmlrpclib.ServerProxy(url_60 + 'db')
79 self.proxy.object_60 = xmlrpclib.ServerProxy(url_60 + 'object')
81 # Use the new (6.1) API.
82 self.proxy.url_61 = url_61 = 'http://%s:%d/openerp/xmlrpc/1/' % (HOST, PORT)
83 self.proxy.common_61 = xmlrpclib.ServerProxy(url_61 + 'common')
84 self.proxy.db_61 = xmlrpclib.ServerProxy(url_61 + 'db')
85 self.proxy.model_61 = xmlrpclib.ServerProxy(url_61 + 'model/' + DB)
88 def generate_database_name(cls):
89 if hasattr(cls, '_database_id'):
93 return '_fresh_name_' + str(cls._database_id) + '_'
95 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: