From 04a027a1052428e359f883cb5d53ed054e518ee8 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Wed, 21 Dec 2016 10:07:57 +0100 Subject: [PATCH] Validate wizard definition on module tests issue6067 review32831002 --- CHANGELOG | 1 + trytond/ir/ui/view.py | 5 ++++- trytond/tests/test_tryton.py | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index cc00f17975..dac36798aa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Validate wizard definition on module tests * Remove order constraint on register ModelSQL * Add relate from report to translations diff --git a/trytond/ir/ui/view.py b/trytond/ir/ui/view.py index 395bca5ce3..5305b367e4 100644 --- a/trytond/ir/ui/view.py +++ b/trytond/ir/ui/view.py @@ -240,7 +240,10 @@ class ShowView(Wizard): def get_view(self, wizard, state_name): pool = Pool() View = pool.get('ir.ui.view') - view = View(Transaction().context.get('active_id')) + view_id = Transaction().context.get('active_id') + if not view_id: + return {} + view = View(view_id) Model = pool.get(view.model) return Model.fields_view_get(view_id=view.id) diff --git a/trytond/tests/test_tryton.py b/trytond/tests/test_tryton.py index fa11f22171..2fe5552f01 100644 --- a/trytond/tests/test_tryton.py +++ b/trytond/tests/test_tryton.py @@ -22,6 +22,7 @@ from trytond.tools import is_instance_method from trytond.transaction import Transaction from trytond.cache import Cache from trytond.config import config, parse_uri +from trytond.wizard import StateView, StateAction __all__ = ['POOL', 'DB_NAME', 'USER', 'CONTEXT', 'activate_module', 'ModuleTestCase', 'with_transaction', @@ -383,6 +384,27 @@ class ModuleTestCase(unittest.TestCase): 'model': model.__name__, }) + @with_transaction() + def test_wizards(self): + 'Test wizards are correctly defined' + for wizard_name, wizard in Pool().iterobject(type='wizard'): + if not isregisteredby(wizard, self.module, type_='wizard'): + continue + session_id, start_state, _ = wizard.create() + assert start_state in wizard.states, ('Unknown start state ' + '"%(state)s" on wizard "%(wizard)s"' % { + 'state': start_state, + 'wizard': wizard_name, + }) + wizard_instance = wizard(session_id) + for state_name, state in wizard_instance.states.iteritems(): + if isinstance(state, StateView): + # Don't test defaults as they may depend on context + state.get_view(wizard_instance, state_name) + state.get_buttons(wizard_instance, state_name) + if isinstance(state, StateAction): + state.get_action() + def db_exist(name=DB_NAME): Database = backend.get('Database')