From 2b9967bf9c0b08766003085c141afe56483b30a1 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 29 Aug 2014 09:59:55 +0200 Subject: [PATCH 1/2] allow to execute scenario without logging in odoo. It can be used to execute sql to repair a database or to create the database before logging in. For this add a tag @no_login to you scenario --- features/environment.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/features/environment.py b/features/environment.py index a4bc109..fceb71a 100644 --- a/features/environment.py +++ b/features/environment.py @@ -26,14 +26,6 @@ def _output_write(text): 'db_name': database, 'openerp_config': server.tools.config, } - # We try to manage default login - # even if there is a sentence to log a given user - # Just add options.admin_login_password in your buildout to log from config - admin_login_password = server.tools.config.get('admin_login_password') - if admin_login_password: - ctx.client.login('admin', admin_login_password, database=database) - else: - ctx.client.login('admin', 'admin', database=database) def before_feature(ctx, feature): @@ -45,6 +37,20 @@ def before_scenario(ctx, scenario): ctx.oe_context = {} if not hasattr(ctx, 'data'): ctx.data = {} + # do not login if tag `no_login` is present + # this allow to do database creation and sql requests + # before trying to login in Odoo + if not ctx.client.user and 'no_login' not in scenario.tags: + server = ctx.conf['server'] + database = ctx.conf['db_name'] + # We try to manage default login + # even if there is a sentence to log a given user + # Just add options.admin_login_password in your buildout to log from config + admin_login_password = server.tools.config.get('admin_login_password') + if admin_login_password: + ctx.client.login('admin', admin_login_password, database=database) + else: + ctx.client.login('admin', 'admin', database=database) def before_step(ctx, step): From c0a4032f2b55b34f665de5ac36de71e408322a52 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Fri, 29 Aug 2014 10:00:53 +0200 Subject: [PATCH 2/2] refactor get of admin_login_password --- features/environment.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/features/environment.py b/features/environment.py index fceb71a..c927c2c 100644 --- a/features/environment.py +++ b/features/environment.py @@ -43,14 +43,13 @@ def before_scenario(ctx, scenario): if not ctx.client.user and 'no_login' not in scenario.tags: server = ctx.conf['server'] database = ctx.conf['db_name'] + config = server.tools.config # We try to manage default login # even if there is a sentence to log a given user - # Just add options.admin_login_password in your buildout to log from config - admin_login_password = server.tools.config.get('admin_login_password') - if admin_login_password: - ctx.client.login('admin', admin_login_password, database=database) - else: - ctx.client.login('admin', 'admin', database=database) + # Just add options.admin_login_password in your buildout to log from + # config + admin_login_password = config.get('admin_login_password', 'admin') + ctx.client.login('admin', admin_login_password, database=database) def before_step(ctx, step):