Skip to content

Commit

Permalink
IMP. Simplification of objectsock_mock
Browse files Browse the repository at this point in the history
With this simplification we allow to call custom functions, diferent
to create, write, unlink, etc.
  • Loading branch information
ecarreras committed Apr 5, 2011
1 parent 43355ae commit 4b7707c
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions ooop.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,14 @@ def __init__(self, parent, cr):

def execute(self, *args, **kargs):
"""mocking execute function"""
if len(args) == 7:
(dbname, uid, pwd, model, action, vals, fields) = args
elif len(args) == 6:
(dbname, uid, pwd, model, action, vals) = args
elif len(args) == 5:
(dbname, uid, pwd, model, action) = args

_model = self.parent.pool.get(model)

if action == 'create':
return _model.create(self.cr, uid, vals)
elif action == 'unlink':
return _model.unlink(self.cr, uid, vals)
elif action == 'write':
return _model.write(self.cr, uid, vals, fields)
elif action == 'read' and len(args) == 7:
return _model.read(self.cr, uid, vals, fields)
elif action == 'read':
return _model.read(self.cr, uid, vals)
elif action == 'search':
return _model.search(self.cr, uid, vals)
else:
return getattr(_model, action)(self.cr, uid) # is callable
uid = args[1]
model = args[3]
action = args[4]
o_model = self.pool.get(model)
newargs = (self.cr, uid, )
if args[5:]:
newargs += args[5:]
return getattr(o_model, action)(*newargs)


class OOOP:
Expand Down

0 comments on commit 4b7707c

Please sign in to comment.