diff options
Diffstat (limited to 'tests/vaulttests.py')
-rw-r--r-- | tests/vaulttests.py | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/tests/vaulttests.py b/tests/vaulttests.py index 6d69ca9..d085faf 100644 --- a/tests/vaulttests.py +++ b/tests/vaulttests.py @@ -259,6 +259,45 @@ 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_resource(self): + """ + This test verify that the vault interface function add_resource succesfully add resource in the vault + and return the new resource id. It also test the deletion of the resource. + """ + # Path of an image file in the test folder + image_path = os.path.join(os.getcwd(), 'tests', 'resources', '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 resource to the tutorial + resource_id = Vault.add_resource(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, 'resources', resource_id)), 'image file not found in vault' + + # Check if get_resource_path Vault interface function is working + vault_path = Vault.get_resource_path(self.save_test_guid, resource_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 resource + Vault.delete_resource(self.save_test_guid, resource_id) + + # Check that the resource is not in the vault anymore + assert os.path.isfile(os.path.join(tuto_path, 'resources', resource_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'); for file in os.listdir(folder): @@ -409,7 +448,7 @@ class TutorialBundlerTests(unittest.TestCase): This module contains all the tests for the storage mecanisms for tutorials This mean testing saving and loading tutorial, .ini file management and - adding ressources to tutorial + adding resources to tutorial """ def setUp(self): @@ -450,4 +489,4 @@ class TutorialBundlerTests(unittest.TestCase): if __name__ == "__main__": - unittest.main() + unittest.main() |