From 29338d21201d35d815719d5efadde70411bdda54 Mon Sep 17 00:00:00 2001 From: JCTutorius Date: Wed, 04 Nov 2009 16:34:45 +0000 Subject: vault ressssources, pending review --- (limited to 'tests/vaulttests.py') diff --git a/tests/vaulttests.py b/tests/vaulttests.py index 02c34e8..d6787ef 100644 --- a/tests/vaulttests.py +++ b/tests/vaulttests.py @@ -277,7 +277,46 @@ class VaultInterfaceTest(unittest.TestCase): # 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 test_add_delete_get_path_ressource(self): + """ + This test verify that the vault interface function add_ressource succesfully add ressource in the vault + and return the new ressource id. It also test the deletion of the ressource. + """ + # Path of an image file in the test folder + image_path = os.path.join(os.getcwd(), 'tests', 'ressources', 'icon.svg') + assert os.path.isfile(image_path), 'cannot find the test image file' + + # Create and save a tutorial + tutorial = Tutorial('test', self.fsm) + Vault.saveTutorial(tutorial, self.test_metadata_dict) + + bundler = TutorialBundler(self.save_test_guid) + tuto_path = bundler.get_tutorial_path(self.save_test_guid) + + # add the ressource to the tutorial + ressource_id = Vault.add_ressource(self.save_test_guid, image_path) + + # Check that the image file is now in the vault + assert os.path.isfile(os.path.join(tuto_path, 'ressources', ressource_id)), 'image file not found in vault' + + # Check if get_ressource_path Vault interface function is working + vault_path = Vault.get_ressource_path(self.save_test_guid, ressource_id) + + assert os.path.isfile(vault_path), 'path returned is not a file' + basename, extension = os.path.splitext(vault_path) + assert extension == '.svg', 'wrong file path have been returned' + + + # Delete the ressource + Vault.delete_ressource(self.save_test_guid, ressource_id) + + # Check that the ressource is not in the vault anymore + assert os.path.isfile(os.path.join(tuto_path, 'ressources', ressource_id)) == False, 'image file found in vault when it should have been deleted.' + + + + def tearDown(self): folder = os.path.join(os.getenv("HOME"),".sugar", 'default', 'tutorius', 'data'); @@ -362,6 +401,9 @@ class XMLSerializerTest(unittest.TestCase): shutil.rmtree(file_path) def create_test_metadata(self, ini_file_path, guid): + """ + Create a basinc .ini file for testing purpose. + """ ini_file = open(ini_file_path, 'wt') ini_file.write("[GENERAL_METADATA]\n") ini_file.write('guid=' + str(guid) + '\n') @@ -513,4 +555,4 @@ class TutorialBundlerTests(unittest.TestCase): if __name__ == "__main__": - unittest.main() + unittest.main() \ No newline at end of file -- cgit v0.9.1