From 51f2422b41e9640ee6b981ada9d126d34a0c3e85 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 31 Oct 2012 16:21:49 +0100 Subject: [PATCH] [IMP] tests.common: improved docstring for ref() and browse_ref() bzr revid: odo@openerp.com-20121031152149-73pxpymjf1yz5xqi --- openerp/tests/common.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/openerp/tests/common.py b/openerp/tests/common.py index 488e4bd8bd8..f05be10f098 100644 --- a/openerp/tests/common.py +++ b/openerp/tests/common.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -import os import threading import time import unittest2 @@ -40,7 +39,6 @@ def stop_openerp(): """ openerp.service.stop_services() - class BaseCase(unittest2.TestCase): """ Subclass of TestCase for common OpenERP-specific code. @@ -55,19 +53,30 @@ 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) + + @classmethod + def ref(self, xid): + """ Returns database ID corresponding to a given identifier. + + :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 - - 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) + + @classmethod + def browse_ref(self, xid): + """ Returns a browsable record for the given identifier. + + :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): """