From ab9a89a1271408f76d10b03a6adbf65b930887ba Mon Sep 17 00:00:00 2001 From: Ghislain Rodrigues Date: Sat, 16 Apr 2016 10:21:39 +0100 Subject: [PATCH 1/4] the action is initialised to None in the engine --- core/Rpg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Rpg.py b/core/Rpg.py index 193d992..7fbd8bb 100644 --- a/core/Rpg.py +++ b/core/Rpg.py @@ -24,7 +24,7 @@ def __init__(self, debug=False): self._savedGame = None self._player = player() self._debug = debug - self._action = [] + self._action = None fight.fight.stopFight() area.resetChangedAreas() container.resetChangedContainers() From fcb6b8f6f119abf1f658cc92e90420f21d7e0378 Mon Sep 17 00:00:00 2001 From: Ghislain Rodrigues Date: Sat, 16 Apr 2016 10:23:55 +0100 Subject: [PATCH 2/4] once the action is run, reset it to None --- core/Rpg.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/Rpg.py b/core/Rpg.py index 7fbd8bb..57c26d7 100644 --- a/core/Rpg.py +++ b/core/Rpg.py @@ -110,6 +110,8 @@ def _runAction(self, renderJson=False): self._savedGame['id_saved_game'] ) + self._action = None + if c == command_factory.quit: return c From 6138820146e63033bbe7a5e6137b3c472a7bbc87 Mon Sep 17 00:00:00 2001 From: Ghislain Rodrigues Date: Sat, 16 Apr 2016 10:24:15 +0100 Subject: [PATCH 3/4] if the action is not set when calling _runAction, throw an exception --- core/Rpg.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/Rpg.py b/core/Rpg.py index 57c26d7..6d83006 100644 --- a/core/Rpg.py +++ b/core/Rpg.py @@ -102,6 +102,8 @@ def _runAction(self, renderJson=False): raise core.exception.exception(_('ERROR_SAVED_GAME_NEEDED_TO_RUN_ACTION')) elif not self._player.isConnected(): raise core.exception.exception(_('ERROR_CONNECTED_PLAYER_NEEDED_FOR_COMMAND')) + elif self._action is None: + raise core.exception.exception(_('ERROR_NO_ACTION_SET')) try: c = command_factory.factory.create( From b15ab2f86b71818ba808ffbe1422106f3ba2dc50 Mon Sep 17 00:00:00 2001 From: Ghislain Rodrigues Date: Sat, 16 Apr 2016 10:24:47 +0100 Subject: [PATCH 4/4] test added to make sure an exception is thrown if _runAction is ran with no action set --- tests/core/testRpg.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/core/testRpg.py b/tests/core/testRpg.py index 9a37681..36e5d1c 100644 --- a/tests/core/testRpg.py +++ b/tests/core/testRpg.py @@ -130,3 +130,8 @@ def test_command_with_no_player(self): with self.assertRaises(core.exception.exception) as raised: rpgEngine._runAction(True) self.assertEquals(str(raised.exception), _('ERROR_CONNECTED_PLAYER_NEEDED_FOR_COMMAND')) + + def test_run_action_with_no_action(self): + with self.assertRaises(core.exception.exception) as raised: + self.rpg._runAction() + self.assertEquals(str(raised.exception), _('ERROR_NO_ACTION_SET'))