import repository from arizona
[raven.git] / 2.0 / python / test / storktransactionTest.py
1 """
2 <Program Name>
3    storktransactionTest.py
4
5 <Started>
6    Oct 15, 2007
7
8 <Author>
9    Collin Reynolds
10
11 <Purpose>
12    To test the storktransaction.py module, see it for details
13 """
14
15 import arizonaunittest
16 import arizonageneral
17 import storktransaction
18
19 class test(arizonaunittest.TestCase):
20
21    #----------------------------------------------------------
22    # tl_create()
23    #----------------------------------------------------------
24    def test_tl_create(self):
25       tl = storktransaction.tl_create()
26       self.assertEqual(tl,[])
27       
28       
29       
30       
31       
32       
33    #----------------------------------------------------------
34    # tl_add(tl, transaction)
35    #----------------------------------------------------------
36    def test_tl_add(self):
37       tl = storktransaction.tl_create()
38       storktransaction.tl_add(tl,"TEST")
39       self.assertEqual(tl,["TEST"])
40    
41    
42    
43    
44    
45    
46    #----------------------------------------------------------
47    # tl_install(tl, filename)
48    #----------------------------------------------------------
49    def test_tl_install(self):
50       #Test normal functionality
51       tl = storktransaction.tl_create()
52       storktransaction.tl_install(tl,"installthis.tar.gz")
53       self.assertEqual(tl,[{'op':'INSTALL','filename':"installthis.tar.gz"}])
54       storktransaction.tl_install(tl,"another.test.gz")
55       self.assertEqual(tl,[{'op':'INSTALL','filename':"installthis.tar.gz"},{'op':'INSTALL','filename':"another.test.gz"}])
56       
57       tl = None      
58       #Try with none for transaction list, should raise TypeError
59       self.assertException(TypeError,storktransaction.tl_install,tl,"test")
60       #Try with dict
61       tl = {}
62       self.assertException(TypeError,storktransaction.tl_install,tl,"test")
63       
64       
65       
66       
67       
68       
69    #----------------------------------------------------------
70    # tl_upgrade(tl, filename, conflict_list)
71    #----------------------------------------------------------
72    def test_tl_upgrade(self):
73       #Test normal functionality
74       tl = storktransaction.tl_create()
75       #Test one conflict
76       storktransaction.tl_upgrade(tl,"installthis.tar.gz",["conflict1"])
77       self.assertEqual(tl,[{'op':'UPGRADE','filename':"installthis.tar.gz",'conflicts':["conflict1"]}])
78       #Test two conflicts
79       storktransaction.tl_upgrade(tl,"test2.tar.gz",["conflict2","conflict3"])
80       self.assertEqual(tl,[{'op':'UPGRADE','filename':"installthis.tar.gz",'conflicts':["conflict1"]},{'op':'UPGRADE','filename':"test2.tar.gz",'conflicts':["conflict2","conflict3"]}])
81       #Test no conflict
82       tl = storktransaction.tl_create()
83       storktransaction.tl_upgrade(tl,"installthis.tar.gz",[])
84       self.assertEqual(tl,[{'op':'UPGRADE','filename':"installthis.tar.gz",'conflicts':[]}])
85       #Test None as conflict, should raise TypeError
86       tl = storktransaction.tl_create()
87       self.assertException(TypeError,storktransaction.tl_upgrade,tl,"installthis.tar.gz",None)
88       
89       
90       
91       
92       
93       
94    #----------------------------------------------------------
95    # tl_remove(tl, packname)
96    #----------------------------------------------------------
97    def test_tl_remove(self):
98       #Test normal functionality
99       tl = storktransaction.tl_create()
100       storktransaction.tl_remove(tl,"remove.tar.gz")
101       self.assertEqual(tl,[{'op':'REMOVE','packname':"remove.tar.gz"}])
102       storktransaction.tl_remove(tl,"another.test.gz")
103       self.assertEqual(tl,[{'op':'REMOVE','packname':"remove.tar.gz"},{'op':'REMOVE','packname':"another.test.gz"}])
104       
105       tl = None      
106       #Try with none for transaction list, should raise TypeError
107       self.assertException(TypeError,storktransaction.tl_remove,tl,"test")
108       #Try with dict
109       tl = {}
110       self.assertException(TypeError,storktransaction.tl_remove,tl,"test")
111       
112       
113       
114       
115       
116       
117    #----------------------------------------------------------
118    # tl_print(tl)
119    #----------------------------------------------------------
120    def test_tl_print(self):
121       #Test normal functionality
122       tl = storktransaction.tl_create()
123       storktransaction.tl_install(tl,"installthis.tar.gz")
124       storktransaction.tl_upgrade(tl,"installthis.tar.gz",["conflict1"])
125       storktransaction.tl_remove(tl,"remove.tar.gz")
126       storktransaction.tl_print(tl)
127       #Above should not create any errors, possibly need to check output of print somehow
128       
129       #Make sure it only prints transaction lists
130       tl = {}
131       self.assertException(TypeError,storktransaction.tl_print,tl)
132       tl = ["TEST"]
133       self.assertException(TypeError,storktransaction.tl_print,tl)
134       tl = [None]
135       self.assertException(TypeError,storktransaction.tl_print,tl)
136       
137       
138       
139       
140       
141       
142    #----------------------------------------------------------
143    # tl_get_count(tl, kind)
144    #----------------------------------------------------------   
145    def test_tl_get_count(self):
146       #Create a tl
147       tl = storktransaction.tl_create()
148       for x in xrange(0,20):
149          storktransaction.tl_install(tl,"test%d.tar.gz"%x)
150          
151       #Test that it counts the install ops and all ops correctly
152       self.assertEqual(storktransaction.tl_get_count(tl,None),20)
153       self.assertEqual(storktransaction.tl_get_count(tl,storktransaction.INSTALL),20)
154       self.assertEqual(storktransaction.tl_get_count(tl,storktransaction.REMOVE),0)      
155       self.assertEqual(storktransaction.tl_get_count(tl,storktransaction.UPGRADE),0)
156       
157       
158       
159       
160       
161       
162    #----------------------------------------------------------
163    # tl_get_filename_list(tl, kind):
164    #----------------------------------------------------------   
165    def test_tl_get_filename_list(self):
166       #Create a tl
167       tl = storktransaction.tl_create()
168       testList = []
169       for x in xrange(0,20):
170          storktransaction.tl_install(tl,"test%d.tar.gz"%x)
171          testList.append("test%d.tar.gz"%x)
172          
173       #Test that it gets all of the the install ops and all ops filenames correctly
174       self.assertEqual(storktransaction.tl_get_filename_list(tl,None),testList)
175       self.assertEqual(storktransaction.tl_get_filename_list(tl,storktransaction.INSTALL),testList)
176       self.assertEqual(storktransaction.tl_get_filename_list(tl,storktransaction.REMOVE),[])      
177       self.assertEqual(storktransaction.tl_get_filename_list(tl,storktransaction.UPGRADE),[])
178       
179       
180       
181       
182       
183       
184    #----------------------------------------------------------   
185    # tl_get_packname_list(tl, kind)
186    #----------------------------------------------------------   
187    def test_tl_get_packname_list(self):
188       #Create a tl
189       tl = storktransaction.tl_create()
190       testList = []
191       for x in xrange(0,20):
192          storktransaction.tl_remove(tl,"test%d.tar.gz"%x)
193          testList.append("test%d.tar.gz"%x)
194          
195       #Test that it gets all of the packnames
196       self.assertEqual(storktransaction.tl_get_packname_list(tl,None),testList)
197       self.assertEqual(storktransaction.tl_get_packname_list(tl,storktransaction.REMOVE),testList)
198       self.assertEqual(storktransaction.tl_get_packname_list(tl,storktransaction.INSTALL),[])      
199       self.assertEqual(storktransaction.tl_get_packname_list(tl,storktransaction.UPGRADE),[])
200       
201       
202       
203       
204       
205      
206    #----------------------------------------------------------   
207    # tl_get_conflict_list(tl, kind)
208    #----------------------------------------------------------   
209    def test_tl_get_conflict_list(self):
210       #Create a tl
211       tl = storktransaction.tl_create()
212       testList = []
213       for x in xrange(0,20):
214          storktransaction.tl_upgrade(tl,"test%d.tar.gz"%x,["conflict%d"%x,"conflict%d"%(x+1),"conflict%d"%(x+2),"conflict%d"%(x+3)])
215          testList.append("conflict%d"%x)
216          testList.append("conflict%d"%(x+1))
217          testList.append("conflict%d"%(x+2))
218          testList.append("conflict%d"%(x+3))
219       
220       testList = arizonageneral.uniq(testList)
221          
222       #Test that it gets all of the unique conflicts
223       self.assertEqual(storktransaction.tl_get_conflict_list(tl,None),testList)
224       self.assertEqual(storktransaction.tl_get_conflict_list(tl,storktransaction.UPGRADE),testList)
225       self.assertEqual(storktransaction.tl_get_conflict_list(tl,storktransaction.INSTALL),[])      
226       self.assertEqual(storktransaction.tl_get_conflict_list(tl,storktransaction.REMOVE),[])
227       
228       
229       
230       
231       
232       
233 #=====================================================================
234 # Run tests
235 #=====================================================================
236 if __name__=='__main__':
237    arizonaunittest.main()