Vo Minh Thu (OpenERP) has proposed merging
lp:~openerp-dev/openobject-server/trunk-run-tests-vmt into lp:openobject-server.
Requested reviews:
OpenERP Core Team (openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-run-tests-vmt/+merge/84078
--
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-run-tests-vmt/+merge/84078
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-server/trunk-run-tests-vmt.
=== modified file 'openerp-server'
--- openerp-server 2011-11-10 13:41:23 +0000
+++ openerp-server 2011-12-01 10:16:34 +0000
@@ -89,7 +89,9 @@
def preload_registry(dbname):
""" Preload a registry, and start the cron."""
try:
- db, registry = openerp.pooler.get_db_and_pool(dbname, update_module=config['init'] or config['update'], pooljobs=False)
+ update_module = True if config['init'] or config['update'] else False
+ db, registry = openerp.pooler.get_db_and_pool(
+ dbname, update_module=update_module, pooljobs=False, force_demo=not config['without_demo'])
# jobs will start to be processed later, when openerp.cron.start_master_thread() is called by openerp.service.start_services()
registry.schedule_cron_jobs()
@@ -99,7 +101,9 @@
def run_test_file(dbname, test_file):
""" Preload a registry, possibly run a test file, and start the cron."""
try:
- db, registry = openerp.pooler.get_db_and_pool(dbname, update_module=config['init'] or config['update'], pooljobs=False)
+ update_module = True if config['init'] or config['update'] else False
+ db, registry = openerp.pooler.get_db_and_pool(
+ dbname, update_module=update_module, pooljobs=False, force_demo=not config['without_demo'])
cr = db.cursor()
logger = logging.getLogger('server')
logger.info('loading test file %s', test_file)
@@ -221,6 +225,20 @@
setup_signal_handlers()
+ if config["run_tests_no_db"]:
+ import unittest2
+ import openerp.tests
+ # This test suite creates a database.
+ unittest2.TextTestRunner(verbosity=2).run(openerp.tests.make_suite_no_db())
+ sys.exit(0)
+
+ if config["run_tests"]:
+ import unittest2
+ import openerp.tests
+ # This test suite assumes a database.
+ unittest2.TextTestRunner(verbosity=2).run(openerp.tests.make_suite())
+ sys.exit(0)
+
if config["test_file"]:
run_test_file(config['db_name'], config['test_file'])
sys.exit(0)
=== modified file 'openerp/addons/base/test/test_ir_cron.py'
--- openerp/addons/base/test/test_ir_cron.py 2011-08-09 11:10:08 +0000
+++ openerp/addons/base/test/test_ir_cron.py 2011-12-01 10:16:34 +0000
@@ -40,7 +40,7 @@
'model': u'ir.cron'
}
-class test_ir_cron(openerp.osv.osv.osv):
+class x_test_ir_cron(openerp.osv.osv.osv):
""" Add a few handy methods to test cron jobs scheduling. """
_inherit = "ir.cron"
@@ -57,7 +57,7 @@
time.sleep(80)
print ">>> out _80_seconds"
- def test_0(self, cr, uid):
+ def x_test_0(self, cr, uid):
now = datetime.now()
t1 = (now + relativedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S')
t2 = (now + relativedelta(minutes=1, seconds=5)).strftime('%Y-%m-%d %H:%M:%S')
@@ -66,17 +66,17 @@
self.create(cr, uid, dict(JOB, name='test_0 _20_seconds B', function='_20_seconds', nextcall=t2))
self.create(cr, uid, dict(JOB, name='test_0 _20_seconds C', function='_20_seconds', nextcall=t3))
- def test_1(self, cr, uid):
+ def x_test_1(self, cr, uid):
now = datetime.now()
t1 = (now + relativedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S')
self.create(cr, uid, dict(JOB, name='test_1 _20_seconds * 3', function='_20_seconds', nextcall=t1, numbercall=3))
- def test_2(self, cr, uid):
+ def x_test_2(self, cr, uid):
now = datetime.now()
t1 = (now + relativedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S')
self.create(cr, uid, dict(JOB, name='test_2 _80_seconds * 2', function='_80_seconds', nextcall=t1, numbercall=2))
- def test_3(self, cr, uid):
+ def x_test_3(self, cr, uid):
now = datetime.now()
t1 = (now + relativedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S')
t2 = (now + relativedelta(minutes=1, seconds=5)).strftime('%Y-%m-%d %H:%M:%S')
@@ -86,7 +86,7 @@
self.create(cr, uid, dict(JOB, name='test_3 _20_seconds C', function='_20_seconds', nextcall=t3))
# This test assumes 4 cron threads.
- def test_00(self, cr, uid):
+ def x_test_00(self, cr, uid):
self.test_00_set = set()
now = datetime.now()
t1 = (now + relativedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S')
=== modified file 'openerp/modules/graph.py'
--- openerp/modules/graph.py 2011-10-12 15:58:18 +0000
+++ openerp/modules/graph.py 2011-12-01 10:16:34 +0000
@@ -88,15 +88,19 @@
for k, v in additional_data[package.name].items():
setattr(package, k, v)
- def add_module(self, cr, module, force=None):
- self.add_modules(cr, [module], force)
+ def add_module(self, cr, module, force_demo=False):
+ self.add_modules(cr, [module], force_demo)
- def add_modules(self, cr, module_list, force=None):
- if force is None:
- force = []
+ def add_modules(self, cr, module_list, force_demo=False):
packages = []
len_graph = len(self)
for module in module_list:
+ if force_demo:
+ cr.execute("""
+ UPDATE ir_module_module
+ SET demo='t'
+ WHERE name = %s""",
+ (module,))
# This will raise an exception if no/unreadable descriptor file.
# NOTE The call to load_information_from_description_file is already
# done by db.initialize, so it is possible to not do it again here.
@@ -122,9 +126,6 @@
current.remove(package)
node = self.add_node(package, info)
node.data = info
- for kind in ('init', 'demo', 'update'):
- if package in tools.config[kind] or 'all' in tools.config[kind] or kind in force:
- setattr(node, kind, True)
else:
later.add(package)
packages.append((package, info))
@@ -186,18 +187,11 @@
node.depth = self.depth + 1
if node not in self.children:
self.children.append(node)
- for attr in ('init', 'update', 'demo'):
- if hasattr(self, attr):
- setattr(node, attr, True)
self.children.sort(lambda x, y: cmp(x.name, y.name))
return node
def __setattr__(self, name, value):
super(Singleton, self).__setattr__(name, value)
- if name in ('init', 'update', 'demo'):
- tools.config[name][self.name] = 1
- for child in self.children:
- setattr(child, name, value)
if name == 'depth':
for child in self.children:
setattr(child, name, value + 1)
=== modified file 'openerp/modules/loading.py'
--- openerp/modules/loading.py 2011-10-17 14:46:15 +0000
+++ openerp/modules/loading.py 2011-12-01 10:16:34 +0000
@@ -164,7 +164,7 @@
register_module_classes(package.name)
models = pool.load(cr, package)
loaded_modules.append(package.name)
- if hasattr(package, 'init') or hasattr(package, 'update') or package.state in ('to install', 'to upgrade'):
+ if package.state in ('to install', 'to upgrade'):
init_module_models(cr, package.name, models)
status['progress'] = float(index) / len(graph)
@@ -178,18 +178,19 @@
idref = {}
- mode = 'update'
- if hasattr(package, 'init') or package.state == 'to install':
+ if package.state == 'to install':
mode = 'init'
+ else:
+ mode = 'update'
- if hasattr(package, 'init') or hasattr(package, 'update') or package.state in ('to install', 'to upgrade'):
+ if package.state in ('to install', 'to upgrade'):
if package.state=='to upgrade':
# upgrading the module information
modobj.write(cr, 1, [module_id], modobj.get_values_from_terp(package.data))
load_init_xml(module_name, idref, mode)
load_update_xml(module_name, idref, mode)
load_data(module_name, idref, mode)
- if hasattr(package, 'demo') or (package.dbdemo and package.state != 'installed'):
+ if package.dbdemo and package.state != 'installed':
status['progress'] = (index + 0.75) / len(graph)
load_demo_xml(module_name, idref, mode)
load_demo(module_name, idref, mode)
@@ -212,9 +213,6 @@
modobj.update_translations(cr, 1, [module_id], None)
package.state = 'installed'
- for kind in ('init', 'demo', 'update'):
- if hasattr(package, kind):
- delattr(package, kind)
cr.commit()
@@ -272,10 +270,7 @@
if not openerp.modules.db.is_initialized(cr):
logger.notifyChannel("init", netsvc.LOG_INFO, "init db")
openerp.modules.db.initialize(cr)
- tools.config["init"]["all"] = 1
- tools.config['update']['all'] = 1
- if not tools.config['without_demo']:
- tools.config["demo"]['all'] = 1
+ update_module = True
# This is a brand new pool, just created in pooler.get_db_and_pool()
pool = pooler.get_pool(cr.dbname)
@@ -286,42 +281,49 @@
# STEP 1: LOAD BASE (must be done before module dependencies can be computed for later steps)
graph = openerp.modules.graph.Graph()
- graph.add_module(cr, 'base', force)
+ graph.add_module(cr, 'base', force_demo)
if not graph:
logger.notifyChannel('init', netsvc.LOG_CRITICAL, 'module base cannot be loaded! (hint: verify addons-path)')
raise osv.osv.except_osv(_('Could not load base module'), _('module base cannot be loaded! (hint: verify addons-path)'))
# processed_modules: for cleanup step after install
# loaded_modules: to avoid double loading
- loaded_modules, processed_modules = load_module_graph(cr, graph, status, perform_checks=(not update_module), report=report)
+ # After load_module_graph(), 'base' has been installed or updated and its state is 'installed'.
+ loaded_modules, processed_modules = load_module_graph(cr, graph, status, report=report)
if tools.config['load_language']:
for lang in tools.config['load_language'].split(','):
tools.load_language(cr, lang)
# STEP 2: Mark other modules to be loaded/updated
+ # This is a one-shot use of tools.config[init|update] from the command line
+ # arguments. It is directly cleared to not interfer with later create/update
+ # issued via RPC.
if update_module:
modobj = pool.get('ir.module.module')
- if ('base' in tools.config['init']) or ('base' in tools.config['update']):
+ if ('base' in tools.config['init']) or ('base' in tools.config['update']) \
+ or ('all' in tools.config['init']) or ('all' in tools.config['update']):
logger.notifyChannel('init', netsvc.LOG_INFO, 'updating modules list')
modobj.update_list(cr, 1)
+ if 'all' in tools.config['init']:
+ ids = modobj.search(cr, 1, [])
+ tools.config['init'] = dict.fromkeys([m['name'] for m in modobj.read(cr, 1, ids, ['name'])], 1)
+
_check_module_names(cr, itertools.chain(tools.config['init'].keys(), tools.config['update'].keys()))
- mods = [k for k in tools.config['init'] if tools.config['init'][k]]
- if mods:
- ids = modobj.search(cr, 1, ['&', ('state', '=', 'uninstalled'), ('name', 'in', mods)])
- if ids:
- modobj.button_install(cr, 1, ids)
-
- mods = [k for k in tools.config['update'] if tools.config['update'][k]]
- if mods:
- ids = modobj.search(cr, 1, ['&', ('state', '=', 'installed'), ('name', 'in', mods)])
- if ids:
- modobj.button_upgrade(cr, 1, ids)
-
- cr.execute("update ir_module_module set state=%s where name=%s", ('installed', 'base'))
-
+ mods = [k for k in tools.config['init'] if tools.config['init'][k] and k not in ('base', 'all')]
+ ids = modobj.search(cr, 1, ['&', ('state', '=', 'uninstalled'), ('name', 'in', mods)])
+ if ids:
+ modobj.button_install(cr, 1, ids) # goes from 'uninstalled' to 'to install'
+
+ mods = [k for k in tools.config['update'] if tools.config['update'][k] and k not in ('base', 'all')]
+ ids = modobj.search(cr, 1, ['&', ('state', '=', 'installed'), ('name', 'in', mods)])
+ if ids:
+ modobj.button_upgrade(cr, 1, ids) # goes from 'installed' to 'to upgrade'
+
+ for kind in ('init', 'demo', 'update'):
+ tools.config[kind] = {}
# STEP 3: Load marked modules (skipping base which was done in STEP 1)
# IMPORTANT: this is done in two parts, first loading all installed or
@@ -371,9 +373,6 @@
if report.get_report():
logger.notifyChannel('init', netsvc.LOG_INFO, report)
- for kind in ('init', 'demo', 'update'):
- tools.config[kind] = {}
-
cr.commit()
if update_module:
# Remove records referenced from ir_model_data for modules to be
=== renamed directory 'tests' => 'openerp/tests'
=== modified file 'openerp/tests/__init__.py'
--- tests/__init__.py 2011-11-22 08:58:48 +0000
+++ openerp/tests/__init__.py 2011-12-01 10:16:34 +0000
@@ -1,4 +1,19 @@
# -*- coding: utf-8 -*-
+import unittest2
+
+import test_orm
+import test_ir_sequence
import test_xmlrpc
+def make_suite():
+ suite = unittest2.TestSuite()
+ suite.addTests(unittest2.TestLoader().loadTestsFromModule(test_ir_sequence))
+ suite.addTests(unittest2.TestLoader().loadTestsFromModule(test_orm))
+ return suite
+
+def make_suite_no_db():
+ suite = unittest2.TestSuite()
+ suite.addTests(unittest2.TestLoader().loadTestsFromModule(test_xmlrpc))
+ return suite
+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== modified file 'openerp/tests/common.py'
--- tests/common.py 2011-11-22 08:58:48 +0000
+++ openerp/tests/common.py 2011-12-01 10:16:34 +0000
@@ -6,9 +6,10 @@
import openerp
-ADDONS_PATH = os.environ['OPENERP_ADDONS_PATH']
-PORT = int(os.environ['OPENERP_PORT'])
-DB = os.environ['OPENERP_DATABASE']
+# The openerp library is supposed already configured.
+ADDONS_PATH = openerp.tools.config['addons_path']
+PORT = openerp.tools.config['xmlrpc_port']
+DB = openerp.tools.config['db_name']
HOST = '127.0.0.1'
@@ -25,15 +26,19 @@
model_proxy_61 = None
model_uri_61 = None
-def setUpModule():
- """
- Start the OpenERP server similary to the openerp-server script and
+def start_openerp():
+ """
+ Start the OpenERP server similary to the openerp-server script.
+ """
+ openerp.service.start_services()
+
+ # Ugly way to ensure the server is listening.
+ time.sleep(2)
+
+def create_xmlrpc_proxies():
+ """
setup some xmlrpclib proxies.
"""
- openerp.tools.config['addons_path'] = ADDONS_PATH
- openerp.tools.config['xmlrpc_port'] = PORT
- openerp.service.start_services()
-
global common_proxy_60
global db_proxy_60
global object_proxy_60
@@ -55,9 +60,6 @@
db_proxy_61 = xmlrpclib.ServerProxy(model_uri_61 + 'db')
model_proxy_61 = xmlrpclib.ServerProxy(model_uri_61 + 'model/' + DB)
- # Ugly way to ensure the server is listening.
- time.sleep(2)
-
def tearDownModule():
""" Shutdown the OpenERP server similarly to a single ctrl-c. """
openerp.service.stop_services()
=== modified file 'openerp/tests/test_ir_sequence.py'
--- tests/test_ir_sequence.py 2011-11-22 08:58:48 +0000
+++ openerp/tests/test_ir_sequence.py 2011-12-01 10:16:34 +0000
@@ -19,7 +19,9 @@
DB = common.DB
ADMIN_USER_ID = common.ADMIN_USER_ID
-setUpModule = common.setUpModule
+def setUpModule():
+ common.create_xmlrpc_proxies()
+
tearDownModule = common.tearDownModule
def registry(model):
=== modified file 'openerp/tests/test_orm.py'
--- tests/test_orm.py 2011-11-22 08:58:48 +0000
+++ openerp/tests/test_orm.py 2011-12-01 10:16:34 +0000
@@ -1,9 +1,10 @@
import os
import unittest2
+
import openerp
UID = 1
-DB = os.environ['OPENERP_DATABASE']
+DB = openerp.tools.config['db_name']
CREATE = lambda values: (0, False, values)
UPDATE = lambda id, values: (1, id, values)
@@ -13,14 +14,13 @@
DELETE_ALL = lambda: (5, False, False)
REPLACE_WITH = lambda ids: (6, False, ids)
-def setUpModule():
- openerp.tools.config['addons_path'] = os.environ['OPENERP_ADDONS_PATH']
-
class TestO2MSerialization(unittest2.TestCase):
+
def setUp(self):
self.cr = openerp.modules.registry.RegistryManager.get(DB).db.cursor()
self.partner = openerp.modules.registry.RegistryManager.get(DB)['res.partner']
self.address = openerp.modules.registry.RegistryManager.get(DB)['res.partner.address']
+
def tearDown(self):
self.cr.rollback()
self.cr.close()
=== modified file 'openerp/tests/test_xmlrpc.py'
--- tests/test_xmlrpc.py 2011-11-22 08:58:48 +0000
+++ openerp/tests/test_xmlrpc.py 2011-12-01 10:16:34 +0000
@@ -19,7 +19,10 @@
ADMIN_USER_ID = common.ADMIN_USER_ID
ADMIN_PASSWORD = common.ADMIN_PASSWORD
-setUpModule = common.setUpModule
+def setUpModule():
+ common.start_openerp()
+ common.create_xmlrpc_proxies()
+
tearDownModule = common.tearDownModule
class test_xmlrpc(unittest2.TestCase):
=== modified file 'openerp/tools/config.py'
--- openerp/tools/config.py 2011-11-22 08:58:48 +0000
+++ openerp/tools/config.py 2011-12-01 10:16:34 +0000
@@ -266,6 +266,10 @@
type="int")
group.add_option("--unaccent", dest="unaccent", my_default=False, action="store_true",
help="Use the unaccent function provided by the database when available.")
+ group.add_option("--run-tests", dest="run_tests", my_default=False, action="store_true",
+ help="Run a test suite. This creates a database (possibly created with --run-tests-no-db).")
+ group.add_option("--run-tests-no-db", dest="run_tests_no_db", my_default=False, action="store_true",
+ help="Run a test suite (which doesn't assume an existing database).")
parser.add_option_group(group)
@@ -323,6 +327,10 @@
"The config file '%s' selected with -c/--config doesn't exist, "\
"use -s/--save if you want to generate it"%(opt.config))
+ die((opt.run_tests or opt.run_tests_no_db) and not opt.db_name,
+ "The --run-tests and --run-tests-no-db need a database name "\
+ "(using the --database or -d options).")
+
# place/search the config file on Win32 near the server installation
# (../etc from the server)
# if the server is run by an unprivileged user, he has to specify location of a config file where he has the rights to write,
@@ -370,6 +378,7 @@
'list_db', 'xmlrpcs',
'test_file', 'test_disable', 'test_commit', 'test_report_directory',
'osv_memory_count_limit', 'osv_memory_age_limit', 'max_cron_threads', 'unaccent',
+ 'run_tests', 'run_tests_no_db',
]
for arg in keys:
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp