[IMP] ref and browse_ref helpers on openerp.tests.common.BaseCase

bzr revid: stephane.bidoul@acsone.eu-20121031103027-2sozmbi3z7bkr22q
This commit is contained in:
Stéphane Bidoul
2012-10-31 11:30:27 +01:00
parent 46e94a312c
commit 2aee5380eb
+15 -1
View File
@@ -44,6 +44,8 @@ def stop_openerp():
class BaseCase(unittest2.TestCase):
"""
Subclass of TestCase for common OpenERP-specific code.
This class is abstract and expects self.cr and self.uid to be initialized by subclasses.
"""
@classmethod
@@ -53,7 +55,19 @@ class BaseCase(unittest2.TestCase):
@classmethod
def registry(self, model):
return openerp.modules.registry.RegistryManager.get(DB)[model]
def ref(self, xmlid):
"""Returns res_id corresponding to a given module_name.xml_id (cached) or raise ValueError if not found"""
assert "." in xmlid, "this method required a fully qualified xml_id"
module, xmlid = xmlid.split('.')
model, id = self.registry('ir.model.data').get_object_reference(self.cr, self.uid, module, xmlid)
return id
def browse_ref(self, xmlid):
"""Returns a browsable record for the given module_name.xml_id or raise ValueError if not found"""
assert "." in xmlid, "this method required a fully qualified xml_id"
module, xmlid = xmlid.split('.')
return self.registry('ir.model.data').get_object(self.cr, self.uid, module, xmlid)
class TransactionCase(BaseCase):
"""