4
Created on Feb 28, 2014
7
Modified by 'od' on 2014 March, the 11th
9
from __future__ import print_function
11
from connection import XMLRPCConnection as XMLConn
12
from connection import UnifieldTestConfigParser
13
from colors import TerminalColors
15
class UnifieldTest(unittest.TestCase):
17
Main test class for Unifield tests using TestCase and Openerplib as main inheritance
18
@var sync: contains Synchro Server oerplib connection
19
@var hq1: same as sync for HQ1 DB
20
@var c1: same as sync for HQ1C1 DB
21
@var p1: same as sync for HQ1C1P1 DB
22
@var db: contains the list of DB connections
23
@var test_module_name: name of the module used to create extended table for tests
24
@var test_module_obj_name: name of the OpenERP object to use to access to extended table
28
test_module_name = 'unifield_tests'
29
test_module_obj_name = 'unifield.test'
31
# FIXME/TODO: Make unittest.TestCase inherit from oerplib.error class because of RPCError that could be raised by unittest.TestCase
33
def _addConnection(self, db_suffix, name):
37
con = XMLConn(db_suffix)
38
setattr(self, name, con)
42
database_display = colors.BRed + '[' + colors.Color_Off + name.center(6) + colors.BRed + ']' + colors.Color_Off
43
self.db[name].colored_name = database_display
45
def _hook_db_process(self, name, database):
47
Some process to do for each database (except SYNC DB)
51
def __init__(self, *args, **kwargs):
53
super(UnifieldTest, self).__init__(*args, **kwargs)
55
c = UnifieldTestConfigParser()
56
self.config = c.read()
57
tempo_mkdb = c.getboolean('DB', 'tempo_mkdb')
58
db_suffixes = ['SYNC_SERVER', 'HQ1', 'HQ1C1', 'HQ1C1P1']
59
names = ['sync', 'hq1', 'c1', 'p1']
61
db_suffixes = ['SYNC_SERVER', 'HQ_01', 'COORDO_01', 'PROJECT_01']
62
colors = TerminalColors()
64
# Keep each database connection
65
for db_tuple in zip(db_suffixes, names):
66
self._addConnection(db_tuple[0], db_tuple[1])
67
# For each database, check that unifield_tests module is loaded
69
#+ Except if the database is sync one
70
for database_name in self.db:
71
if database_name == 'sync':
73
database = self.db.get(database_name)
74
module_obj = database.get('ir.module.module')
75
m_ids = module_obj.search([('name', '=', self.test_module_name)])
76
database_display = database.colored_name
77
for module in module_obj.read(m_ids, ['state']):
78
state = module.get('state', '')
79
if state == 'uninstalled':
80
print (database_display + ' [' + colors.BYellow + 'UP'.center(4) + colors.Color_Off + '] Module %s' % (self.test_module_name))
81
module_obj.button_install([module.get('id')])
82
database.get('base.module.upgrade').upgrade_module([])
83
elif state in ['to upgrade', 'to install']:
84
print (database_display + ' [' + colors.BYellow + 'UP'.center(4) + colors.Color_Off + '] Module %s' % (self.test_module_name))
85
database.get('base.module.upgrade').upgrade_module([])
86
elif state in ['installed']:
87
print (database_display + ' [' + colors.BGreen + 'OK'.center(4) + colors.Color_Off + '] Module %s' % (self.test_module_name))
90
raise EnvironmentError(' Wrong module state: %s' % (state or '',))
91
# Some processes after instanciation for this database
92
self._hook_db_process(database_name, database)
94
def is_keyword_present(self, db, keyword):
96
Check that the given keyword is present in given db connection and active.
99
if not db or not keyword:
101
t_obj = db.get(self.test_module_obj_name)
102
t_ids = t_obj.search([('name', '=', keyword), ('active', '=', True)])
107
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: