class OOTestSuite(unittest.TestSuite): def __init__(self, tests=()): super(OOTestSuite, self).__init__(tests) self.config = config_from_environment( 'DESTRAL', ['module', 'testing_langs'], use_template=True, testing_langs=[] ) ooconfig = {} self.config['use_template'] = False ooconfig['demo'] = {'all': 1} if self.config['module'] == 'base': ooconfig.setdefault('update', {}) ooconfig['update'].update({'base': 1}) self.openerp = OpenERPService(**ooconfig) self.drop_database = True def run(self, result, debug=False): """Run the test suite * Sets the config using environment variables prefixed with `DESTRAL_`. * Creates a new OpenERP service. * Installs the module to test if a database is not defined. """ module_suite = not result._testRunEntered if module_suite: if not self.openerp.db_name: self.openerp.db_name = self.openerp.create_database( self.config['use_template'] ) else: self.drop_database = False result.db_name = self.openerp.db_name self.openerp.install_module(self.config['module']) else: self.openerp.db_name = result.db_name res = super(OOTestSuite, self).run(result, debug) module_suite = not result._testRunEntered if module_suite: if self.drop_database: self.openerp.drop_database() self.openerp.db_name = False else: logger.info('Not dropping database %s', self.openerp.db_name) self.openerp.enable_admin() return res def _handleClassSetUp(self, test, result): test_class = test.__class__ test_class.openerp = self.openerp test_class.config = self.config super(OOTestSuite, self)._handleClassSetUp(test, result)
class OOTestSuite(unittest.TestSuite): def __init__(self, tests=()): super(OOTestSuite, self).__init__(tests) self.config = config_from_environment('DESTRAL', ['module', 'testing_langs'], use_template=True, testing_langs=[]) ooconfig = {} self.config['use_template'] = False ooconfig['demo'] = {'all': 1} if self.config['module'] == 'base': ooconfig.setdefault('update', {}) ooconfig['update'].update({'base': 1}) self.openerp = OpenERPService(**ooconfig) self.drop_database = True def run(self, result, debug=False): """Run the test suite * Sets the config using environment variables prefixed with `DESTRAL_`. * Creates a new OpenERP service. * Installs the module to test if a database is not defined. """ module_suite = not result._testRunEntered if module_suite: if not self.openerp.db_name: self.openerp.db_name = self.openerp.create_database( self.config['use_template']) else: self.drop_database = False result.db_name = self.openerp.db_name self.openerp.install_module(self.config['module']) else: self.openerp.db_name = result.db_name res = super(OOTestSuite, self).run(result, debug) module_suite = not result._testRunEntered if module_suite: if self.drop_database: self.openerp.drop_database() self.openerp.db_name = False else: logger.info('Not dropping database %s', self.openerp.db_name) self.openerp.enable_admin() return res def _handleClassSetUp(self, test, result): test_class = test.__class__ test_class.openerp = self.openerp test_class.config = self.config super(OOTestSuite, self)._handleClassSetUp(test, result)
class OOTestCase(unittest.TestCase): """Base class to inherit test cases from for OpenERP Testing Framework. """ @property def database(self): return self.openerp.db_name def setUp(self): self.config = config_from_environment('DESTRAL', ['module']) self.openerp = OpenERPService() self.drop_database = False if not self.openerp.db_name: self.openerp.db_name = self.openerp.create_database() self.drop_database = True self.openerp.install_module(self.config['module']) def test_all_views(self): logger.info('Testing views for module %s', self.config['module']) imd_obj = self.openerp.pool.get('ir.model.data') view_obj = self.openerp.pool.get('ir.ui.view') with Transaction().start(self.database) as txn: imd_ids = imd_obj.search(txn.cursor, txn.user, [ ('model', '=', 'ir.ui.view'), ('module', '=', self.config['module']) ]) if imd_ids: views = {} for imd in imd_obj.read(txn.cursor, txn.user, imd_ids): view_xml_name = '{}.{}'.format(imd['module'], imd['name']) views[imd['res_id']] = view_xml_name view_ids = views.keys() logger.info('Testing %s views...', len(view_ids)) for view in view_obj.browse(txn.cursor, txn.user, view_ids): view_xml_name = views[view.id] model = self.openerp.pool.get(view.model) if model is None: # Check if model exists raise Exception( 'View (xml id: %s) references model %s which does ' 'not exist' % (view_xml_name, view.model) ) logger.info('Testing view %s (id: %s)', view.name, view.id) model.fields_view_get(txn.cursor, txn.user, view.id, view.type) def tearDown(self): if self.drop_database: self.openerp.drop_database() self.openerp.config['db_name'] = False
class OOTestCase(unittest.TestCase): """Base class to inherit test cases from for OpenERP Testing Framework. """ @property def database(self): return self.openerp.db_name def setUp(self): self.config = config_from_environment('DESTRAL', ['module']) self.openerp = OpenERPService() if not self.openerp.db_name: self.openerp.db_name = self.openerp.create_database() self.openerp.install_module(self.config['module']) def test_all_views(self): logger.info('Testing views for module %s', self.config['module']) imd_obj = self.openerp.pool.get('ir.model.data') view_obj = self.openerp.pool.get('ir.ui.view') with Transaction().start(self.database) as txn: imd_ids = imd_obj.search(txn.cursor, txn.user, [ ('model', '=', 'ir.ui.view'), ('module', '=', self.config['module']) ]) if imd_ids: views = {} for imd in imd_obj.read(txn.cursor, txn.user, imd_ids): view_xml_name = '{}.{}'.format(imd['module'], imd['name']) views[imd['res_id']] = view_xml_name view_ids = views.keys() logger.info('Testing %s views...', len(view_ids)) for view in view_obj.browse(txn.cursor, txn.user, view_ids): view_xml_name = views[view.id] model = self.openerp.pool.get(view.model) if model is None: # Check if model exists raise Exception( 'View (xml id: %s) references model %s which does ' 'not exist' % (view_xml_name, view.model) ) logger.info('Testing view %s (id: %s)', view.name, view.id) model.fields_view_get(txn.cursor, txn.user, view.id, view.type) def tearDown(self): self.openerp.drop_database() self.openerp.config['db_name'] = False