Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/bundlertests.py
blob: ad8d1bb085ece822ca9a61cf0e5df514abd8f0da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Copyright (C) 2009, Tutorius.org
# Copyright (C) 2009, Charles-Etienne Carriere <iso.swiffer@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
"""
Bundler tests

This module contains all the tests for the storage mecanisms for tutorials
This mean testing savins and loading tutorial, .ini file management and
adding ressources to tutorial
"""

import unittest
import os
import uuid

from sugar.tutorius import bundler 

##class VaultTests(unittest.TestCase):
##    def setUp(self):
##        pass
##
##    def tearDown(self):
##        pass
##
##    def test_basicQuery(self):
##        vault = Vault()
##        
##        list_metadata = vault.query(keyword='tutorial', startIndex=2, numResults=5)
##
##        assert len(list_metadata) <= 5
##    
##    def test_advancedQuery(self):
##        vault = Vault()
##    
##        list_metadata = vault.query(keyword='', category='Math', startIndex=10, numResults=10)
##
##        assert len(list_metadata) <= 10
##
##        pass
##    
##    def test_installTutorial(self):
##        # Create a new tutorial
##        
##
##        xml_serializer = XmlSerializer()
##
##        
##        xml_serializer.save_fsm()
##
##    def test_deleteTutorial(self):
##        pass
##    
##    def test_saveTutorial(self):
##        pass
##
##    def test_readTutorial(self):
##        pass
##
##    def _generateSampleTutorial(self):
##        """
##        Creates a new tutorial and bundles it.
##        
##        @return The UUID for the new tutorial.
##        """
##        self._fsm = FiniteStateMachine("Sample testing FSM")
##        # Add a few states
##        act1 = addon.create('BubbleMessage', message="Hi", pos=[300, 450])
##        ev1 = addon.create('GtkWidgetEventFilter', "0.12.31.2.2", "clicked", "FINAL")
##        act2 = addon.create('BubbleMessage', message="Second message", pos=[250, 150], tailpos=[1,2])
##
##        st1 = State("INIT")
##        st1.add_action(act1)
##        st1.add_event_filter(ev1)
##        
##        st2 = State("FINAL")
##        st2.add_action(act2)
##        
##        self._fsm.add_state(st1)
##        self._fsm.add_state(st2)
##
##        xml_ser = XmlSerializer()
##
##        os.makedirs(os.path.join(sugar.tutorius.bundler._get_store_root(), str(self.uuid)))
##
##        # xml_ser.save_fsm(self._fsm, TUTORIAL_FILENAME, 

class TutorialBundlerTests(unittest.TestCase):
    
    def setUp(self):
        
        #generate a test GUID
        self.test_guid = uuid.uuid1()
        self.guid_path = os.path.join(bundler._get_store_root(),str(self.test_guid))
        os.mkdir(self.guid_path)
        
        self.ini_file = os.path.join(self.guid_path, "meta.ini")
        
        f = open(self.ini_file,'w')
        f.write("[GENERAL_METADATA]")
        f.write(os.linesep)
        f.write("GUID:")
        f.write(str(self.test_guid))
        f.close()
        
    def tearDown(self):
        os.remove(self.ini_file)
        os.rmdir(self.guid_path)
        
    def test_add_ressource(self):
        bund = bundler.TutorialBundler(unicode(self.test_guid))

        temp_file = open("test.txt",'w')
        temp_file.write('test')
        temp_file.close()

        bund.add_resources("text", "test.txt")
        
        assert os.path.exists(os.path.join(self.guid_path,"test.txt")), "add_ressource did not create the file"
        
if __name__ == "__main__":
    unittest.main()