diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/enginetests.py | 58 | ||||
-rw-r--r-- | tests/linear_creatortests.py | 79 | ||||
-rw-r--r-- | tests/vaulttests.py | 66 |
3 files changed, 112 insertions, 91 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): diff --git a/tests/linear_creatortests.py b/tests/linear_creatortests.py deleted file mode 100644 index e3c30c1..0000000 --- a/tests/linear_creatortests.py +++ /dev/null @@ -1,79 +0,0 @@ -# Copyright (C) 2009, Tutorius.org -# Greatly influenced by sugar/activity/namingalert.py -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -from sugar.tutorius.core import * -from sugar.tutorius.actions import * -from sugar.tutorius.filters import * -from sugar.tutorius.linear_creator import * -from sugar.tutorius.addons.triggereventfilter import * -from actiontests import CountAction -import unittest - -class CreatorTests(unittest.TestCase): - - def test_simple_usage(self): - creator = LinearCreator() - fsm_name = "SimpleUsageTest" - - creator.set_name(fsm_name) - - # Generate an FSM using the steps - creator.action(CountAction()) - creator.action(CountAction()) - - creator.event(TriggerEventFilter()) - - creator.action(CountAction()) - - creator.event(TriggerEventFilter()) - - fsm = creator.generate_fsm() - - # Make sure everything worked! - assert fsm.name == fsm_name, "Name was not set properly" - - init_state = fsm.get_state_by_name("INIT") - - assert len(init_state.get_action_list()) == 2, "Creator did not insert all the actions" - - assert init_state.get_event_filter_list()[0][1] == "State 1" , "expected next state to be 'State 1' but got %s" % init_state.get_event_filter_list()[0][1] - - state1 = fsm.get_state_by_name("State 1") - - assert len(state1.get_action_list()) == 1, "Creator did not insert all the actions" - - assert state1.get_event_filter_list()[0][1] == "State 2" - - # Make sure we have the final state and that it's empty - state2 = fsm.get_state_by_name("State2") - - assert len(state2.get_action_list()) == 0, "Creator inserted extra actions on wrong state" - - assert len(state2.get_event_filter_list()) == 0, "Creator assigner events to the final state" - - creator.action(CountAction()) - - fsm = creator.generate_fsm() - - state2 = fsm.get_state_by_name("State2") - - assert len(state2.get_action_list()) == 1, "Creator did not add the action" - - assert len(state2.get_event_filter_list()) == 0, "Creator assigner events to the final state" - -if __name__ == '__main__': - unittest.main() diff --git a/tests/vaulttests.py b/tests/vaulttests.py index e8e732e..729d36d 100644 --- a/tests/vaulttests.py +++ b/tests/vaulttests.py @@ -92,7 +92,7 @@ class VaultInterfaceTest(unittest.TestCase): ini_file2.write('guid=' + str(self.test_guid2) + '\n') ini_file2.write('name=TestTutorial2\n') ini_file2.write('version=2\n') - ini_file2.write('description=This is a test tutorial 2\n') + ini_file2.write('description=This is a test tutorial 2. FOR_TEST\n') ini_file2.write('rating=4\n') ini_file2.write('category=Test2\n') ini_file2.write('publish_state=false\n') @@ -125,7 +125,7 @@ class VaultInterfaceTest(unittest.TestCase): self.test_metadata_dict['publish_state'] = 'false' activities_dict = {} activities_dict['org.laptop.tutoriusactivity'] = '1' - activities_dict['org.laptop,writus'] = '1' + activities_dict['org.laptop.writus'] = '1' self.test_metadata_dict['activities'] = activities_dict @@ -142,7 +142,7 @@ class VaultInterfaceTest(unittest.TestCase): shutil.rmtree(os.path.join(os.getenv("HOME"),".sugar", 'default', 'tutorius', 'tmp')) os.makedirs(test_path) - # Creat a dummy tutorial .xml file + # Create a dummy tutorial .xml file serializer = XMLSerializer() with file(os.path.join(test_path, 'tutorial.xml'), 'w') as fsmfile: @@ -159,7 +159,7 @@ class VaultInterfaceTest(unittest.TestCase): zout = zipfile.ZipFile(os.path.join(test_path, zfilename), "w") for fname in archive_list: fname_splitted = fname.rsplit('/') - file_only_name = fname_splitted[fname_splitted.__len__() - 1] + file_only_name = fname_splitted[-1] zout.write(fname, file_only_name) zout.close() @@ -186,12 +186,10 @@ class VaultInterfaceTest(unittest.TestCase): correspond to the specified parameters. """ - # Note : Temporary only test query that return ALL tutorials in the vault. - # TODO : Test with varying parameters - + # Test the return of all the tutorials tutorial_list = Vault.query() - if tutorial_list.__len__() < 2: + if len(tutorial_list) < 2: assert False, 'Error, list doesnt have enough tutorial in it : ' + str(tutorial_list.__len__()) + ' element' for tuto_dictionnary in tutorial_list: @@ -208,7 +206,7 @@ class VaultInterfaceTest(unittest.TestCase): elif tuto_dictionnary['name'] == 'TestTutorial2': related = tuto_dictionnary['activities'] assert tuto_dictionnary['version'] == '2' - assert tuto_dictionnary['description'] == 'This is a test tutorial 2' + assert tuto_dictionnary['description'] == 'This is a test tutorial 2. FOR_TEST' assert tuto_dictionnary['rating'] == '4' assert tuto_dictionnary['category'] == 'Test2' assert tuto_dictionnary['publish_state'] == 'false' @@ -218,7 +216,55 @@ class VaultInterfaceTest(unittest.TestCase): else: assert False, 'list is empty or name property is wrong' - + + # Test the return of just a given tutorial with a given keyword present in one + # or more of is metadata fields. + tutorial_list = Vault.query(keyword=['FOR_TEST']) + + # Should return only tutorial with metadata like tutorial # 2 + if len(tutorial_list) == 0: + assert False, 'Error on keyword, at least 1 tutorial should has been returned. ' + related = tutorial_list[0]['activities'] + assert tutorial_list[0]['version'] == '2' + assert tutorial_list[0]['description'] == 'This is a test tutorial 2. FOR_TEST' + assert tutorial_list[0]['rating'] == '4' + assert tutorial_list[0]['category'] == 'Test2' + assert tutorial_list[0]['publish_state'] == 'false' + assert related.has_key('org.laptop.tutoriusactivity') + assert related.has_key('org.laptop.writus') + assert related.has_key('org.laptop.testus') + + # Test the return of just a given tutorial with a given related activity in is metadata + tutorial_list = Vault.query(relatedActivityNames=['org.laptop.testus']) + + # Should return only tutorials like tutorial # 2 + if len(tutorial_list) == 0: + assert False, 'Error on related activity, at least 1 tutorial should has been returned. ' + related = tutorial_list[0]['activities'] + assert tutorial_list[0]['version'] == '2' + assert tutorial_list[0]['description'] == 'This is a test tutorial 2. FOR_TEST' + assert tutorial_list[0]['rating'] == '4' + assert tutorial_list[0]['category'] == 'Test2' + assert tutorial_list[0]['publish_state'] == 'false' + assert related.has_key('org.laptop.tutoriusactivity') + assert related.has_key('org.laptop.writus') + assert related.has_key('org.laptop.testus') + + # Test the return of just a given tutorial with a given category in is metadata + tutorial_list = Vault.query(category=['test']) + + # Should return only tutorials like tutorial # 1 + if len(tutorial_list) == 0: + assert False, 'Error on category, at least 1 tutorial should has been returned. ' + related = tutorial_list[0]['activities'] + assert tutorial_list[0]['version'] == '1' + assert tutorial_list[0]['description'] == 'This is a test tutorial 1' + assert tutorial_list[0]['rating'] == '3.5' + assert tutorial_list[0]['category'] == 'Test' + assert tutorial_list[0]['publish_state'] == 'false' + assert related.has_key('org.laptop.tutoriusactivity') + assert related.has_key('org.laptop.writus') + def test_loadTutorial(self): """ |