diff options
author | JCTutorius <charlie@tutorius-dev.(none)> | 2009-10-23 19:05:34 (GMT) |
---|---|---|
committer | JCTutorius <charlie@tutorius-dev.(none)> | 2009-10-23 19:05:34 (GMT) |
commit | c16f29574cd9f8de15507e0d50139eeabfc2d266 (patch) | |
tree | 630c177b0dd0a0aec9527f9563ff94604e68ad2c | |
parent | a2d2561b08620f3f7d6e0e2ffd86758b3e6d506f (diff) |
Vault function add_ressource is now functional and tested in vaulttests.py
-rw-r--r-- | tests/ressources/icon.svg | 21 | ||||
-rw-r--r-- | tests/vaulttests.py | 22 | ||||
-rw-r--r-- | tutorius/vault.py | 24 |
3 files changed, 56 insertions, 11 deletions
diff --git a/tests/ressources/icon.svg b/tests/ressources/icon.svg new file mode 100644 index 0000000..bb28f04 --- /dev/null +++ b/tests/ressources/icon.svg @@ -0,0 +1,21 @@ +<?xml version="1.0" ?><!-- Created with Inkscape (http://www.inkscape.org/) --><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [ + <!ENTITY stroke_color "#000000"> + <!ENTITY fill_color "#ffffff"> +]><svg height="55px" id="svg2393" inkscape:output_extension="org.inkscape.output.svg.inkscape" inkscape:version="0.47pre1 r21720" sodipodi:docname="tutortool.svg" sodipodi:version="0.32" version="1.1" width="55px" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:svg="http://www.w3.org/2000/svg"> + <defs id="defs2395"> + <inkscape:perspective id="perspective2401" inkscape:persp3d-origin="16 : 10.666667 : 1" inkscape:vp_x="0 : 16 : 1" inkscape:vp_y="0 : 1000 : 0" inkscape:vp_z="32 : 16 : 1" sodipodi:type="inkscape:persp3d"/> + </defs> + <sodipodi:namedview bordercolor="#666666" borderopacity="1.0" id="base" inkscape:current-layer="layer1" inkscape:cx="3.7661233" inkscape:cy="33.132055" inkscape:document-units="px" inkscape:grid-bbox="true" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:window-height="675" inkscape:window-maximized="0" inkscape:window-width="1057" inkscape:window-x="108" inkscape:window-y="45" inkscape:zoom="3.9590209" pagecolor="#ffffff" showgrid="true"/> + <metadata id="metadata2398"> + <rdf:RDF> + <cc:Work rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/> + </cc:Work> + </rdf:RDF> + </metadata> + <g id="layer1" inkscape:groupmode="layer" inkscape:label="Layer 1" transform="translate(0,23)"> + <path d="m 38.01548,1.5478747 c 0,7.1837999 -7.3667,13.0141283 -16.443525,13.0141283 -2.269208,0 -8.124729,3.152936 -13.9608513,4.252763 C 13.382177,14.110994 11.434521,11.926642 9.9463815,10.748864 6.9701032,8.3933076 5.1284282,5.1397735 5.1284282,1.5478747 c 0,-7.1837994 7.3666998,-13.0141297 16.4435268,-13.0141297 9.076825,0 16.443525,5.8303303 16.443525,13.0141297 z" id="path2403" sodipodi:nodetypes="cscsssc" style="fill:&fill_color;;fill-opacity:1;fill-rule:nonzero;stroke:&stroke_color;;stroke-width:1.96931934;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/> + <path d="m 50.150276,6.4721386 c 0,2.621116 -1.428036,4.9953144 -3.735846,6.7142344 -1.153905,0.85946 -1.824287,2.434433 1.398853,6.784273 -6.258422,-3.991066 -8.65379,-4.001712 -10.413335,-4.001712 -7.03818,0 -12.750327,-4.254565 -12.750327,-9.4967954 0,-5.2422321 5.712147,-9.4967971 12.750327,-9.4967971 7.038182,0 12.750328,4.254565 12.750328,9.4967971 z" id="path3175" sodipodi:nodetypes="cccsssc" style="fill:&fill_color;;fill-opacity:1;fill-rule:nonzero;stroke:&stroke_color;;stroke-width:1.96931934;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/> + </g> +</svg>
\ No newline at end of file diff --git a/tests/vaulttests.py b/tests/vaulttests.py index 70a81f1..b56def2 100644 --- a/tests/vaulttests.py +++ b/tests/vaulttests.py @@ -283,8 +283,25 @@ class VaultInterfaceTest(unittest.TestCase): This test verify that the vault interface function add_ressource succesfully add ressource in the vault and return the new ressource id. """ + # 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 + vault = Vault() + 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' + - def tearDown(self): folder = os.path.join(os.getenv("HOME"),".sugar", 'default', 'tutorius', 'data'); @@ -369,6 +386,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') diff --git a/tutorius/vault.py b/tutorius/vault.py index e6f4505..47665fc 100644 --- a/tutorius/vault.py +++ b/tutorius/vault.py @@ -62,6 +62,7 @@ NODE_COMPONENT = "Component" NODE_SUBCOMPONENT = "property" NODE_SUBCOMPONENTLIST = "listproperty" NEXT_STATE_ATTR = "next_state" +RESSOURCES_FOLDER = 'ressources' class Vault(object): @@ -327,7 +328,7 @@ class Vault(object): Returns a unique name for this resource composed from the original name of the file and a suffix to make it unique ( ex: name_1.jpg ) and add it to the resources for the tutorial. @param tutorial_guid The guid of the tutorial - @param file_path the fiel path of the ressource to add + @param file_path the file path of the ressource to add @returns the ressource_id of the ressource """ @@ -337,16 +338,19 @@ class Vault(object): # Get the file name fname_splitted = file_path.rsplit('/') file_name = fname_splitted[fname_splitted.__len__() - 1] + base_name, extension = os.path.splitext(file_name) # Append unique name to file name - file_name_appended = file_name + '_' + str(uuid.uuid1()) - # Check if the ressource file exists - file_path = os.path.join(tutorial_path, ressource_id) - if os.path.isfile(file_path): + file_name_appended = base_name + '_' + str(uuid.uuid1()) + extension + # Check if the ressource file already exists + new_file_path = os.path.join(tutorial_path, RESSOURCES_FOLDER, file_name_appended) + if os.path.isfile(new_file_path) == False: # Copy the ressource file in the vault - shutil.copyfile(file_path, os.path.join(tutorial_path, file_name_appended)) - return file_name_appended - else: - return None + if os.path.isdir(os.path.join(tutorial_path, RESSOURCES_FOLDER)) == False: + os.makedirs(os.path.join(tutorial_path, RESSOURCES_FOLDER)) + assert os.path.isfile(file_path) + shutil.copyfile(file_path, new_file_path) + + return file_name_appended @staticmethod @@ -378,7 +382,7 @@ class Vault(object): bundler = TutorialBundler(tutorial_guid) tutorial_path = bundler.get_tutorial_path(tutorial_guid) # Check if the ressource file exists - file_path = os.path.join(tutorial_path, ressource_id) + file_path = os.path.join(tutorial_path, RESSOURCES_FOLDER, ressource_id) if os.path.isfile(file_path): return file_path else: |