[ADD] tests: shitty support for context

The API doesn't correctly match the server-side `Environment`/`Model`
API, but neither did `with_user`, so probably fine for now, can
revisit this thing if I start needing it more than once in a blue
moon.
This commit is contained in:
Xavier Morel 2025-01-28 15:53:04 +01:00
parent 86796ed730
commit 62dd3ee636

View File

@ -1238,12 +1238,18 @@ class Environment:
self._password = None
self._object = xmlrpc.client.ServerProxy(f'http://localhost:{port}/xmlrpc/2/object')
self.login('admin', 'admin')
self._context = {}
def with_user(self, login, password):
env = copy.copy(self)
env.login(login, password)
return env
def with_context(self, **kw):
env = copy.copy(self)
env._context = {**self._context, **kw}
return env
def login(self, login, password):
self._password = password
self._uid = xmlrpc.client.ServerProxy(
@ -1251,6 +1257,7 @@ class Environment:
).authenticate(self._db, login, password, {})
def __call__(self, model, method, *args, **kwargs):
kwargs['context'] = {**self._context, **kwargs.get('context', {})}
return self._object.execute_kw(
self._db, self._uid, self._password,
model, method,