[IMP] Moved the tests directory inside the openerp module, added --run-tests command-line argument.
bzr revid: vmt@openerp.com-20111115163843-djq6hybp24lk9f5e
This commit is contained in:
@@ -221,6 +221,20 @@ if __name__ == "__main__":
|
||||
|
||||
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)
|
||||
|
||||
@@ -40,7 +40,7 @@ JOB = {
|
||||
'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 @@ class test_ir_cron(openerp.osv.osv.osv):
|
||||
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 @@ class test_ir_cron(openerp.osv.osv.osv):
|
||||
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 @@ class test_ir_cron(openerp.osv.osv.osv):
|
||||
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')
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# -*- 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
|
||||
@@ -6,9 +6,10 @@ import xmlrpclib
|
||||
|
||||
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 @@ db_proxy_61 = None
|
||||
model_proxy_61 = None
|
||||
model_uri_61 = None
|
||||
|
||||
def setUpModule():
|
||||
def start_openerp():
|
||||
"""
|
||||
Start the OpenERP server similary to the openerp-server script and
|
||||
setup some xmlrpclib proxies.
|
||||
Start the OpenERP server similary to the openerp-server script.
|
||||
"""
|
||||
openerp.tools.config['addons_path'] = ADDONS_PATH
|
||||
openerp.tools.config['xmlrpc_port'] = PORT
|
||||
openerp.service.start_services()
|
||||
|
||||
# Ugly way to ensure the server is listening.
|
||||
time.sleep(2)
|
||||
|
||||
def create_xmlrpc_proxies():
|
||||
"""
|
||||
setup some xmlrpclib proxies.
|
||||
"""
|
||||
global common_proxy_60
|
||||
global db_proxy_60
|
||||
global object_proxy_60
|
||||
@@ -55,9 +60,6 @@ def setUpModule():
|
||||
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()
|
||||
@@ -19,7 +19,9 @@ import common
|
||||
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):
|
||||
@@ -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 @@ LINK_TO = lambda id: (4, id, False)
|
||||
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()
|
||||
@@ -19,7 +19,10 @@ ADMIN_USER = common.ADMIN_USER
|
||||
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):
|
||||
@@ -266,6 +266,10 @@ class configmanager(object):
|
||||
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.")
|
||||
group.add_option("--run-tests-no-db", dest="run_tests_no_db", my_default=False, action="store_true",
|
||||
help="Run a test suite (which does'nt assume an existing database).")
|
||||
|
||||
parser.add_option_group(group)
|
||||
|
||||
@@ -370,6 +374,7 @@ class configmanager(object):
|
||||
'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:
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import test_xmlrpc
|
||||
Reference in New Issue
Block a user