[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:
parent
81b84c62b1
commit
b49f536baf
|
@ -28,7 +28,7 @@ class ViewCase(common.TransactionCase):
|
||||||
self.assertTreesEqual(c1, c2, msg)
|
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
|
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)
|
match when it finds something (no jquery-style node sets)
|
||||||
|
|
|
@ -102,6 +102,10 @@ class Registry(Mapping):
|
||||||
""" Return the model with the given name or raise KeyError if it doesn't exist."""
|
""" Return the model with the given name or raise KeyError if it doesn't exist."""
|
||||||
return self.models[model_name]
|
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):
|
def do_parent_store(self, cr):
|
||||||
for o in self._init_parent:
|
for o in self._init_parent:
|
||||||
self.get(o)._parent_store_compute(cr)
|
self.get(o)._parent_store_compute(cr)
|
||||||
|
|
|
@ -84,18 +84,13 @@ class BaseCase(unittest2.TestCase):
|
||||||
"""
|
"""
|
||||||
Subclass of TestCase for common OpenERP-specific code.
|
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):
|
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):
|
def ref(self, xid):
|
||||||
""" Returns database ID corresponding to a given identifier.
|
""" 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)
|
_, id = self.registry('ir.model.data').get_object_reference(self.cr, self.uid, module, xid)
|
||||||
return id
|
return id
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def browse_ref(self, xid):
|
def browse_ref(self, xid):
|
||||||
""" Returns a browsable record for the given identifier.
|
""" Returns a browsable record for the given identifier.
|
||||||
|
|
||||||
|
@ -126,10 +120,9 @@ class TransactionCase(BaseCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# Store cr and uid in class variables, to allow ref() and browse_ref to be BaseCase @classmethods
|
self.registry = openerp.modules.registry.RegistryManager.get(DB)
|
||||||
# and still access them
|
self.cr = self.cursor()
|
||||||
TransactionCase.cr = self.cursor()
|
self.uid = openerp.SUPERUSER_ID
|
||||||
TransactionCase.uid = openerp.SUPERUSER_ID
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.cr.rollback()
|
self.cr.rollback()
|
||||||
|
@ -144,7 +137,8 @@ class SingleTransactionCase(BaseCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
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
|
cls.uid = openerp.SUPERUSER_ID
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in New Issue