import repository from arizona
[raven.git] / 2.0 / python / test / storkrpmTest.py
1 #! /usr/bin/env python
2 """
3 <Module>
4    storkrpmTest
5 <Author>
6    Jeffry Johnston, under the direction of Justin Cappos
7    Rewritten by Collin Reynolds
8 <Started>
9    September 29, 2005   
10 <Purpose>
11    Test module for storkrpm.  See storkrpm.py for more details.
12 """
13
14 import arizonaunittest
15 import storkrpm
16 import os
17 import arizonaconfig
18 import arizonatransfer
19
20 # Unit tests for each function, listed in code order
21 class test(arizonaunittest.TestCase):
22
23    #------------------------------------------------------------------
24    # initialize() -> void
25    #------------------------------------------------------------------
26    def test_initialize(self):
27       # note: this test will fail as the version of rpm changes 
28       self.assertEqual(storkrpm.initialize(), 
29                        ['rpmlib(VersionedDependencies) = 3.0.3-1', 'rpmlib(CompressedFileNames) = 3.0.4-1', 
30                         'rpmlib(PayloadIsBzip2) = 3.0.5-1', 'rpmlib(PayloadFilesHavePrefix) = 4.0-1', 
31                         'rpmlib(ExplicitPackageProvide) = 4.0-1', 'rpmlib(HeaderLoadSortsTags) = 4.0.1-1', 
32                         'rpmlib(ScriptletInterpreterArgs) = 4.0.3-1', 'rpmlib(PartialHardlinkSets) = 4.0.4-1', 
33                         'rpmlib(ConcurrentAccess) = 4.1-1', 'rpmlib(BuiltinLuaScripts) = 4.2.2-1'])
34    
35
36
37
38
39    #------------------------------------------------------------------
40    # is_package_understood(filename)
41    # filename -> bool, TypeError
42    #------------------------------------------------------------------
43    def test_is_package_understood(self): 
44       # A non-string
45       self.assertException(TypeError, storkrpm.is_package_understood, 3)
46
47       # The empty string
48       self.assertFalse(storkrpm.is_package_understood(""))
49
50       # A file that should exist and be readable
51       self.assertFalse(storkrpm.is_package_understood("/bin/ls"))
52
53       # A path
54       self.assertFalse(storkrpm.is_package_understood("/tmp"))
55
56       # An invalid path
57       self.assertFalse(storkrpm.is_package_understood("/jasdfljk/ajsdfjkadf/asjdf"))
58
59       # An invalid file
60       self.assertFalse(storkrpm.is_package_understood("/usr/bin/asjdf"))
61       
62       # A misnamed file
63       os.system("cp /bin/ls /tmp/ls.rpm")
64       self.assertFalse(storkrpm.is_package_understood("/tmp/ls.rpm"))
65       os.system("rm /tmp/ls.rpm")
66
67       # A real rpm
68       self.assertTrue(os.path.isfile("../test/PyXML-0.8.3-6.i386.rpm"))
69       self.assertTrue(storkrpm.is_package_understood("../test/PyXML-0.8.3-6.i386.rpm"))
70                                                   
71       # A real rpm that has been corrupted
72       os.system('cp ../test/PyXML-0.8.3-6.i386.rpm ../test/Corrupted.rpm')
73       os.system('echo "abcTestingcorrupted" > ../test/Corrupted.rpm')
74       self.assertFalse(storkrpm.is_package_understood("../test/Corrupted.rpm"))
75       os.remove("../test/Corrupted.rpm")
76       
77       
78       
79       
80       
81       
82    #------------------------------------------------------------------
83    # get_packages_provide(filename_list)
84    #------------------------------------------------------------------   
85    def test_get_packages_provide(self):
86       #test normal input
87       dep_list = storkrpm.get_packages_provide(["../test/PyXML-0.8.3-6.i386.rpm"])
88       self.assertEqual(dep_list,['boolean.so', 'pyexpat.so', 'sgmlop.so', 'PyXML = 0.8.3-6'])
89       
90       #test errors
91       self.assertException(TypeError,storkrpm.get_packages_provide,"../test/PyXML-0.8.3-6.i386.rpm")
92       self.assertException(TypeError,storkrpm.get_packages_provide,{"filename":"../test/PyXML-0.8.3-6.i386.rpm"})
93       self.assertException(TypeError,storkrpm.get_packages_provide,None)
94       self.assertException(TypeError,storkrpm.get_packages_provide,356)
95       self.assertException(TypeError,storkrpm.get_packages_provide,[123])
96       
97       
98       
99       
100       
101    #------------------------------------------------------------------
102    # get_packages_require(filename_list)
103    #------------------------------------------------------------------
104    def test_get_packages_require(self):
105       #test normal input
106       dep_list = storkrpm.get_packages_require(["../test/PyXML-0.8.3-6.i386.rpm"])
107       self.assertEqual(dep_list,['/usr/bin/python', 'libc.so.6', 'libc.so.6(GLIBC_2.0)', 
108                                  'libc.so.6(GLIBC_2.1.3)', 'libc.so.6(GLIBC_2.3)', 
109                                  'libpthread.so.0', 'python', 'rpmlib(CompressedFileNames) <= 3.0.4-1', 
110                                  'rpmlib(PayloadFilesHavePrefix) <= 4.0-1'])
111       
112       #test errors
113       self.assertException(TypeError,storkrpm.get_packages_require,"../test/PyXML-0.8.3-6.i386.rpm")
114       self.assertException(TypeError,storkrpm.get_packages_require,{"filename":"../test/PyXML-0.8.3-6.i386.rpm"})
115       self.assertException(TypeError,storkrpm.get_packages_require,None)
116       self.assertException(TypeError,storkrpm.get_packages_require,356)
117       self.assertException(TypeError,storkrpm.get_packages_require,[123])                                     
118       
119       
120       
121       
122       
123    #------------------------------------------------------------------
124    # get_packages_files(filename_list)
125    #------------------------------------------------------------------
126    def test_get_packages_files(self):
127       #test normal input
128       self.assertTrue(os.path.isfile("../test/PyXML-0.8.3-6.i386.rpm"))
129       os.system("rpm -qpl ../test/PyXML-0.8.3-6.i386.rpm > ../test/rpmoutput.dat")
130       pack_files = storkrpm.get_packages_files(["../test/PyXML-0.8.3-6.i386.rpm"])
131       
132       compare_list = []
133       for line in file("../test/rpmoutput.dat","r"):
134          compare_list.append(line.strip("\n"))
135          
136       self.assertEqual(pack_files,compare_list)
137       os.remove("../test/rpmoutput.dat")
138       
139       #test errors
140       self.assertException(TypeError,storkrpm.get_packages_files,"../test/PyXML-0.8.3-6.i386.rpm")
141       self.assertException(TypeError,storkrpm.get_packages_files,{"filename":"../test/PyXML-0.8.3-6.i386.rpm"})
142       self.assertException(TypeError,storkrpm.get_packages_files,None)
143       self.assertException(TypeError,storkrpm.get_packages_files,356)
144       self.assertException(TypeError,storkrpm.get_packages_files,[123])
145       
146       
147       
148       
149       
150    #------------------------------------------------------------------      
151    # get_package_info(filename)
152    #------------------------------------------------------------------
153    def test_get_package_info(self):
154       #test normal input
155       pack_info = storkrpm.get_package_info("../test/PyXML-0.8.3-6.i386.rpm")
156       self.assertEqual(pack_info, ['PyXML', '0.8.3', '6', '6944287'])
157       
158       #test errors
159       self.assertException(TypeError,storkrpm.get_package_info,["../test/PyXML-0.8.3-6.i386.rpm"])
160       self.assertException(TypeError,storkrpm.get_package_info,{"filename":"../test/PyXML-0.8.3-6.i386.rpm"})
161       self.assertException(TypeError,storkrpm.get_package_info,None)
162       self.assertException(TypeError,storkrpm.get_package_info,356)
163       self.assertException(TypeError,storkrpm.get_package_info,[123])    
164       
165       
166       
167       
168       
169       
170    #------------------------------------------------------------------
171    # get_installed_versions(package_list)
172    #------------------------------------------------------------------
173    def test_get_installed_versions(self):
174       #test normal input
175       version_list = storkrpm.get_installed_versions(["PyXML"])
176       self.assertEqual(version_list,['PyXML = 0.8.4-4'])
177       
178       #test errors
179       self.assertException(TypeError,storkrpm.get_installed_versions,"PyXML")
180       self.assertException(TypeError,storkrpm.get_installed_versions,{"package":"PyXML"})
181       self.assertException(TypeError,storkrpm.get_installed_versions,None)
182       self.assertException(TypeError,storkrpm.get_installed_versions,356)
183       self.assertException(TypeError,storkrpm.get_installed_versions,[123])    
184       
185       
186
187       
188    #------------------------------------------------------------------      
189    # get_installedpackages_requiring(dep_list)
190    #------------------------------------------------------------------
191    def test_get_installedpackages_requiring(self):
192       dep_list = storkrpm.get_packages_require(["../test/PyXML-0.8.3-6.i386.rpm"])
193       #somehow test that this worked...
194       #self.assertEqual(storkrpm.get_installedpackages_requiring(dep_list),some huge list of packages)
195       
196       
197       
198       
199       
200       
201    #------------------------------------------------------------------
202    # get_installedpackages_fulfilling(dep_list)
203    # dep_list -> package_list, TypeError   
204    #------------------------------------------------------------------
205    def test_get_installedpackages_fulfilling(self):
206       # Not a string list
207       self.assertException(TypeError, storkrpm.get_installedpackages_provide, "abc")
208       
209       # test with installed packages
210       self.assertEqual(storkrpm.get_installedpackages_fulfilling(["filesystem", "coreutils"]),
211                         ['filesystem-2.4.0-1', 'coreutils-5.97-12.5.fc6'])
212                         
213                         
214                         
215                         
216      
217    #------------------------------------------------------------------                        
218    # get_installedpackages()                        
219    #------------------------------------------------------------------
220    def test_get_installedpackages(self):
221       #Test normal input
222       out = os.popen("rpm -q -a")
223       compare_list = []
224       for line in out:
225          compare_list.append(line.strip("\n"))
226          
227       self.assertEqual(storkrpm.get_installedpackages(),compare_list)
228       
229       
230       
231       
232       
233          
234    #------------------------------------------------------------------
235    # package_list -> dep_list, IOError, TypeError      
236    #------------------------------------------------------------------
237    def test_get_installedpackages_provide(self):
238       # note: this test will fail as the version of rpm changes 
239
240       # Not a string list
241       self.assertException(TypeError, storkrpm.get_installedpackages_provide, "abc")
242
243       # test with installed packages
244       self.assertEqual(storkrpm.get_installedpackages_provide(["coreutils"]), ['config(coreutils) = 5.97-12.5.fc6', 'fileutils = 5.97', 'sh-utils = 5.97', 'stat', 'textutils = 5.97', 'coreutils = 5.97-12.5.fc6'])
245       
246       
247       
248       
249       
250    
251    #------------------------------------------------------------------
252    # get_installedpackages_requires(package_list)   
253    #------------------------------------------------------------------
254    def test_get_installedpackages_requires(self):
255       pass
256       
257       
258       
259       
260       
261    #------------------------------------------------------------------
262    # check_install_status(filename_list)
263    #------------------------------------------------------------------
264    def test_check_install_status(self):
265       self.assertEqual(storkrpm.check_install_status(["../test/PyXML-0.8.3-6.i386.rpm"]),([],["PyXML"]))   
266       #Needs more work
267       
268       
269       
270       
271       
272       
273    #------------------------------------------------------------------
274    # execute(trans_list)
275    #------------------------------------------------------------------
276    def test_execute(self):
277       import storktransaction
278       # check params: Not a string list
279       self.assertException(TypeError, storkrpm.get_installedpackages_provide, "abc")
280       
281       try:
282          storkrpm.remove("PyXML")
283       except:
284          pass
285       
286       # install package
287       self.assertTrue(os.path.isfile("../test/PyXML-0.8.3-6.i386.rpm"))
288       tl = storktransaction.tl_create()
289       storktransaction.tl_install(tl,"../test/PyXML-0.8.3-6.i386.rpm")
290       storkrpm.execute(tl)
291
292
293
294
295
296    #------------------------------------------------------------------
297    # package_list -> void, IOError, NameError, TypeError
298    #------------------------------------------------------------------
299    def test_remove(self):
300       pass
301
302  
303 """ 
304       self.assertException(TypeError, arizonaconfig.init_options, 100)
305       self.set_cmdline(["--help"])
306       self.reset_stdout()
307       self.reset_stderr()
308       reload(arizonaconfig)
309 """
310
311 # Run tests
312 if __name__ == '__main__':
313    storkrpm.initialize()
314    arizonaconfig.init_options("storkrpmTest") 
315    arizonaconfig.set_option("transfermethod", ['http', 'ftp'])
316    arizonaunittest.main()