import repository from arizona
[raven.git] / 2.0 / python / test / storkpackagelistTest.py
1 #! /usr/bin/env python
2 """
3 <Module>
4    storkpackagelistTest
5 <Author>
6    Jeffry Johnston, under the direction of Justin Cappos
7
8    Extended by Mario Gonzalez.
9
10 <Started>
11    October 13, 2005   
12 <Purpose>
13    Test module for storkpackagelist.  See storkpackagelist.py for more 
14    details.
15 """
16
17 import os
18 import arizonaconfig
19 import arizonatransfer
20 import arizonaunittest
21 import storkpackagelist
22
23 # Unit tests for each function, listed in code order
24 class test(arizonaunittest.TestCase):
25
26    #------------------------------------------------------------------
27    # reset_options()
28    #------------------------------------------------------------------
29    def reset_options(self):
30       self.set_cmdline([])
31       prefix = os.environ.get("TESTPREFIX")
32       #reload(storkpackagelist)
33       arizonaconfig.init_options("storkpackagelist.py", alt_paths=[prefix], version="2.0")
34
35
36    #------------------------------------------------------------------
37    # init():
38    #------------------------------------------------------------------
39    def test_init(self):
40       self.reset_options()
41       prefix = os.getenv('TESTPREFIX')
42
43       # test without initializing the "pdir" option:
44       self.assertException(SystemExit, storkpackagelist.init)
45
46       # test without initializing the "repinfo" option:
47       arizonaconfig.init_options("storkpackagelist.py", alt_paths = [prefix], version='2.0')
48       arizonaconfig.set_option("pdir", ["nr06.cs.arizona.edu/PlanetLab/V3/dist"])
49       self.assertException(SystemExit, storkpackagelist.init)
50       self.reset_options()
51
52
53       # test with both options initialized. Test with "updatedb" unset.
54       arizonaconfig.init_options("storkpackagelist.py", alt_paths = [prefix], version='2.0')
55       # shouldn't init_options() set all the variables by itself?
56       # NOTE that currently, if "updatedb" variable is not set manually, then calling get_option("updatedb") returns None.
57       arizonaconfig.set_option("pdir", ["nr06.cs.arizona.edu/PlanetLab/V3/dist"])
58       arizonaconfig.set_option("repinfo", ["nr06.cs.arizona.edu/packageinfo"])
59       # localpdir will now be populated with "nr06.cs.arizona.edu_PlanetLab_V3_dist" and set_option will be called
60       # with the string  "localpdir" and the newly created list.
61       # Since the variable "localinfo" has not been set yet, it should give an error
62       #self.assertException(TypeError, storkpackagelist.init)
63       # now set the "localinfo" variable and call init().
64       arizonaconfig.set_option("localinfo", "/usr/local/stork/var/packageinfo")
65       storkpackagelist.init()
66       self.assertEquals(["nr06.cs.arizona.edu_PlanetLab_V3_dist"], arizonaconfig.get_option("localpdir"))
67             
68    
69       # Manually set "updatedb" to false and test init()
70       self.reset_options()
71       arizonaconfig.set_option("updatedb", False)
72       arizonaconfig.set_option("pdir", ["nr06.cs.arizona.edu/PlanetLab/V3/dist"])
73       arizonaconfig.set_option("repinfo", ["nr06.cs.arizona.edu/packageinfo"])
74       # localpdir will now be populated with "nr06.cs.arizona.edu_packageinfo" and set_option will be called
75       # with the string  "localpdir" and the newly created list.
76       # Since the variable "localinfo" has not been set yet, it should give an error
77       self.assertException(TypeError, storkpackagelist.init)
78       # now set the "localinfo" variable and call init().
79       arizonaconfig.set_option("localinfo", "/usr/local/stork/var/packageinfo")
80       storkpackagelist.init()
81       self.assertEquals(["nr06.cs.arizona.edu_PlanetLab_V3_dist"], arizonaconfig.get_option("localpdir"))
82       
83
84       # Manually set "updatedb" to true and test init()
85       self.reset_options()
86       arizonaconfig.set_option("updatedb", True)
87       arizonaconfig.set_option("pdir", ["nr06.cs.arizona.edu/PlanetLab/V3/dist"])
88       arizonaconfig.set_option("repinfo", ["nr06.cs.arizona.edu/packageinfo"])
89       # Since the variable "localinfo" has not been set yet, it should give an error
90       self.assertException(TypeError, storkpackagelist.init)
91       # now set the "localinfo" variable and call init().
92       arizonaconfig.set_option("localinfo", "/usr/local/stork/var/packageinfo")
93       storkpackagelist.init()
94       self.assertEquals(["nr06.cs.arizona.edu_PlanetLab_V3_dist"], arizonaconfig.get_option("localpdir"))
95
96       
97
98       # TODO: test that a database directory for "nr06.cs.arizona.edu_packageinfo" is found AND also
99       # TODO: test that a database directory for "nr06.cs.arizona.edu_packageinfo" is NOT found
100
101
102       # Assuming a database directory is found:
103       # If the option "updatedb" is true in the arizonaconfig block of storkpackagelist, then
104       # the package info (the metadata) will be updated.
105       #
106       # TODO: make sure package files are not retrieved successfully and get the error report
107
108       # TODO: make sure package files ARE retrieved successfully and report.
109       
110
111       # Test when updatedb is set to FALSE
112       reload(storkpackagelist)
113       arizonaconfig.init_options("storkpackagelist.py")
114       arizonaconfig.set_option("updatedb", False)
115       arizonaconfig.set_option("pdir", ["nr06.cs.arizona.edu/PlanetLab/V3/dist"])
116       arizonaconfig.set_option("repinfo", ["nr06.cs.arizona.edu/packageinfo"])
117       storkpackagelist.init()                     
118
119
120       # Now test everything above without manually setting the options for storkpackagelist: that is,
121       # only use arizonaconfig.init_options(..)
122       # TODO:
123
124             
125       # NOT SURE IF IT STILL APPLIES:
126       # CURRENTLY, init() only works if set_option() is used explicitly with "localinfo".
127       # Should work fine without this, though.
128       #arizonaconfig.set_option("localinfo", "some path")
129       storkpackagelist.init()
130       #except:
131          # is it that it could not locate a database directory for some option?
132          # TODO: figure out how to get the send_error() messages
133          ## Let's see what "localpdir" returns (the assertion failure, if any, will contain the return value):
134          #self.assertEquals(None, arizonaconfig.get_option("localpdir"))
135          #pass
136
137
138    #------------------------------------------------------------------
139    # package_exists():
140    #------------------------------------------------------------------
141    def test_package_exists(self):
142       self.reset_options()
143       
144
145       # should return None if None is passed:
146       self.assertEquals(None, storkpackagelist.package_exists(None))
147
148       # pass invalid input
149       self.assertRaises(Exception, storkpackagelist.package_exists, 3.0)
150
151       # ON HOLD-- docs may be wrong
152       ## pass names that are not known packages without initializing the options.
153       ## Should return None:
154       #self.assertEquals(None, storkpackagelist.package_exists(" "))
155       #self.assertEquals(None, storkpackagelist.package_exists("some unknown package"))
156
157       # pass names that are not known packages, but initialize options first
158       # since arizonaconfig.get_options() is used:
159       prefix = os.environ.get("TESTPREFIX")
160       arizonaconfig.init_options("storkpackagelist.py", alt_paths=[prefix], version='2.0')
161       #arizonaconfig.set_option("localpdir", ["some string"]) <- this should not be set manually
162       # now set the "localinfo" variable and call init().
163       arizonaconfig.set_option("localinfo", "/usr/local/stork/var/packageinfo")
164       arizonaconfig.set_option("pdir", ["nr06.cs.arizona.edu/PlanetLab/V3/dist"])
165       arizonaconfig.set_option("repinfo", ["nr06.cs.arizona.edu/packageinfo"])
166       storkpackagelist.init()
167       self.assertFalse(storkpackagelist.package_exists("hello"))
168       self.assertFalse(storkpackagelist.package_exists("some unknown name"))
169       self.assertFalse(storkpackagelist.package_exists("gnuchess"))
170       self.assertFalse(storkpackagelist.package_exists(" "))
171
172       # this test was from Jeffry Johnston.
173       # NOTE that currently, it only works if the metadata exists on the system.
174       arizonaconfig.init_options("storkpackagelist.py", alt_paths = [prefix], version = '2.0')
175       arizonaconfig.set_option("updatedb", False)
176       arizonaconfig.set_option("pdir", ["nr06.cs.arizona.edu/PlanetLab/V3/dist/"])
177       arizonaconfig.set_option("repinfo", ["nr06.cs.arizona.edu/packageinfo"])
178       storkpackagelist.init()
179       self.assertTrue(storkpackagelist.package_exists("gnuchess"))
180       
181
182
183    #------------------------------------------------------------------------------------
184    # find_package_name()
185    #------------------------------------------------------------------------------------
186    def test_find_package_name(self):
187
188       self.reset_options()
189
190       # set the options needed by storkpackagelist.init()
191       arizonaconfig.set_option("pdir", ["nr06.cs.arizona.edu/PlanetLab/V3/dist"])
192       arizonaconfig.set_option("repinfo", ["nr06.cs.arizona.edu/packageinfo"])
193       storkpackagelist.init()
194       self.assertEquals( "/usr/local/stork/var/packageinfo", arizonaconfig.get_option("localinfo") )
195       # init() should have set the localpdir variable
196
197       # Should return None if nothing is found
198       self.assertEquals(None, storkpackagelist.find_package_name('stork'))
199       self.assertEquals(None, storkpackagelist.find_package_name(''))
200       self.assertEquals(None, storkpackagelist.find_package_name(' '))
201       self.assertEquals(None, storkpackagelist.find_package_name('-'))
202       self.assertEquals(None, storkpackagelist.find_package_name('.'))
203       self.assertEquals(None, storkpackagelist.find_package_name('23'))
204       
205
206
207       # Pass it a valid, existent, filename
208       # Since grep is called with the instruction:
209       #      out, err, status = arizonageneral.popen5("grep -rl ^" + field + ":" + search + " " + os.path.join(arizonaconfig.get_option("localinfo"), package_dir))                               
210       # set the variables to the variable "localinfo" and "localpdir" to point to the directory where the packages are:
211       # TODO arizonaconfig.set_option( "pdir", ["stork"] )
212       # TODO arizonaconfig.set_option( "localinfo", "/usr/local/stork/" )      
213       self.assertEquals(None, storkpackagelist.find_package_name("storkd-0.1.0-1.src.rpm") )
214
215
216    #------------------------------------------------------------------------------------
217    # find_packages()
218    #------------------------------------------------------------------------------------
219    def test_find_packages(self):
220       pass
221
222
223
224    #------------------------------------------------------------------------------------
225    # __find_package_fnlist_on_one_criteria()
226    #------------------------------------------------------------------------------------
227 #   def test___find_package_fnlist_on_one_criteria(self):
228 #      _test._storkpackagelist__find_package_fnlist_on_one_criteria('filename', 'stork')
229
230                   
231
232                
233    
234       
235    #------------------------------------------------------------------
236    # cull_database(items, fields): ->
237    #------------------------------------------------------------------
238    def test_cull_database(self):
239       pass
240
241    #------------------------------------------------------------------
242    # get_field(field): ->
243    #------------------------------------------------------------------
244    def test_get_field(self):
245       pass
246
247    #------------------------------------------------------------------
248    # get_db_field(string,field): ->
249    #------------------------------------------------------------------
250    def test_get_db_field(self):
251       pass
252
253    #------------------------------------------------------------------
254    # package_cache_name(pkg_db): -> string
255    #------------------------------------------------------------------
256    def test_package_cache_name(self):
257       pass
258       
259    #------------------------------------------------------------------
260    # which_pdir(line): -> string or None
261    #------------------------------------------------------------------
262    def test_which_pdir(self):
263       pass
264
265    #------------------------------------------------------------------
266    # check_package(name): -> True/False, None (error)
267    #------------------------------------------------------------------
268    def test_check_package(self):
269       pass
270
271 # Run tests
272 if __name__ == '__main__':
273    arizonaconfig.init_options("storkpackagelist.py") 
274    arizonaunittest.main()