From c16ef18b33858618cb3ec11d81648b9cf14abf7e Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Fri, 21 Oct 2016 18:06:38 +0200 Subject: [PATCH] [IMP] Monkey patch BaseModel in _setup_complete so the suspend_security method is available in tests without calling the _register_hook Indeed tests are run after the call to _setup_complete and before the call to _register_hook --- base_suspend_security/README.rst | 1 + base_suspend_security/models/ir_rule.py | 4 ++-- base_suspend_security/tests/test_base_suspend_security.py | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/base_suspend_security/README.rst b/base_suspend_security/README.rst index 886d71103..8e4bf7fef 100644 --- a/base_suspend_security/README.rst +++ b/base_suspend_security/README.rst @@ -39,6 +39,7 @@ Contributors ------------ * Holger Brunn +* Laurent Mignon Maintainer ---------- diff --git a/base_suspend_security/models/ir_rule.py b/base_suspend_security/models/ir_rule.py index 86c0ff2d8..7ce16f742 100644 --- a/base_suspend_security/models/ir_rule.py +++ b/base_suspend_security/models/ir_rule.py @@ -30,9 +30,9 @@ class IrRule(models.Model): return [], [], ['"%s"' % self.pool[model_name]._table] return super(IrRule, self).domain_get(model_name, mode=mode) - def _register_hook(self, cr): + def _setup_complete(self, cr, uid): if not hasattr(models.BaseModel, SUSPEND_METHOD): setattr(models.BaseModel, SUSPEND_METHOD, lambda self: self.sudo( user=BaseSuspendSecurityUid(self.env.uid))) - return super(IrRule, self)._register_hook(cr) + return super(IrRule, self)._setup_complete(cr, uid) diff --git a/base_suspend_security/tests/test_base_suspend_security.py b/base_suspend_security/tests/test_base_suspend_security.py index 7621c052a..cdc0a31db 100644 --- a/base_suspend_security/tests/test_base_suspend_security.py +++ b/base_suspend_security/tests/test_base_suspend_security.py @@ -24,7 +24,6 @@ from openerp.tests.common import TransactionCase class TestBaseSuspendSecurity(TransactionCase): def test_base_suspend_security(self): # tests are called before register_hook - self.env['ir.rule']._register_hook() user_id = self.env.ref('base.user_demo').id other_company = self.env['res.company'].create({ 'name': 'other company',