Skip to content

Commit

Permalink
[IMP] tests.common: turn class methods into instance methods (this wi…
Browse files Browse the repository at this point in the history
…ll ease some future refactoring)

bzr revid: rco@openerp.com-20140408114936-jfagg4qvft8bk3ms
  • Loading branch information
rco-odoo committed Apr 8, 2014
1 parent 81b84c6 commit b49f536
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion openerp/addons/base/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def assertTreesEqual(self, n1, n2, msg=None):
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)
Expand Down
4 changes: 4 additions & 0 deletions openerp/modules/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def __getitem__(self, model_name):
""" 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)
Expand Down
22 changes: 8 additions & 14 deletions openerp/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

@classmethod
def registry(self, model):
return openerp.modules.registry.RegistryManager.get(DB)[model]
return self.registry.db.cursor()

@classmethod
def ref(self, xid):
""" Returns database ID corresponding to a given identifier.
Expand All @@ -107,7 +102,6 @@ def ref(self, xid):
_, 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.
Expand All @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit b49f536

Please sign in to comment.