Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJCTutorius <charlie@tutorius-dev.(none)>2009-10-18 16:46:52 (GMT)
committer JCTutorius <charlie@tutorius-dev.(none)>2009-10-18 16:46:52 (GMT)
commitf7989bd6fbce8858e233ebddfd4d20bd2cb81435 (patch)
treedfb5cf9de9ecb3c205d916cf1e321889b258a801
parent1ebaff8c43b3949a956b7c2de245b6441fde0b57 (diff)
Tested vault interface function saveTutorial and added test for it in vaulttest.py
-rw-r--r--tests/vaulttests.py51
-rw-r--r--tutorius/vault.py12
2 files changed, 51 insertions, 12 deletions
diff --git a/tests/vaulttests.py b/tests/vaulttests.py
index 04a473a..3b0b4dc 100644
--- a/tests/vaulttests.py
+++ b/tests/vaulttests.py
@@ -32,7 +32,7 @@ import zipfile
# from mock import Mock
from sugar.tutorius import addon
-from sugar.tutorius.core import State, FiniteStateMachine
+from sugar.tutorius.core import State, FiniteStateMachine, Tutorial
from sugar.tutorius.actions import *
from sugar.tutorius.filters import *
from sugar.tutorius.vault import Vault, XMLSerializer, Serializer, TutorialBundler
@@ -114,6 +114,20 @@ class VaultInterfaceTest(unittest.TestCase):
self.fsm.add_state(st1)
self.fsm.add_state(st2)
self.tuto_guid = uuid1()
+
+ # Create a dummy metadata dictionnary
+ self.test_metadata_dict = {}
+ self.test_metadata_dict['name'] = 'TestTutorial1'
+ self.test_metadata_dict['guid'] = str(uuid1())
+ self.test_metadata_dict['version'] = '1'
+ self.test_metadata_dict['description'] = 'This is a test tutorial 1'
+ self.test_metadata_dict['rating'] = '3.5'
+ self.test_metadata_dict['category'] = 'Test'
+ self.test_metadata_dict['publish_state'] = 'false'
+ activities_dict = {}
+ activities_dict['org.laptop.tutoriusactivity'] = '1'
+ activities_dict['org.laptop,writus'] = '1'
+ self.test_metadata_dict['activities'] = activities_dict
def test_installTutorials(self):
@@ -204,12 +218,16 @@ class VaultInterfaceTest(unittest.TestCase):
def test_openTutorial(self):
+ """
+ Test the opening of a tutorial from the vault by passing it is guid and
+ returning the Tutorial object representation. This test verify that the
+ initial underlying FSM and the new loaded one are equivalent.
+ """
# call test_installTutorials to be sure that the tuto is now in the Vault
self.test_installTutorials()
bundler = TutorialBundler(self.tuto_guid)
test = bundler.get_tutorial_path(self.tuto_guid)
- print('Test : ' + test)
# load tutorial created in the test_installTutorial function
vault = Vault()
reloaded_tuto = vault.openTutorial(self.tuto_guid)
@@ -225,6 +243,35 @@ class VaultInterfaceTest(unittest.TestCase):
self.fsm._states.get("INIT").get_action_list()[0].message, \
'FSM underlying State underlying Action differ from original to reformed one'
assert len(reloaded_fsm.get_action_list()) == 0, "FSM should not have any actions on itself"
+
+ def test_saveTutorial(self):
+ """
+ This test verify the vault function that save a new tutorial (Tutorial object +metadata).
+ """
+
+ # Save the tutorial in the vault
+ vault = Vault()
+ tutorial = Tutorial('test', self.fsm)
+ vault.saveTutorial(tutorial, self.test_metadata_dict, None)
+
+ # Get the tutorial back
+ reloaded_tuto = vault.openTutorial(self.tuto_guid)
+
+ # Compare the two FSMs
+ reloaded_fsm = reloaded_tuto.state_machine
+
+ assert reloaded_fsm._states.get("INIT").name == self.fsm._states.get("INIT").name, \
+ 'FSM underlying dictionary differ from original to reformed one'
+ assert reloaded_fsm._states.get("Second").name == self.fsm._states.get("Second").name, \
+ 'FSM underlying dictionary differ from original to reformed one'
+ assert reloaded_fsm._states.get("INIT").get_action_list()[0].message == \
+ self.fsm._states.get("INIT").get_action_list()[0].message, \
+ 'FSM underlying State underlying Action differ from original to reformed one'
+ assert len(reloaded_fsm.get_action_list()) == 0, "FSM should not have any actions on itself"
+
+ # TODO : Compare the initial and reloaded metadata when vault.Query() will accept specifc argument
+ # (so we can specifiy that we want only the metadata for this particular tutorial
+
def tearDown(self):
diff --git a/tutorius/vault.py b/tutorius/vault.py
index 7770fb4..614d905 100644
--- a/tutorius/vault.py
+++ b/tutorius/vault.py
@@ -250,7 +250,7 @@ class Vault(object):
tuto = Tutorial(name, fsm)
return tuto
- def saveTutorial(tutorial_fsm, metadata_dict, ExternalResource):
+ def saveTutorial(self, tutorial, metadata_dict, ExternalResource):
"""
Creates a persistent version of a tutorial in the Vault.
@returns true if the tutorial was saved correctly
@@ -266,7 +266,7 @@ class Vault(object):
# Serialize the tutorial and write it to disk
xml_ser = XMLSerializer()
os.makedirs(tutorial_path)
- xml_ser.save_fsm(tutorial_fsm, TUTORIAL_FILENAME, tutorial_path)
+ xml_ser.save_fsm(tutorial.state_machine, TUTORIAL_FILENAME, tutorial_path)
# Create the metadata file
ini_file_path = os.path.join(tutorial_path, "meta.ini")
@@ -289,14 +289,6 @@ class Vault(object):
# Error, tutorial already exist
return False
-## # Writes an FSM to disk, then compares the file to the expected results.
-## # "Remove" boolean argument specify if the test data must be removed or not
-## # """
-## xml_ser = XMLSerializer()
-## os.makedirs(os.path.join(sugar.tutorius.bundler._get_store_root(), str(self.uuid)))
-## #rpdb2.start_embedded_debugger('flakyPass')
-## xml_ser.save_fsm(self.fsm, bundler.TUTORIAL_FILENAME, os.path.join(sugar.tutorius.bundler._get_store_root(), str(self.uuid)))
-
def deleteTutorial(Tutorial):
"""