import repository from arizona
[raven.git] / 2.0 / python / test / storkpackageTest.py
1 #! /usr/bin/env python
2 """
3 <Module>
4    storkpackageTest
5 <Author>
6    Justin Cappos
7
8    Extended by Mario Gonzalez
9    
10 <Started>
11    May 23, 2006
12 <Purpose>
13    Test module for storkpackage.  See storkpackage.py for more details.
14 """
15
16 import os
17 import arizonaconfig
18 import arizonatransfer
19 import arizonaunittest
20 import storkpackagelist
21 import arizonageneral
22 import storkpackage
23 import sys
24 from package import storktar
25
26 # Unit tests for each function, listed in code order
27 class test(arizonaunittest.TestCase):
28
29
30    #------------------------------------------------------------------
31    # reset_options(): call this every time you wish to set or re-set the options
32    # since the tests are not called in order
33    #------------------------------------------------------------------
34    def reset_options(self):
35       self.set_cmdline([])
36       prefix = os.environ.get("TESTPREFIX")
37       storkpackage.reset()
38       arizonaconfig.init_options("storkpackage.py", alt_paths=[prefix], version="2.0")
39                   
40    
41    #------------------------------------------------------------------
42    # init():
43    #------------------------------------------------------------------
44    def test_initialize(self):
45
46       # set or re-set the options since the tests are not called in order
47       self.reset_options()
48
49       # no "packagemanagers" should exist yet
50       arizonaconfig.reset()
51       
52       # should raise an exception if arizonaconfig.init_options() has not been called yet or
53       # no option has been set:
54       self.assertException(Exception, storkpackage.initialize) 
55       self.assertException(Exception, storkpackage.initialize, None) 
56       # check that a specific exception is raised (white box test):
57       self.assertRaises(arizonageneral.Exception_Data, storkpackage.initialize)
58
59       # assert that the expected message is the actual one
60       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: missing --packagemanagers setting", storkpackage.initialize)
61
62       # White box: do preparation so that arizonaconfig.init_options()
63       # has been successfuly called prior to running storkpackage.initialize()
64       # since this is needed by storkpackage.initialize():
65
66       # ---- TEST STARTS ------------------------------------------------------------------------------
67       # Prepare the options to test storkpackage: make sure init_options 
68       # run successfully but storkpackage.initialize() does NOT find any
69       # usable package managers
70
71       # set or re-set the options since the tests are not called in order
72       self.reset_options()
73       self.set_cmdline([])
74
75       # create new option (which is invalid.. string instead of list of strings)
76       arizonaconfig.set_option("packagemanagers", "rpm")
77       self.assertEqual(arizonaconfig.get_option("packagemanagers"), "rpm")
78
79       # Now that the options have been successfuly initialized, 
80       # test the method:
81       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: no usable package managers.", storkpackage.initialize)
82       self.assertTrue(storkpackage.possible_packmanagers != None)
83       self.assertEquals(len(storkpackage.inited_packmanager_list), 0)
84       self.assertTrue(storkpackage.glo_packagemanagers_provide == [])
85
86       # create new option
87       self.reset_options()
88       arizonaconfig.set_option("packagemanagers", "an unusable package manager")
89       self.assertEqual(arizonaconfig.get_option("packagemanagers"), "an unusable package manager")
90
91       # Now that the options have been successfuly initialized,
92       # test the method:
93       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: no usable package managers.", storkpackage.initialize)
94       self.assertTrue(storkpackage.possible_packmanagers != None)
95       self.assertEquals(len(storkpackage.inited_packmanager_list), 0)
96       self.assertTrue(storkpackage.glo_packagemanagers_provide == [])
97                                                                                                 
98       # ---- TEST ENDS ------------------------------------------------------------------------------      
99
100       # ---- TEST STARTS ------------------------------------------------------------------------------
101       # Prepare the options to test storkpackage: make sure init_options 
102       # run successfully and storkpackage.initialize() DOES find 
103       # usable package managers
104       self.reset_options()
105
106       # Is this actually needed or should init_options see and set "packagemanagers" itself?
107       #arizonaconfig.set_option("packagemanagers", ["rpm", 'tar'])
108       self.assertEquals(["rpm", "tar"], arizonaconfig.get_option("packagemanagers"))
109
110       # Now that arizonaconfig.init_options() has been successfuly called, 
111       # test the method:
112       try:
113           storkpackage.initialize()
114       except arizonageneral.Exception_Data:
115           self.fail("Should not have failed")
116       self.assertTrue(storkpackage.possible_packmanagers != None)
117       self.assertTrue(len(storkpackage.inited_packmanager_list) > 0)
118       # the following line is simply to output the contents of inited_packmanager_list. Comment out when not
119       # needed. Note that it IS NOT A TEST!
120       #self.assertEquals("", storkpackage.inited_packmanager_list)
121       self.assertEquals("/usr/local/stork/tar_packinfo", arizonaconfig.get_option('tarpackinfopath'))
122       self.assertTrue(len(storkpackage.glo_packagemanagers_provide) > 0 )
123       self.assertTrue(storkpackage.glo_packagemanagers_provide != None)
124       self.assertTrue(storkpackage.glo_packagemanagers_provide != [])
125       # ---- TEST ENDS ------------------------------------------------------------------------------
126
127
128       # ---- TEST STARTS ------------------------------------------------------------------------------
129       # Call initialize but set the package manager options like this: ['tar', 'rpm']. That is, first
130       # tar and then rpm.
131       self.reset_options()
132       #arizonaconfig.set_option("packagemanagers", ['tar', 'rpm'])
133       #self.assertEquals(["tar", "rpm"], arizonaconfig.get_option("packagemanagers"))
134
135       # Now that arizonaconfig.init_options() has been successfuly called,
136       # test the method:
137       try:
138          storkpackage.initialize()
139       except arizonageneral.Exception_Data:
140          self.fail("Should not have failed")
141       self.assertTrue(storkpackage.possible_packmanagers != None)
142       self.assertTrue(len(storkpackage.inited_packmanager_list) > 0)
143       # The following line is simply to output the contents of inited_packmanager_list. Comment out when not
144       # needed. Note that it IS NOT A TEST!
145       #self.assertEquals("", storkpackage.inited_packmanager_list)
146       self.assertEquals("/usr/local/stork/tar_packinfo", arizonaconfig.get_option('tarpackinfopath'))
147       self.assertTrue(len(storkpackage.glo_packagemanagers_provide) > 0 )
148       self.assertTrue(storkpackage.glo_packagemanagers_provide != None)
149       self.assertTrue(storkpackage.glo_packagemanagers_provide != [])
150                                                                                             
151       # ---- TEST ENDS ------------------------------------------------------------------------------
152       
153       
154       
155    #------------------------------------------------------------------
156    # get_packagemanagers_provide()
157    #------------------------------------------------------------------
158    def test_get_packagemanagers_provide(self):
159       self.reset_options()
160       arizonaconfig.reset()
161       
162       # should raise an exception if arizonaconfig.init_options() has not been called yet:
163       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: missing --packagemanagers setting", storkpackage.initialize)
164       self.assertException(Exception, storkpackage.get_packagemanagers_provide)
165       # check that a specific exception is raised (white box test):
166       self.assertRaises(arizonageneral.Exception_Data, storkpackage.get_packagemanagers_provide)
167
168
169       # White box: do preparation so that some needed options are initialized 
170       # prior to running this method
171
172       # ---- TEST STARTS ------------------------------------------------------------------------------
173       # The tests are the same as for initialize() since initialize() is the only method called.
174       # ---- TEST ENDS ------------------------------------------------------------------------------
175
176
177    #------------------------------------------------------------------
178    # is_package_understood():
179    #------------------------------------------------------------------
180    def test_is_package_understood(self):
181       reload(storkpackage)
182       self.reset_options()
183
184       prefix = os.environ.get("TESTPREFIX")
185       
186       # test with invalud input:
187       self.assertRaises(TypeError, storkpackage.is_package_understood, None)
188       self.assertRaises(TypeError, storkpackage.is_package_understood, [])
189       self.assertRaises(TypeError, storkpackage.is_package_understood, ["sdsd"])
190       self.assertRaises(TypeError, storkpackage.is_package_understood, 23)
191       self.assertRaises(TypeError, storkpackage.is_package_understood, 56.3)
192
193       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: missing --packagemanagers setting", storkpackage.is_package_understood, 'filename')
194       
195       self.assertException(Exception, storkpackage.is_package_understood)
196
197       # White box: do preparation so that some needed options are initialized 
198       # prior to running this method
199
200       # ---- TEST STARTS ------------------------------------------------------------------------------
201       # Prepare the options to test storkpackage: make sure init_options 
202       # run successfully but storkpackage.initialize() does NOT find any
203       # package managers that can be UNDERSTOOD:
204       
205       # set or re-set the options since the tests are not called in order
206       self.reset_options()
207
208       # create new option
209       arizonaconfig.set_option("packagemanagers", "an invalid package manager")
210       self.assertEqual(arizonaconfig.get_option("packagemanagers"), "an invalid package manager")
211
212       # Now that arizonaconfig.init_options() has been successfuly called, 
213       # test the method. Note that is should raise exceptions since there are no valid package managers:
214       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: no usable package managers.", storkpackage.is_package_understood, "")
215  
216       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: no usable package managers.", storkpackage.is_package_understood, ".")
217
218       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: no usable package managers.", storkpackage.is_package_understood, "''")
219             
220       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: no usable package managers.", storkpackage.is_package_understood, "rpm")
221
222       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: no usable package managers.", storkpackage.is_package_understood, "some invalid package")
223       
224
225       # ---- TEST ENDS ------------------------------------------------------------------------------
226
227
228       # Make the following tests independent of the testing path:
229       # Extract the path where "stork/..." starts and leave the part before this substring to a variable
230       # that will change so that the tests can be run in different machines:
231       subIdx = prefix.find("stork")
232       path = prefix[:subIdx]
233       #self.debug_print(path)
234
235                               
236       # ---- TEST STARTS ------------------------------------------------------------------------------
237       # Prepare the options to test storkpackage: make sure init_options 
238       # run successfully and  storkpackage.initialize() DOES find 
239       # package managers that can be UNDERSTOOD:
240
241       # Test with tar package manager
242       self.reset_options()
243
244       arizonaconfig.set_option("packagemanagers", ["tar"])
245       # Now that arizonaconfig.init_options() has been successfuly called, 
246       # test the method:
247       self.assertFalse(storkpackage.is_package_understood("some invalid file name here"))
248       self.assertFalse( storkpackage.is_package_understood( "hello"))
249       self.assertFalse( storkpackage.is_package_understood( ""))
250       self.assertFalse( storkpackage.is_package_understood( " "))
251       self.assertFalse( storkpackage.is_package_understood( "-*"))
252       # the following two lines freeze up is_package_understood()
253       #self.assertFalse( storkpackage.is_package_understood( "-"))
254       #self.assertFalse( storkpackage.is_package_understood( "- "))
255       self.assertFalse( storkpackage.is_package_understood("- dashSpaceAndSomeName"))
256       self.debug_print("hi")
257       self.assertFalse( storkpackage.is_package_understood( "."))
258       self.assertFalse( storkpackage.is_package_understood( "storktar.pyc"))
259       self.assertFalse( storkpackage.is_package_understood( " some string "))
260       self.assertFalse( storkpackage.is_package_understood( prefix + "/package/storktar.pyc"))
261       # test with valid package filenames
262       
263       self.assertTrue(storkpackage.is_package_understood(path + "stork/webpage/downloads/stork_example.tar.gz"))
264
265       self.assertTrue(storkpackage.is_package_understood(path + "stork/webpage/downloads/stork_key.tar.gz"))
266
267       # exists but contains ???
268       #self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/stork-0.1.0.tar"))
269
270       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/storkd-0.1.0.tar.gz"))
271
272       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testa-0.1.tar.gz"))
273
274       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testa-0.2.tar.gz"))
275
276       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testb-0.1.tar.gz"))
277
278       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testb-10.1.tar.gz"))
279
280       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testb-9.1.tar.gz"))
281
282       self.assertTrue(storkpackage.is_package_understood(path + "stork/python/tests/install.tar.gz"))
283       
284       self.assertTrue(storkpackage.is_package_understood(path + "stork/python/refactor/package-dir.tar"))
285
286       self.assertTrue(storkpackage.is_package_understood(path + "stork/python/package-dir/lib-package/arizona-lib-1.0.0.tar.gz"))
287
288       self.assertTrue(storkpackage.is_package_understood(path + "stork/keypack/stork_key.tar.gz"))
289
290       # does not exist
291       #self.assertTrue(storkpackage.is_package_understood(path + "stork/2.0/stork.tar.bz2"))
292
293       self.assertTrue(storkpackage.is_package_understood(path + "stork/repository.tar.gz"))
294
295       # "rpm" is not set as a manager, so these calls must return false:
296       self.assertFalse(storkpackage.is_package_understood(path + "stork/testpack/stork-0.1.0-1.i386.rpm"))
297
298       self.assertFalse(storkpackage.is_package_understood(path + "stork/testpack/stork-0.1.0-1.src.rpm"))
299
300       self.assertFalse(storkpackage.is_package_understood(path + "stork/testpack/storkd-0.1.0-1.i386.rpm"))
301
302       self.assertFalse(storkpackage.is_package_understood(path + "stork/testpack/storkd-0.1.0-1.src.rpm"))
303
304       self.assertFalse(storkpackage.is_package_understood(path + "stork/testpack/testa-0.1-1.i386.rpm"))
305
306       self.assertFalse(storkpackage.is_package_understood(path + "stork/testpack/testa-0.1-1.src.rpm"))
307                                     
308
309
310       # Now test with rpm package manager
311       self.reset_options()
312       arizonaconfig.set_option("packagemanagers", ["rpm"])
313       self.assertEqual(['rpm'], arizonaconfig.get_option("packagemanagers"))
314       storkpackage.initialize()
315       self.debug_print(storkpackage.inited_packmanager_list)
316       for i in storkpackage.inited_packmanager_list:
317          self.debug_print(i[1])
318       # Now that arizonaconfig.init_options() has been successfuly called,
319       # test the method:
320       self.assertFalse( storkpackage.is_package_understood( " "))
321       self.assertFalse( storkpackage.is_package_understood( "some invalid file name here" ))
322       self.assertFalse(storkpackage.is_package_understood("filename"))
323       self.assertFalse( storkpackage.is_package_understood( "-"))
324       self.assertFalse( storkpackage.is_package_understood("- dashSpaceAndSomeName"))
325       self.assertFalse( storkpackage.is_package_understood("- "))
326       self.assertFalse( storkpackage.is_package_understood( "."))
327       self.assertFalse( storkpackage.is_package_understood( "2322"))
328       self.assertFalse( storkpackage.is_package_understood(""))
329       #self.assertFalse( storkpackage.is_package_understood( prefix + "/package/storkrpm.pyc"))
330       # test with valid package filenames
331       # Since the valid packages are stored in the stork/ directory, take the last part off of the
332       # prefix so that the packages can be accessed by the tests:
333       #testStringIdx = prefix.find("stork/2.0/python")
334       #pathString = prefix.ljust(testStringIdx, None)
335       #self.assertEquals(None, pathString)
336
337 #      # Make the following tests independent of the testing path:
338 #      # Extract the path where "stork/..." starts and leave the part before this substring to a variable
339 #      # that will change so that the tests can be run in different machines:
340 #      subIdx = prefix.find("stork")
341 #      path = prefix[:subIdx]
342 #      #self.debug_print(path)
343
344       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/stork-0.1.0-1.i386.rpm"))
345    
346       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/stork-0.1.0-1.src.rpm"))
347       
348       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/storkd-0.1.0-1.i386.rpm"))
349       
350       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/storkd-0.1.0-1.src.rpm"))
351       
352       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testa-0.1-1.i386.rpm"))
353       
354       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testa-0.1-1.src.rpm"))
355
356       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testa-0.2-1.i386.rpm"))
357
358       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testa-0.2-1.src.rpm"))
359
360       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testb-0.1-1.i386.rpm"))
361
362       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testb-0.1-1.src.rpm"))
363
364       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testb-9.1-1.i386.rpm"))
365
366       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testb-9.1-1.src.rpm"))
367
368       # exists but is empty:
369       #self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testc-0.1-1.i386.rpm"))
370
371       self.assertTrue(storkpackage.is_package_understood(path + "stork/python/tests/cpio-2.5-6.i386.rpm"))
372
373       self.assertTrue(storkpackage.is_package_understood(path + "stork/python/tests/stork-1.0.0-1.i386.rpm"))
374
375       self.assertTrue(storkpackage.is_package_understood(path + "stork/python/tests/stork-slice-1.0.0b-3.i386.rpm"))
376
377       # does not exist anymore
378       #self.assertTrue(storkpackage.is_package_understood(path + "stork/pack/stork-slice-1.0.0-1.i386.rpm"))
379
380       self.assertTrue(storkpackage.is_package_understood(path + "stork/pack/cpio-2.5-6.i386.rpm"))
381
382       self.assertTrue(storkpackage.is_package_understood(path + "stork/appman/remote/do_install/cpio-2.5-6.i386.rpm"))
383
384       self.assertTrue(storkpackage.is_package_understood(path + "stork/appman/remote/do_install/stork-slice-1.0.0b-3.i386.rpm"))
385       
386       self.assertTrue(storkpackage.is_package_understood(path + "stork/appman/remote/inst/authd-0.2.2-1.i386.rh9.rpm"))
387
388       self.assertTrue(storkpackage.is_package_understood(path + "stork/appman/remote/inst/pcp-0.3.3-1.i386.rh9.rpm"))
389       
390       self.assertTrue(storkpackage.is_package_understood(path + "stork/appman/remote/inst/tcp_wrappers-7.6-36.i386.rpm"))
391
392       self.assertTrue(storkpackage.is_package_understood(path + "stork/appman/remote/inst/xinetd-2.3.13-2.i386.rpm"))
393
394       self.assertTrue(storkpackage.is_package_understood(path + "stork/pyspecer/stork/BitTorrent-4.0.4-1.noarch.rpm"))
395
396       self.assertTrue(storkpackage.is_package_understood(path + "stork/pyspecer/stork/PyXML-0.8.3-6.i386.rpm"))
397
398       self.assertTrue(storkpackage.is_package_understood(path + "stork/pyspecer/stork/cpio-2.5-6.i386.rpm"))
399
400       self.debug_print("passed rpm packages")
401       
402       # "tar" is not set as a package manager, so the calls should return false:
403       self.assertFalse(storkpackage.is_package_understood(path + "stork/testpack/storkd-0.1.0.tar.gz"))
404
405       self.assertFalse(storkpackage.is_package_understood(path + "stork/testpack/testa-0.1.tar.gz"))
406
407       self.assertFalse(storkpackage.is_package_understood(path + "stork/testpack/testa-0.2.tar.gz"))
408
409       self.assertFalse(storkpackage.is_package_understood(path + "stork/testpack/testb-0.1.tar.gz"))
410
411       self.assertFalse(storkpackage.is_package_understood(path + "stork/testpack/testb-10.1.tar.gz"))
412
413       self.assertFalse(storkpackage.is_package_understood(path + "stork/testpack/testb-9.1.tar.gz"))
414
415       self.assertFalse(storkpackage.is_package_understood(path + "stork/python/tests/install.tar.gz"))
416
417       self.assertFalse(storkpackage.is_package_understood(path + "stork/python/refactor/package-dir.tar"))
418
419       self.debug_print("passed tar")
420       
421       
422       # test with both rpm and tar as package managers
423       self.reset_options()
424       arizonaconfig.set_option("packagemanagers", ["rpm", "tar"])
425       self.assertFalse( storkpackage.is_package_understood(" "))
426       self.assertFalse( storkpackage.is_package_understood('some invalid file name here'))
427       self.assertFalse( storkpackage.is_package_understood("filename "))
428       
429       self.assertFalse( storkpackage.is_package_understood( "-*"))
430       # the following two lines freeze up is_package_understood()
431       #self.assertFalse( storkpackage.is_package_understood( "-"))
432       #self.assertFalse( storkpackage.is_package_understood( "- "))
433       self.assertFalse( storkpackage.is_package_understood("- dashSpaceAndSomeName"))         
434       self.assertFalse( storkpackage.is_package_understood("123"))
435       self.assertFalse( storkpackage.is_package_understood(prefix + "/package/storkrpm.pyc"))
436       self.assertFalse( storkpackage.is_package_understood(prefix + "/package/storktar.pyc"))
437       # now test with valid filenames
438       self.debug_print("passed invalid filenames")
439       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/storkd-0.1.0.tar.gz"))
440       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testa-0.1.tar.gz"))
441       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testa-0.2.tar.gz"))
442       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testb-0.1.tar.gz"))
443       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testb-10.1.tar.gz"))
444       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testb-9.1.tar.gz"))
445       self.assertTrue(storkpackage.is_package_understood(path + "stork/python/tests/install.tar.gz"))
446       self.assertTrue(storkpackage.is_package_understood(path + "stork/python/refactor/package-dir.tar"))
447       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/stork-0.1.0-1.i386.rpm"))
448       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/stork-0.1.0-1.src.rpm"))
449       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/storkd-0.1.0-1.i386.rpm"))
450       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/storkd-0.1.0-1.src.rpm"))
451       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testa-0.1-1.i386.rpm"))
452       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testa-0.1-1.src.rpm"))
453       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testa-0.2-1.i386.rpm"))
454       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testa-0.2-1.src.rpm"))
455       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testb-0.1-1.i386.rpm"))
456       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testb-0.1-1.src.rpm"))
457       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testb-9.1-1.i386.rpm"))
458       self.assertTrue(storkpackage.is_package_understood(path + "stork/testpack/testb-9.1-1.src.rpm"))
459                                                                         
460       
461       # ---- TEST ENDS ------------------------------------------------------------------------------
462
463
464
465    #------------------------------------------------------------------
466    # get_package_metadata():
467    #------------------------------------------------------------------
468    def test_get_package_metadata(self): #(filename):
469       arizonaconfig.reset()
470       storkpackage.reset()
471
472       # pass invalid parameter
473       self.assertException(TypeError, storkpackage.get_package_metadata, [])
474       self.assertException(TypeError, storkpackage.get_package_metadata, {})
475       self.assertException(TypeError, storkpackage.get_package_metadata, ())
476       self.assertException(TypeError, storkpackage.get_package_metadata, 23)
477       self.assertException(TypeError, storkpackage.get_package_metadata, 34.5)
478       self.assertException(TypeError, storkpackage.get_package_metadata, ["asa"])
479
480       self.reset_options()
481
482       prefix = os.environ.get("TESTPREFIX")
483       # Make the following tests independent of the testing path:
484       # Extract the path where "stork/..." starts and leave the part before this substring to a variable
485       # that will change so that the tests can be run in different machines:
486       subIdx = prefix.find("stork")
487       path = prefix[:subIdx]
488       #self.debug_print(path)
489
490
491       #-------------------- SUBTEST STARTS --------------------------------------------------------
492       # Right now, test with rpm packages only:
493       arizonaconfig.set_option("packagemanagers", ['rpm'])
494       
495       # Make it raise TypeError with "unrecognized package format" message:
496       # Pass it a name of a file that does NOT exist:
497       self.assertException(TypeError, "Unrecognized package format", storkpackage.get_package_metadata, path + "stork/testpack/file-9.1-1.src.rpm")
498       self.assertExceptionMessage(TypeError, "Unrecognized package format",  storkpackage.get_package_metadata, "some unknown file")
499       self.assertExceptionMessage(TypeError, "Unrecognized package format",  storkpackage.get_package_metadata, "- some unknownfile")
500       self.assertExceptionMessage(TypeError, "Unrecognized package format",  storkpackage.get_package_metadata, "- ")
501       # Pass it an existing rpm file that is EMPTY:
502       self.assertExceptionMessage(TypeError, "Unrecognized package format",  storkpackage.get_package_metadata, path + "stork/testpack/testc-0.1-1.i386.rpm")
503       # Pass 'tar' packages
504       self.assertExceptionMessage(TypeError, "Unrecognized package format",  storkpackage.get_package_metadata, path + "stork/testpack/storkd-0.1.0.tar.gz")
505       self.assertExceptionMessage(TypeError, "Unrecognized package format",  storkpackage.get_package_metadata, path + "stork/testpack/testa-0.1.tar.gz")
506       self.assertExceptionMessage(TypeError, "Unrecognized package format",  storkpackage.get_package_metadata, path + "stork/testpack/testa-0.2.tar.gz")
507       self.assertExceptionMessage(TypeError, "Unrecognized package format",  storkpackage.get_package_metadata, path + "stork/testpack/testb-10.1.tar.gz")
508       self.assertExceptionMessage(TypeError, "Unrecognized package format",  storkpackage.get_package_metadata, path + "stork/python/tests/install.tar.gz")
509       self.assertExceptionMessage(TypeError, "Unrecognized package format",  storkpackage.get_package_metadata, path + "stork/python/refactor/package-dir.tar")
510       
511       
512       # TODO: Make it raise IOError:
513       # Do not open the file with "w" because this will erase its contents.
514       #f = file(path + "stork/testpack/testa-0.2-1.i386.rpm", "r")
515       #self.assertException(IOError, storkpackage.get_package_metadata, path + "stork/testpack/testa-0.2-1.i386.rpm")
516       #f.close()
517
518
519       # Pass valid 'rpm' package names
520       #self.debug_print(  storkpackage.get_package_metadata( path + "stork/testpack/testa-0.2-1.i386.rpm" ) )
521       # The dictionary returned must contain 9 key-value pairs with the following keys: 'filename', 'name',
522       # 'version', 'release', 'size', 'hash', 'provides', 'requires', 'files'.
523       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/testa-0.2-1.i386.rpm" ) ) )
524       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/stork-0.1.0-1.i386.rpm" ) ) )
525       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/storkd-0.1.0-1.i386.rpm" ) ) )
526       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/storkd-0.1.0-1.src.rpm" ) ) )
527       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/testa-0.2-1.i386.rpm" ) ) )
528       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/testb-0.1-1.i386.rpm" ) ) )
529       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/testb-9.1-1.src.rpm" ) ) )
530       
531       #-------------------- SUBTEST ENDS --------------------------------------------------------
532       
533
534       #-------------------- SUBTEST STARTS --------------------------------------------------------
535       # Now, test with 'tar' packages only:
536       arizonaconfig.reset()
537       self.reset_options()
538       arizonaconfig.set_option("packagemanagers", ['tar'])
539       self.assertEqual(arizonaconfig.get_option("packagemanagers"), ['tar'])
540       
541       # Make it raise TypeError with "unrecognized package format" message:
542       # Pass it a name of a file that does NOT exist:
543       self.assertException(TypeError, "Unrecognized package format", storkpackage.get_package_metadata, path + "stork/testpack/file-9.1-1.src.tar")
544       self.assertExceptionMessage(TypeError, "Unrecognized package format",  storkpackage.get_package_metadata, "some unknownfile")
545       self.assertExceptionMessage(TypeError, "Unrecognized package format",  storkpackage.get_package_metadata, "- some unknownfile")
546       self.assertExceptionMessage(TypeError, "Unrecognized package format",  storkpackage.get_package_metadata, "- ")
547       # Pass it an existing tar file that is EMPTY:
548       f = file(path + "stork/testpack/testc-0.1-1.i386.tar", 'w')
549       f.close()
550       self.assertExceptionMessage(TypeError, "Unrecognized package format",  storkpackage.get_package_metadata, path + "stork/testpack/testc-0.1-1.i386.tar")
551       os.remove(path + "stork/testpack/testc-0.1-1.i386.tar")
552       # make sure that the file was erased by this test
553       self.assertException(IOError, file, path + "stork/testpack/testc-0.1-1.i386.tar", "r")
554             
555       # Pass it 'rpm' packages
556       self.assertExceptionMessage( TypeError, "Unrecognized package format", storkpackage.get_package_metadata, path + "stork/testpack/testa-0.2-1.i386.rpm" )
557       self.assertExceptionMessage( TypeError, "Unrecognized package format", storkpackage.get_package_metadata, path + "stork/testpack/stork-0.1.0-1.i386.rpm" )
558       self.assertExceptionMessage( TypeError, "Unrecognized package format", storkpackage.get_package_metadata, path + "stork/testpack/storkd-0.1.0-1.i386.rpm"  )
559       self.assertExceptionMessage( TypeError, "Unrecognized package format", storkpackage.get_package_metadata, path + "stork/testpack/storkd-0.1.0-1.src.rpm" )
560       self.assertExceptionMessage( TypeError, "Unrecognized package format", storkpackage.get_package_metadata, path + "stork/testpack/testa-0.2-1.i386.rpm" ) 
561       self.assertExceptionMessage( TypeError, "Unrecognized package format", storkpackage.get_package_metadata, path + "stork/testpack/testb-0.1-1.i386.rpm" ) 
562       self.assertExceptionMessage( TypeError, "Unrecognized package format", storkpackage.get_package_metadata, path + "stork/testpack/testb-9.1-1.src.rpm" ) 
563                                           
564       # Pass valid 'tar' package names
565       # The dictionary returned must contain 9 key-value pairs with the following keys: 'filename', 'name',
566       # 'version', 'release', 'size', 'hash', 'provides', 'requires', 'files'.
567       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/storkd-0.1.0.tar.gz" ) ) )
568       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/testa-0.1.tar.gz") ) )
569       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/testa-0.2.tar.gz") ) )
570       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/testb-10.1.tar.gz") ) )
571       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/python/tests/install.tar.gz") ) )      
572       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/python/refactor/package-dir.tar") ) )
573                                                                   
574       #-------------------- SUBTEST ENDS --------------------------------------------------------
575
576
577       #-------------------- SUBTEST STARTS --------------------------------------------------------
578       # Now, test with both tar and rpm packages:
579       arizonaconfig.reset()
580       self.reset_options()
581       self.assertEqual(arizonaconfig.get_option("packagemanagers"), ['rpm', 'tar'])
582                         
583       # Pass valid 'tar' and 'rpm' package names
584       # The dictionary returned must contain 9 key-value pairs with the following keys: 'filename', 'name',
585       # 'version', 'release', 'size', 'hash', 'provides', 'requires', 'files'.
586       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/storkd-0.1.0.tar.gz" ) ) )
587       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/testa-0.1.tar.gz") ) )
588       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/testa-0.2.tar.gz") ) )
589       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/testb-10.1.tar.gz") ) )
590       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/python/tests/install.tar.gz") ) )
591       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/python/refactor/package-dir.tar") ) )
592       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/testa-0.2-1.i386.rpm" ) ) )
593       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/stork-0.1.0-1.i386.rpm" ) ) )
594       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/storkd-0.1.0-1.i386.rpm" ) ) )
595       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/storkd-0.1.0-1.src.rpm" ) ) )
596       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/testa-0.2-1.i386.rpm" ) ) )
597       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/testb-0.1-1.i386.rpm" ) ) )
598       self.assertEqual( 9, len( storkpackage.get_package_metadata( path + "stork/testpack/testb-9.1-1.src.rpm" ) ) )
599                                           
600       #-------------------- SUBTEST ENDS --------------------------------------------------------
601       
602
603
604    #------------------------------------------------------------------
605    # get_packages_provide():
606    #------------------------------------------------------------------
607    def test_get_packages_provide(self):
608       self.reset_options()
609
610       self.assertException(TypeError, storkpackage.get_packages_provide, "filename")
611       self.assertException(TypeError, storkpackage.get_packages_provide, "")
612       self.assertException(TypeError, storkpackage.get_packages_provide, {})
613       self.assertException(TypeError, storkpackage.get_packages_provide, ())
614       self.assertException(TypeError, storkpackage.get_packages_provide, 23)
615
616       # set arizonaconfig to its initial state so that "packagemanagers" options is not set.
617       #self.reset_options()
618       arizonaconfig.reset()
619       #storkpackage.reset()
620       self.assertEqual([], storkpackage.get_packages_provide([]))
621       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: missing --packagemanagers setting", storkpackage.get_packages_provide, ['filename'])
622
623
624       # Make the following tests independent of the testing path:
625       # Extract the path where "stork/..." starts and leave the part before this substring to a variable
626       # that will change so that the tests can be run in different machines:
627       prefix = os.environ.get("TESTPREFIX")
628       subIdx = prefix.find("stork")
629       path = prefix[:subIdx]
630       #self.debug_print(path)
631
632                                     
633       # Set the options so that initialize() does not throw an exception
634       self.reset_options()
635       self.assertEqual([], storkpackage.get_packages_provide(["filename"]))
636       self.assertEqual([], storkpackage.get_packages_provide([]))
637       # subtests with valid rpm and tar packages
638       self.debug_print(storkpackage.get_packages_provide([path + "stork/testpack/testb-9.1-1.src.rpm"]))
639       self.debug_print(storkpackage.get_packages_provide([path + "stork/python/tests/install.tar.gz"]))
640
641       # TODO: figure out how to test when passing the valid packages
642
643
644       # Set the options so that initialize() throws a "no usable packages" error:
645       arizonaconfig.set_option("packagemanagers", "none")
646       self.assertEqual([], storkpackage.get_packages_provide([]))
647       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: no usable package managers.", storkpackage.get_packages_provide, ['filename'])
648
649       
650
651    #------------------------------------------------------------------
652    # get_packages_require():
653    #------------------------------------------------------------------
654    def test_get_packages_require(self):
655
656       self.assertException(TypeError, storkpackage.get_packages_require, "filename")
657       self.assertException(TypeError, storkpackage.get_packages_require, "")
658       self.assertException(TypeError, storkpackage.get_packages_require, {})
659       self.assertException(TypeError, storkpackage.get_packages_require, ())
660       self.assertException(TypeError, storkpackage.get_packages_require, 23)
661
662       # set arizonaconfig to its initial state so that "packagemanagers" options is not set.
663       #self.reset_options()
664       arizonaconfig.reset()
665       #storkpackage.reset()
666       self.assertEqual([], storkpackage.get_packages_require([]))
667       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: missing --packagemanagers setting", storkpackage.get_packages_require, ['filename'])
668
669
670       # Make the following tests independent of the testing path:
671       # Extract the path where "stork/..." starts and leave the part before this substring to a variable
672       # that will change so that the tests can be run in different machines:
673       prefix = os.environ.get("TESTPREFIX")
674       subIdx = prefix.find("stork")
675       path = prefix[:subIdx]
676       #self.debug_print(path)
677
678
679       # Set the options so that initialize() does not throw an exception
680       self.reset_options()
681       self.assertEqual([], storkpackage.get_packages_require(["filename"]))
682       self.assertEqual([], storkpackage.get_packages_require([]))
683       # subtests with valid rpm and tar packages
684       self.debug_print(storkpackage.get_packages_require([path + "stork/testpack/testb-9.1-1.src.rpm"]))
685       self.debug_print(storkpackage.get_packages_require([path + "stork/python/tests/install.tar.gz"]))
686
687       # TODO: figure out how to test when passing the valid packages
688                                                                                     
689
690       # Set the options so that initialize() throws a "no usable packages" error:
691       arizonaconfig.set_option("packagemanagers", "none")
692       self.assertEqual([], storkpackage.get_packages_require([]))
693       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: no usable package managers.", storkpackage.get_packages_require, ['filename'])
694
695                         
696
697    #------------------------------------------------------------------
698    # get_packages_files():
699    #------------------------------------------------------------------
700    def test_get_packages_files(self):
701       # Pass invalid data
702       self.assertException(TypeError, storkpackage.get_packages_files, 23)
703       self.assertException(TypeError, storkpackage.get_packages_files, ())
704       self.assertException(TypeError, storkpackage.get_packages_files, {})
705       self.assertException(TypeError, storkpackage.get_packages_files, [[]])
706       self.assertException(TypeError, storkpackage.get_packages_files, 'string')
707       self.assertException(TypeError, storkpackage.get_packages_files, 23.4)
708
709       # Should simply return an empty list if an empty list is passed:
710       self.assertEqual([], storkpackage.get_packages_files( [] ) )
711
712       arizonaconfig.reset()
713       storkpackage.reset()
714       self.reset_options()
715
716
717       # Make the following tests independent of the testing path:
718       # Extract the path where "stork/..." starts and leave the part before this substring to a variable
719       # that will change so that the tests can be run in different machines:
720       prefix = os.environ.get("TESTPREFIX")
721       subIdx = prefix.find("stork")
722       path = prefix[:subIdx]
723       #self.debug_print(path)
724                                     
725
726       #----------------------- SUBTEST STARTS --------------------------------------------------------------
727       # Test with only 'rpm' as a package manager
728       arizonaconfig.set_option("packagemanagers", ['rpm'])
729       self.assertEqual(['rpm'], arizonaconfig.get_option( "packagemanagers" ) )
730       
731       # Pass it non-existent files:
732       self.assertEqual( [], storkpackage.get_packages_files( [path + "stork/testpack/testb-9.1-1.src.tar"] ) )
733       self.assertEqual( [], storkpackage.get_packages_files( [path + "filename"] ) )
734       self.assertEqual( [], storkpackage.get_packages_files( ["what"] ) )
735       self.assertEqual( [], storkpackage.get_packages_files( ["some", 'unknown', 'file', 'name'] ) )
736       
737       # Pass it 'tar' packages:
738       self.assertEqual( [], storkpackage.get_packages_files( [path + "stork/python/tests/install.tar.gz"] ) )
739       self.assertEqual( [], storkpackage.get_packages_files( [path + "stork/testpack/storkd-0.1.0.tar.gz"] ) )
740       
741       # Pass it 'rpm' packages 
742       self.assertFalse(['(contains no files)'] == storkpackage.get_packages_files( [path + "stork/testpack/testb-9.1-1.src.rpm"] ) )
743       self.assertFalse(['(contains no files)'] == storkpackage.get_packages_files( [path + "stork/testpack/testb-0.1-1.i386.rpm"] ) )
744       self.assertFalse(['(contains no files)']== storkpackage.get_packages_files( [path + "stork/testpack/stork-0.1.0-1.i386.rpm"] ) )
745       self.assertFalse(['(contains no files)']== storkpackage.get_packages_files( [path + "stork/testpack/testa-0.2-1.i386.rpm"] ) )
746       self.assertFalse(['(contains no files)']== storkpackage.get_packages_files( [path + "stork/testpack/storkd-0.1.0-1.src.rpm"] ) )
747       
748       #----------------------- SUBTEST ENDS --------------------------------------------------------------
749       
750
751       #----------------------- SUBTEST STARTS --------------------------------------------------------------
752       # Test with only 'tar' as a package manager
753       arizonaconfig.reset()
754       storkpackage.reset()
755       self.reset_options()
756       arizonaconfig.set_option("packagemanagers", ['tar'] )
757       self.assertEqual( ['tar'], arizonaconfig.get_option("packagemanagers") )
758       
759       # Pass it non-existent files:
760       self.assertEqual( [], storkpackage.get_packages_files( [path + "stork/testpack/testb.s9.1-1.src.rpm"] ) )
761       self.assertEqual( [], storkpackage.get_packages_files( [path + "filename"] ) )
762       self.assertEqual( [], storkpackage.get_packages_files( ["what"] ) )
763       self.assertEqual( [], storkpackage.get_packages_files( ["some", 'unknown', 'file', 'name'] ) )
764
765       # Pass it 'rpm' packages
766       self.assertEqual([], storkpackage.get_packages_files( [path + "stork/testpack/testb-9.1-1.src.rpm"] ) )
767       self.assertEqual([], storkpackage.get_packages_files( [path + "stork/testpack/testb-0.1-1.i386.rpm"] ) )
768       self.assertEqual([], storkpackage.get_packages_files( [path + "stork/testpack/stork-0.1.0-1.i386.rpm"] ) )
769       self.assertEqual([], storkpackage.get_packages_files( [path + "stork/testpack/testa-0.2-1.i386.rpm"] ) )
770       self.assertEqual([], storkpackage.get_packages_files( [path + "stork/testpack/storkd-0.1.0-1.src.rpm"] ) )
771
772       # Pass it 'tar' packages
773       self.assertFalse( ['(contains no files)']== storkpackage.get_packages_files( [ path + "stork/testpack/storkd-0.1.0.tar.gz"] ) )
774       self.assertFalse( ['(contains no files)']== storkpackage.get_packages_files( [ path + "stork/testpack/testa-0.1.tar.gz"] ) )
775       self.assertFalse( ['(contains no files)']== storkpackage.get_packages_files( [path + "stork/testpack/testa-0.2.tar.gz"] ) )
776       self.assertFalse( ['(contains no files)']== storkpackage.get_packages_files( [path + "stork/testpack/testb-10.1.tar.gz"] ) )
777       self.assertFalse( ['(contains no files)']== storkpackage.get_packages_files( [path + "stork/python/tests/install.tar.gz"] ) )
778       self.assertFalse( ['(contains no files)']== storkpackage.get_packages_files( [path + "stork/python/refactor/package-dir.tar"] ) ) 
779                                     
780       #----------------------- SUBTEST ENDS --------------------------------------------------------------
781       
782
783       #----------------------- SUBTEST STARTS --------------------------------------------------------------
784       # Test with both 'rpm' and 'tar' as package managers
785       #----------------------- SUBTEST ENDS --------------------------------------------------------------
786       arizonaconfig.reset()
787       storkpackage.reset()
788       self.reset_options()
789       self.assertEqual( ['rpm', 'tar'], arizonaconfig.get_option("packagemanagers") )
790       
791       # Pass it non-existent files:
792       self.assertEqual( [], storkpackage.get_packages_files( [path + "stork/testpack/testb.s9.1-1.src.rpm"] ) )
793       self.assertEqual( [], storkpackage.get_packages_files( [path + "filename"] ) )
794       self.assertEqual( [], storkpackage.get_packages_files( ["what"] ) )
795       self.assertEqual( [], storkpackage.get_packages_files( ["some", 'unknown', 'file', 'name'] ) )
796       self.assertEqual( [], storkpackage.get_packages_files( [path + "stork/python/refactor/pakage-dir.tar"] ) )
797
798       # Pass it valid 'rpm' and 'tar' files
799       self.assertFalse( ['(contains no files)']== storkpackage.get_packages_files( [ path + "stork/testpack/storkd-0.1.0.tar.gz"] ) )
800       self.assertFalse( ['(contains no files)']== storkpackage.get_packages_files( [ path + "stork/testpack/testa-0.1.tar.gz"] ) )
801       self.assertFalse( ['(contains no files)']== storkpackage.get_packages_files( [path + "stork/testpack/testa-0.2.tar.gz"]) )
802       self.assertFalse( ['(contains no files)']== storkpackage.get_packages_files( [path + "stork/testpack/testb-10.1.tar.gz" ] ) )
803       self.assertFalse( ['(contains no files)']== storkpackage.get_packages_files( [path + "stork/python/tests/install.tar.gz"] ) )
804       self.assertFalse( ['(contains no files)']== storkpackage.get_packages_files( [path + "stork/python/refactor/package-dir.tar"] ) )
805                                     
806       self.assertFalse(['(contains no files)'] == storkpackage.get_packages_files( [path + "stork/testpack/testb-9.1-1.src.r\
807 pm"] ) )
808       self.assertFalse(['(contains no files)'] == storkpackage.get_packages_files( [path + "stork/testpack/testb-0.1-1.i386.\
809 rpm"] ) )
810       self.assertFalse(['(contains no files)']== storkpackage.get_packages_files( [path + "stork/testpack/stork-0.1.0-1.i386\
811 .rpm"] ) )
812       self.assertFalse(['(contains no files)']== storkpackage.get_packages_files( [path + "stork/testpack/testa-0.2-1.i386.r\
813 pm"] ) )
814       self.assertFalse(['(contains no files)']== storkpackage.get_packages_files( [path + "stork/testpack/storkd-0.1.0-1.src\
815 .rpm"] ) )
816
817       # (if it contains no files, should return [], not ['(contains no files)']
818
819
820    #------------------------------------------------------------------
821    # get_package_info():
822    #------------------------------------------------------------------
823    def test_get_package_info(self): #, filename):
824       reload(storkpackage)
825
826       # test with invalid input:
827       self.assertRaises(TypeError, storkpackage.get_package_info, None)
828       self.assertRaises(TypeError, storkpackage.get_package_info, [])
829       self.assertRaises(TypeError, storkpackage.get_package_info, ["sdsd"])
830       self.assertRaises(TypeError, storkpackage.get_package_info, 23)
831       self.assertRaises(TypeError, storkpackage.get_package_info, 56.3)
832
833       self.assertExceptionMessage(arizonageneral.Exception_Data, "ERROR: missing --packagemanagers setting", storkpackage.get_package_info, 'filename')
834
835       self.assertException(Exception, storkpackage.get_package_info)
836
837       # White box: do preparation so that some needed options are initialized 
838       # prior to running this method
839
840       # Make the following tests independent of the testing path:
841       # Extract the path where "stork/..." starts and leave the part before this substring to a variable
842       # that will change so that the tests can be run in different machines:
843       prefix = os.environ.get("TESTPREFIX")
844       subIdx = prefix.find("stork")
845       path = prefix[:subIdx]
846       self.debug_print(path)
847                                     
848       # ---- TEST STARTS ------------------------------------------------------------------------------
849       # Test for when the variable "tarpackinfopack" is not set
850       self.reset_options()
851       self.assertEqual(arizonaconfig.get_option("tarpackinfopath"), "/usr/local/stork/tar_packinfo")
852       arizonaconfig.set_option("tarpackinfopath", None)
853       self.assertEqual(arizonaconfig.get_option("tarpackinfopath"), None)
854       # packagemanagers variable is already set.
855       self.assertEquals(['rpm', 'tar'], arizonaconfig.get_option("packagemanagers"))
856       # After the call to get_package_info(), only the rpm package manager should be set, since
857       # the variable for tar is set to None. Should not raise any excepions and simply return None if the
858       # file given is not an rpm package, or the info if it is an rpm package.
859       self.assertEqual(storkpackage.get_package_info("filename"), None)
860       self.assertEqual(storkpackage.get_package_info(""), None)
861       self.assertEqual(storkpackage.get_package_info("."), None)
862       # The following two lines make storktar freeze up:
863       #self.assertEqual(None, storkpackage.get_package_info("-"))
864       #self.assertEqual(None, storkpackage.get_package_info("- "))
865       
866       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/storkd-0.1.0.tar.gz"))
867       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/testa-0.1.tar.gz"))
868       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/testa-0.2.tar.gz"))
869       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/testb-0.1.tar.gz"))
870       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/testb-10.1.tar.gz"))
871       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/testb-9.1.tar.gz"))
872       self.assertEqual(None, storkpackage.get_package_info(path + "stork/python/tests/install.tar.gz"))
873       self.assertEqual(None, storkpackage.get_package_info(path + "stork/python/refactor/package-dir.tar"))
874                                                 
875       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testb-9.1-1.src.rpm"))
876       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/stork-0.1.0-1.i386.rpm"))
877       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/stork-0.1.0-1.src.rpm"))
878       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/storkd-0.1.0-1.i386.rpm"))
879       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/storkd-0.1.0-1.src.rpm"))
880       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testa-0.1-1.i386.rpm"))
881       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testa-0.1-1.src.rpm"))
882       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testa-0.2-1.i386.rpm"))
883       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testa-0.2-1.src.rpm"))
884       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testb-0.1-1.i386.rpm"))
885       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testb-0.1-1.src.rpm"))
886       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testb-9.1-1.i386.rpm"))
887       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testb-9.1-1.src.rpm"))
888
889                                                                    
890       # ---- TEST ENDS ------------------------------------------------------------------------------
891             
892
893       # ---- TEST STARTS ------------------------------------------------------------------------------
894       # Prepare the options to test storkpackage: make sure init_options 
895       # run successfully but storkpackage.initialize() DOES find 
896       # USABLE package managers:
897
898       # set or re-set the options since the tests are not called in order
899       self.reset_options()
900
901       # create new option
902       arizonaconfig.set_option("packagemanagers", ['rpm', 'tar'])
903       self.assertEqual(arizonaconfig.get_option("packagemanagers"), ['rpm', 'tar'])
904
905       # The variable tested below has to be set for tar packages. Note that storkpackage.py will try
906       # to create this directory if it does not exist. However, if these tests are run in a restriced
907       # profile, then storktar will not be able to create the new directory and the tests will fail.
908       # Exchange the original string (the directory that will be created by storktar) with a string
909       # that will result in the directory being able to get created in the restriced machine:
910       #self.assertEqual("/usr/local/stork/tar_packinfo", arizonaconfig.get_option("tarpackinfopath"))
911       arizonaconfig.set_option("tarpackinfopath", path + "/usr/local/stork/tar_packinfo")
912                               
913       # Now that the options have been successfuly called, 
914       # test the method with wrong package names:
915       self.assertEqual(None,  storkpackage.get_package_info("some wrong filename"))
916       self.assertEqual(None,  storkpackage.get_package_info(""))
917       self.assertEqual(None, storkpackage.get_package_info(" "))
918       self.assertEqual(None, storkpackage.get_package_info("rpm"))
919       self.assertEqual(None, storkpackage.get_package_info("targz"))
920       self.assertEqual(None, storkpackage.get_package_info("."))
921       # The following two lines make storktar freeze up:
922       #self.assertEqual(None, storkpackage.get_package_info("-"))
923       #self.assertEqual(None, storkpackage.get_package_info("- "))
924             
925       # Test the method with correct package names:
926       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testa-0.1.tar.gz"))
927       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testb-9.1-1.src.rpm"))
928       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/stork-0.1.0-1.i386.rpm"))
929       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/stork-0.1.0-1.src.rpm"))
930       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/storkd-0.1.0-1.i386.rpm"))
931       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/storkd-0.1.0-1.src.rpm"))
932       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testa-0.1-1.i386.rpm"))
933       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testa-0.1-1.src.rpm"))
934       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testa-0.2-1.i386.rpm"))
935       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testa-0.2-1.src.rpm"))
936       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testb-0.1-1.i386.rpm"))
937       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testb-0.1-1.src.rpm"))
938       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testb-9.1-1.i386.rpm"))
939       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testb-9.1-1.src.rpm"))
940       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/storkd-0.1.0.tar.gz"))
941       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testa-0.1.tar.gz"))
942       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testa-0.2.tar.gz"))
943       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testb-0.1.tar.gz"))
944       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testb-10.1.tar.gz"))
945       self.assertTrue(storkpackage.get_package_info(path + "stork/testpack/testb-9.1.tar.gz"))
946       self.assertTrue(storkpackage.get_package_info(path + "stork/python/tests/install.tar.gz"))
947       self.assertTrue(storkpackage.get_package_info(path + "stork/python/refactor/package-dir.tar"))
948                                                 
949       # ---- TEST ENDS ------------------------------------------------------------------------------
950
951
952       # ---- TEST STARTS ------------------------------------------------------------------------------
953       # Check only with 'tar' packages
954       arizonaconfig.reset()
955       self.reset_options()
956       arizonaconfig.set_option("packagemanagers", ['tar'])
957       self.assertEqual( ['tar'], arizonaconfig.get_option("packagemanagers"))
958
959       # The variable tested below has to be set for tar packages. Note that storkpackage.py will try
960
961       # The variable tested below has to be set for tar packages. Note that storkpackage.py will try
962       # to create this directory if it does not exist. However, if these tests are run in a restriced
963       # profile, then storktar will not be able to create the new directory and the tests will fail.
964       # Exchange the original string (the directory that will be created by storktar) with a string
965       # that will result in the directory being able to get created in the restriced machine:
966       #self.assertEqual("/usr/local/stork/tar_packinfo", arizonaconfig.get_option("tarpackinfopath"))
967       arizonaconfig.set_option("tarpackinfopath", path + "/usr/local/stork/tar_packinfo")
968
969       # Pass 'rpm' packages
970       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/testb-9.1-1.src.rpm"))
971       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/stork-0.1.0-1.i386.rpm"))
972       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/stork-0.1.0-1.src.rpm"))
973       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/storkd-0.1.0-1.i386.rpm"))
974       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/storkd-0.1.0-1.src.rpm"))
975       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/testa-0.1-1.i386.rpm"))
976       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/testa-0.1-1.src.rpm"))
977       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/testa-0.2-1.i386.rpm"))
978       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/testa-0.2-1.src.rpm"))
979       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/testb-0.1-1.i386.rpm"))
980       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/testb-0.1-1.src.rpm"))
981       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/testb-9.1-1.i386.rpm"))
982       self.assertEqual(None, storkpackage.get_package_info(path + "stork/testpack/testb-9.1-1.src.rpm"))
983                                                                               
984       # Pass 'tar' packages
985       self.assertTrue( storkpackage.get_package_info(path + "stork/testpack/storkd-0.1.0.tar.gz"))
986       self.assertTrue( storkpackage.get_package_info(path + "stork/testpack/testa-0.1.tar.gz"))
987       self.assertTrue( storkpackage.get_package_info(path + "stork/testpack/testa-0.2.tar.gz"))
988       self.assertTrue( storkpackage.get_package_info(path + "stork/testpack/testb-0.1.tar.gz"))
989       self.assertTrue( storkpackage.get_package_info(path + "stork/testpack/testb-10.1.tar.gz"))
990       self.assertTrue( storkpackage.get_package_info(path + "stork/testpack/testb-9.1.tar.gz"))
991       self.assertTrue( storkpackage.get_package_info(path + "stork/python/tests/install.tar.gz"))
992       self.assertTrue( storkpackage.get_package_info(path + "stork/python/refactor/package-dir.tar"))
993                                                 
994       # ---- TEST ENDS ------------------------------------------------------------------------------
995       
996
997       
998    #------------------------------------------------------------------
999    # get_installed_versions():
1000    #------------------------------------------------------------------
1001    def test_get_installed_versions(package_list):
1002       pass
1003
1004
1005    #------------------------------------------------------------------
1006    # get_installedpackages_fulfulling():
1007    #------------------------------------------------------------------
1008    def test_get_installedpackages_fulfilling(dep_list):
1009       pass
1010
1011
1012    #------------------------------------------------------------------
1013    # get_installedpackages_provide():
1014    #------------------------------------------------------------------
1015    def test_get_installedpackages_provide(package_list):
1016       pass
1017   
1018    #-----------------------------------
1019    # execute(trans_list)
1020    #-----------------------------------
1021    def test_execute(self):
1022       pass
1023   
1024    #-----------------------------------
1025    # remove(package_list, nodeps=False)
1026    #-----------------------------------
1027    def test_remove(self):
1028       pass
1029
1030
1031
1032   
1033       
1034 # Run tests
1035 if __name__ == '__main__':
1036    arizonaconfig.init_options("storkpackageTest" ) 
1037    arizonaconfig.set_option("packagemanagers",["rpm"]) 
1038    arizonaconfig.set_option("hashtype",["-sha1"]) 
1039    arizonaunittest.main()