diff --git a/openerp/addons/base/ir/ir_ui_menu.py b/openerp/addons/base/ir/ir_ui_menu.py index 5ab546cb554..43ece8c0868 100644 --- a/openerp/addons/base/ir/ir_ui_menu.py +++ b/openerp/addons/base/ir/ir_ui_menu.py @@ -132,20 +132,29 @@ class ir_ui_menu(osv.osv): return len(result) return result - def _get_full_name(self, cr, uid, ids, name, args, context): - res = {} - for m in self.browse(cr, uid, ids, context=context): - res[m.id] = self._get_one_full_name(m) + def name_get(self, cr, uid, ids, context=None): + res = [] + for id in ids: + elmt = self.browse(cr, uid, id, context=context) + res.append((id, self._get_one_full_name(elmt))) return res - def _get_one_full_name(self, menu, level=6): + def _get_full_name(self, cr, uid, ids, name=None, args=None, context=None): + if context == None: + context = {} + res = {} + for elmt in self.browse(cr, uid, ids, context=context): + res[elmt.id] = self._get_one_full_name(elmt) + return res + + def _get_one_full_name(self, elmt, level=6): if level<=0: return '...' - if menu.parent_id: - parent_path = self._get_one_full_name(menu.parent_id, level-1) + "/" + if elmt.parent_id: + parent_path = self._get_one_full_name(elmt.parent_id, level-1) + "/" else: parent_path = '' - return parent_path + menu.name + return parent_path + elmt.name def create(self, *args, **kwargs): self.clear_cache() @@ -282,7 +291,7 @@ class ir_ui_menu(osv.osv): 'groups_id': fields.many2many('res.groups', 'ir_ui_menu_group_rel', 'menu_id', 'gid', 'Groups', help="If you have groups, the visibility of this menu will be based on these groups. "\ "If this field is empty, OpenERP will compute visibility based on the related object's read access."), - 'complete_name': fields.function(_get_full_name, + 'complete_name': fields.function(_get_full_name, string='Full Path', type='char', size=128), 'icon': fields.selection(tools.icons, 'Icon', size=64), 'icon_pict': fields.function(_get_icon_pict, type='char', size=32), diff --git a/openerp/addons/base/module/module_view.xml b/openerp/addons/base/module/module_view.xml index c3b3684f07c..e825451674b 100644 --- a/openerp/addons/base/module/module_view.xml +++ b/openerp/addons/base/module/module_view.xml @@ -105,7 +105,7 @@ ir.module.module.form ir.module.module -
+
diff --git a/openerp/tests/__init__.py b/openerp/tests/__init__.py index 3427743263c..d06e1030d6f 100644 --- a/openerp/tests/__init__.py +++ b/openerp/tests/__init__.py @@ -9,6 +9,7 @@ See the :ref:`test-framework` section in the :ref:`features` list. """ from . import test_expression, test_html_sanitize, test_ir_sequence, test_orm,\ + test_per_class_teardown, \ test_view_validation, test_uninstall, test_misc, test_db_cursor fast_suite = [ @@ -20,6 +21,7 @@ checks = [ test_html_sanitize, test_db_cursor, test_orm, + test_per_class_teardown, test_view_validation, test_misc, ] diff --git a/openerp/tests/common.py b/openerp/tests/common.py index 53c67c68844..b3ee4ac53f2 100644 --- a/openerp/tests/common.py +++ b/openerp/tests/common.py @@ -40,10 +40,25 @@ def stop_openerp(): """ openerp.service.stop_services() -class TransactionCase(unittest2.TestCase): + +class BaseCase(unittest2.TestCase): """ - Subclass of TestCase with a single transaction, rolled-back at the end of - the tests. + Subclass of TestCase for common OpenERP-specific code. + """ + + @classmethod + def cursor(self): + return openerp.modules.registry.RegistryManager.get(DB).db.cursor() + + @classmethod + def registry(self, model): + return openerp.modules.registry.RegistryManager.get(DB)[model] + + +class TransactionCase(BaseCase): + """ + Subclass of BaseCase with a single transaction, rolled-back at the end of + each test (method). """ def setUp(self): @@ -54,11 +69,23 @@ class TransactionCase(unittest2.TestCase): self.cr.rollback() self.cr.close() - def cursor(self): - return openerp.modules.registry.RegistryManager.get(DB).db.cursor() - def registry(self, model): - return openerp.modules.registry.RegistryManager.get(DB)[model] +class SingleTransactionCase(BaseCase): + """ + Subclass of BaseCase with a single transaction for the whole class, + rolled-back after all the tests. + """ + + @classmethod + def setUpClass(cls): + cls.cr = cls.cursor() + cls.uid = openerp.SUPERUSER_ID + + @classmethod + def tearDownClass(cls): + cls.cr.rollback() + cls.cr.close() + class RpcCase(unittest2.TestCase): """ diff --git a/openerp/tests/test_per_class_teardown.py b/openerp/tests/test_per_class_teardown.py new file mode 100644 index 00000000000..a1890095c09 --- /dev/null +++ b/openerp/tests/test_per_class_teardown.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +import unittest2 + +import openerp +import common + +class test_per_class_teardown(common.SingleTransactionCase): + """ + Check the whole-class transaction behavior of SingleTransactionCase. + """ + + def test_00(self): + """Create a partner.""" + cr, uid = self.cr, self.uid + self.registry('res.partner').create(cr, uid, {'name': 'test_per_class_teardown_partner'}) + ids = self.registry('res.partner').search(cr, uid, [('name', '=', 'test_per_class_teardown_partner')]) + self.assertEqual(1, len(ids), "Test partner not found.") + + def test_01(self): + """Find the created partner.""" + cr, uid = self.cr, self.uid + ids = self.registry('res.partner').search(cr, uid, [('name', '=', 'test_per_class_teardown_partner')]) + self.assertEqual(1, len(ids), "Test partner not found.") + +class test_per_method_teardown(common.TransactionCase): + """ + Check the per-method transaction behavior of TransactionCase. + """ + + def test_00(self): + """Create a partner.""" + cr, uid = self.cr, self.uid + ids = self.registry('res.partner').search(cr, uid, [('name', '=', 'test_per_class_teardown_partner')]) + self.assertEqual(0, len(ids), "Test partner found.") + self.registry('res.partner').create(cr, uid, {'name': 'test_per_class_teardown_partner'}) + ids = self.registry('res.partner').search(cr, uid, [('name', '=', 'test_per_class_teardown_partner')]) + self.assertEqual(1, len(ids), "Test partner not found.") + + def test_01(self): + """Don't find the created partner.""" + cr, uid = self.cr, self.uid + ids = self.registry('res.partner').search(cr, uid, [('name', '=', 'test_per_class_teardown_partner')]) + self.assertEqual(0, len(ids), "Test partner found.") + +if __name__ == '__main__': + unittest2.main() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: