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-11-06 02:21:08 (GMT)
committer JCTutorius <charlie@tutorius-dev.(none)>2009-11-06 02:21:08 (GMT)
commit7aad5a2f6a93ae3385794f94f8b175c243165532 (patch)
tree0ea47c2adbfee2780fac2675e2ca860dc1a39b15
parent29aea8f7d71d5584e011a6955999e37efe6343f9 (diff)
Made change after Charlie code review.
-rw-r--r--tests/vaulttests.py67
-rw-r--r--tutorius/vault.py19
2 files changed, 52 insertions, 34 deletions
diff --git a/tests/vaulttests.py b/tests/vaulttests.py
index 5fdb7f9..e45adcb 100644
--- a/tests/vaulttests.py
+++ b/tests/vaulttests.py
@@ -305,33 +305,7 @@ class VaultInterfaceTest(unittest.TestCase):
# If false, new metadata hasn't been found in the vault
assert new_metadata_found == True, 'Modified metadata not found in the vault'
-
-
- def test_get_tutorial_archive(self):
- """
- This test verify that the vault interface function get_tutorial_archive zip a tutorial and
- return the zipped archive object succesfully.
- """
- # Create and save a tutorial
- tutorial = Tutorial('test')
- Vault.saveTutorial(tutorial, self.test_metadata_dict)
-
- bundler = TutorialBundler(self.save_test_guid)
-
- # Test get_tutorial_archive()
- archive_object = Vault.get_tutorial_archive(self.save_test_guid)
-
- # Write the archive data as a new file
- zip_path = str(self.save_test_guid) + '_test_.zip'
- file = open(zip_path, 'wt')
- file.write(archive_object)
- file.close()
-
- # Test if new zip is valid
- assert zipfile.is_zipfile(zip_path)
- # Remove test file
- os.remove(zip_path)
-
+
def test_add_delete_get_path_resource(self):
"""
@@ -347,8 +321,6 @@ class VaultInterfaceTest(unittest.TestCase):
resource_file = open(file_path, 'wt')
resource_file.write('test')
resource_file.close()
- #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')
@@ -375,7 +347,44 @@ class VaultInterfaceTest(unittest.TestCase):
# 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 test_get_tutorial_archive(self):
+ """
+ This test verify that the vault interface function get_tutorial_archive zip a tutorial and
+ return the zipped archive object succesfully.
+ """
+ # Create and save a tutorial
+ tutorial = Tutorial('test')
+ Vault.saveTutorial(tutorial, self.test_metadata_dict)
+
+ bundler = TutorialBundler(self.save_test_guid)
+
+ # Add test ressources to the tutorial
+ test_path = os.path.join(os.getenv("HOME"),".sugar", 'default', 'tutorius', 'tmp')
+ if os.path.isdir(test_path) == True:
+ shutil.rmtree(os.path.join(os.getenv("HOME"),".sugar", 'default', 'tutorius', 'tmp'))
+ os.makedirs(test_path)
+ file_path = os.path.join(test_path, 'test_resource.svg')
+ resource_file = open(file_path, 'wt')
+ resource_file.write('test')
+ resource_file.close()
+ resource_id = Vault.add_resource(self.save_test_guid, file_path)
+
+ # Test get_tutorial_archive()
+ archive_object = Vault.get_tutorial_archive(self.save_test_guid)
+
+ # Write the archive data as a new file
+ zip_path = str(self.save_test_guid) + '_test_.zip'
+ file = open(zip_path, 'wt')
+ file.write(archive_object)
+ file.close()
+
+ # Test if new zip is valid
+ assert zipfile.is_zipfile(zip_path)
+ # Remove test file
+ os.remove(zip_path)
+
def tearDown(self):
diff --git a/tutorius/vault.py b/tutorius/vault.py
index c0409da..fbe9e75 100644
--- a/tutorius/vault.py
+++ b/tutorius/vault.py
@@ -367,8 +367,8 @@ class Vault(object):
parser.set(INI_ACTIVITY_SECTION, related_key, related_value)
# Delete the old metadata file
- if os.path.isfile(ini_file_path):
- os.remove(ini_file_path)
+## if os.path.isfile(ini_file_path):
+## os.remove(ini_file_path)
# Write the new metadata file to disk
with open(ini_file_path, 'wb') as configfile:
@@ -391,15 +391,24 @@ class Vault(object):
bundle_path = bundle.get_tutorial_path(guid)
#Zip the tutorials files in the pkzip file format in a temp file
- archive_list = [os.path.join(bundle_path, 'meta.ini'), os.path.join(bundle_path, 'tutorial.xml')] #, os.path.join(bundle_path, RESOURCES_FOLDER)]
+ archive_list = [os.path.join(bundle_path, 'meta.ini'), os.path.join(bundle_path, 'tutorial.xml')]
+
+ # Add all the files in the archive folder
+ for root, dirs, files in os.walk(os.path.join(bundle_path, RESOURCES_FOLDER)):
+ for name in files:
+ archive_list.append(os.path.join(bundle_path, RESOURCES_FOLDER, name))
zfilename = str(guid) + ".zip"
zout = zipfile.ZipFile(os.path.join(bundle_path, zfilename), "w")
for fname in archive_list:
fname_splitted = fname.rsplit('/')
- file_only_name = fname_splitted[fname_splitted.__len__() - 1]
- zout.write(fname, file_only_name)
+ if fname_splitted[-2] == RESOURCES_FOLDER:
+ ressource_path_and_file = os.path.join(fname_splitted[-2], fname_splitted[-1])
+ zout.write(fname, ressource_path_and_file)
+ else:
+ file_only_name = fname_splitted[-1]
+ zout.write(fname, file_only_name)
zout.close()
# test if the temp file is a valid pkzip file