[IMP] tests.common: improved docstring for ref() and browse_ref()

bzr revid: odo@openerp.com-20121031152149-73pxpymjf1yz5xqi
This commit is contained in:
Olivier Dony 2012-10-31 16:21:49 +01:00
parent 43513d7ccc
commit 51f2422b41
1 changed files with 23 additions and 14 deletions

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os
import threading import threading
import time import time
import unittest2 import unittest2
@ -40,7 +39,6 @@ def stop_openerp():
""" """
openerp.service.stop_services() openerp.service.stop_services()
class BaseCase(unittest2.TestCase): class BaseCase(unittest2.TestCase):
""" """
Subclass of TestCase for common OpenERP-specific code. Subclass of TestCase for common OpenERP-specific code.
@ -55,19 +53,30 @@ class BaseCase(unittest2.TestCase):
@classmethod @classmethod
def registry(self, model): def registry(self, model):
return openerp.modules.registry.RegistryManager.get(DB)[model] return openerp.modules.registry.RegistryManager.get(DB)[model]
def ref(self, xmlid): @classmethod
"""Returns res_id corresponding to a given module_name.xml_id (cached) or raise ValueError if not found""" def ref(self, xid):
assert "." in xmlid, "this method required a fully qualified xml_id" """ Returns database ID corresponding to a given identifier.
module, xmlid = xmlid.split('.')
model, id = self.registry('ir.model.data').get_object_reference(self.cr, self.uid, module, xmlid) :param xid: fully-qualified record identifier, in the form ``module.identifier``
:raise: ValueError if not found
"""
assert "." in xid, "this method requires a fully qualified parameter, in the following form: 'module.identifier'"
module, xid = xid.split('.')
_, id = self.registry('ir.model.data').get_object_reference(self.cr, self.uid, module, xid)
return id return id
def browse_ref(self, xmlid): @classmethod
"""Returns a browsable record for the given module_name.xml_id or raise ValueError if not found""" def browse_ref(self, xid):
assert "." in xmlid, "this method required a fully qualified xml_id" """ Returns a browsable record for the given identifier.
module, xmlid = xmlid.split('.')
return self.registry('ir.model.data').get_object(self.cr, self.uid, module, xmlid) :param xid: fully-qualified record identifier, in the form ``module.identifier``
:raise: ValueError if not found
"""
assert "." in xid, "this method requires a fully qualified parameter, in the following form: 'module.identifier'"
module, xid = xid.split('.')
return self.registry('ir.model.data').get_object(self.cr, self.uid, module, xid)
class TransactionCase(BaseCase): class TransactionCase(BaseCase):
""" """