[IMP] tests.common: turn class methods into instance methods (this will ease some future refactoring)

bzr revid: rco@openerp.com-20140408114936-jfagg4qvft8bk3ms
This commit is contained in:
Raphael Collet 2014-04-08 13:49:36 +02:00
parent 81b84c62b1
commit b49f536baf
3 changed files with 13 additions and 15 deletions

View File

@ -28,7 +28,7 @@ class ViewCase(common.TransactionCase):
self.assertTreesEqual(c1, c2, msg)
class TestNodeLocator(common.BaseCase):
class TestNodeLocator(common.TransactionCase):
"""
The node locator returns None when it can not find a node, and the first
match when it finds something (no jquery-style node sets)

View File

@ -102,6 +102,10 @@ class Registry(Mapping):
""" Return the model with the given name or raise KeyError if it doesn't exist."""
return self.models[model_name]
def __call__(self, model_name):
""" Same as ``self[model_name]``. """
return self.models[model_name]
def do_parent_store(self, cr):
for o in self._init_parent:
self.get(o)._parent_store_compute(cr)

View File

@ -84,18 +84,13 @@ 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.
This class is abstract and expects self.registry, self.cr and self.uid to be
initialized by subclasses.
"""
@classmethod
def cursor(self):
return openerp.modules.registry.RegistryManager.get(DB).db.cursor()
return self.registry.db.cursor()
@classmethod
def registry(self, model):
return openerp.modules.registry.RegistryManager.get(DB)[model]
@classmethod
def ref(self, xid):
""" Returns database ID corresponding to a given identifier.
@ -107,7 +102,6 @@ class BaseCase(unittest2.TestCase):
_, id = self.registry('ir.model.data').get_object_reference(self.cr, self.uid, module, xid)
return id
@classmethod
def browse_ref(self, xid):
""" Returns a browsable record for the given identifier.
@ -126,10 +120,9 @@ class TransactionCase(BaseCase):
"""
def setUp(self):
# Store cr and uid in class variables, to allow ref() and browse_ref to be BaseCase @classmethods
# and still access them
TransactionCase.cr = self.cursor()
TransactionCase.uid = openerp.SUPERUSER_ID
self.registry = openerp.modules.registry.RegistryManager.get(DB)
self.cr = self.cursor()
self.uid = openerp.SUPERUSER_ID
def tearDown(self):
self.cr.rollback()
@ -144,7 +137,8 @@ class SingleTransactionCase(BaseCase):
@classmethod
def setUpClass(cls):
cls.cr = cls.cursor()
cls.registry = openerp.modules.registry.RegistryManager.get(DB)
cls.cr = cls.registry.db.cursor()
cls.uid = openerp.SUPERUSER_ID
@classmethod