diff options
Diffstat (limited to 'tests/enginetests.py')
-rw-r--r-- | tests/enginetests.py | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/tests/enginetests.py b/tests/enginetests.py index ca86c9f..4a8a3ca 100644 --- a/tests/enginetests.py +++ b/tests/enginetests.py @@ -85,6 +85,60 @@ class MockProbeMgrMultiAddons(object): del self.event_dict[event_name] break +class MockProbeMgrMultiAddons(object): + """ + Mock probe manager that supports installing more than one action + at the time. + """ + def __init__(self): + self.action_dict = {} + self.event_dict = {} + self.event_cb_dict = {} + + self._action_installed_cb_list = [] + self._install_error_cb_list = [] + self._event_subscribed_cb_list = [] + self._subscribe_error_cb_list = [] + + currentActivity = property(fget=lambda s:s, fset=lambda s, v: v) + + def run_install_cb(self, action_number, action): + self._action_installed_cb_list[action_number](action, str(uuid1())) + + def run_install_error_cb(self, action_number): + self._install_error_cb_list[action_number](Exception("Could not install action...")) + + def run_subscribe_cb(self, event_number): + self._event_subscribed_cb_list[event_number](str(uuid1())) + + def run_subscribe_error(self, event_number): + self._subscribe_error_cb_list[event_number](str(uuid1())) + + def install(self, action, action_installed_cb, error_cb): + action_address = str(uuid1()) + self.action_dict[action_address] = action + self._action_installed_cb_list.append(action_installed_cb) + self._install_error_cb_list.append(error_cb) + + def update(self, action_address, new_action): + self.action_dict[action_address] = new_action + + def uninstall(self, action_address): + del self.action_dict[action_address] + + def subscribe(self, event_name, event, notif_cb, subscribe_cb, error_cb): + event_address = str(uuid1()) + self.event_dict[event_name] = event_address + self.event_cb_dict[event_name] = notif_cb + self._event_subscribed_cb_list.append(subscribe_cb) + self._subscribe_error_cb_list.append(error_cb) + + def unsubscribe(self, address): + for (event_name, other_event) in self.event_dict.values(): + if event == othet_event: + del self.event_dict[event_name] + break + class MockProbeMgr(object): def __init__(self): self.action = None @@ -172,7 +226,7 @@ class TestRunnerStates(unittest.TestCase): self.pM._action_installed_cb('action1') - assert self.runner._runner_state == engine.RUNNER_STATE_STOPPED + assert self.runner._runner_state == engine.RUNNER_STATE_IDLE def test_stop_in_events(self): self.runner.start() @@ -185,7 +239,7 @@ class TestRunnerStates(unittest.TestCase): assert self.runner._runner_state == engine.RUNNER_STATE_SETUP_EVENTS, "Tutorial should not be stopped until all events have been confirmed" self.pM.event_sub_cB('event1') - assert self.runner._runner_state == engine.RUNNER_STATE_STOPPED, "Tutorial should have been stopped right after the last event was confirmed" + assert self.runner._runner_state == engine.RUNNER_STATE_IDLE, "Tutorial should have been stopped right after the last event was confirmed" class TestInstallationStates(unittest.TestCase): def setUp(self): |