@@ -47,7 +47,13 @@ def tearDown(self):
4747
4848 def install_init (self , type = "classic" ,
4949 settings = "mail_domain=example.com," +
50- "mail_host=localhost," + "tracker_web=http://test/" ):
50+ "mail_host=localhost," +
51+ "tracker_web=http://test/," +
52+ "rdbms_name=rounduptest," +
53+ "rdbms_user=rounduptest," +
54+ "rdbms_password=rounduptest," +
55+ "rdbms_template=template0"
56+ ):
5157 ''' install tracker with settings for required config.ini settings.
5258 '''
5359
@@ -113,7 +119,7 @@ def testFind(self):
113119 the context managers capture the pdb prompts and this screws
114120 up the stdout strings with (pdb) prefixed to the line.
115121 '''
116- import sys , json
122+ import sys
117123
118124 self .admin = AdminTool ()
119125 self .install_init ()
@@ -179,6 +185,120 @@ def testFind(self):
179185 # so eval to real list so Equal can do a list compare
180186 self .assertEqual (sorted (eval (out )), ['1' , '2' ])
181187
188+ def testFilter (self ):
189+ ''' Note the tests will fail if you run this under pdb.
190+ the context managers capture the pdb prompts and this screws
191+ up the stdout strings with (pdb) prefixed to the line.
192+ '''
193+ import sys
194+
195+ self .admin = AdminTool ()
196+ self .install_init ()
197+
198+ with captured_output () as (out , err ):
199+ sys .argv = ['main' , '-i' , '_test_admin' , 'create' , 'issue' ,
200+ 'title="foo bar"' , 'assignedto=admin' ]
201+ ret = self .admin .main ()
202+
203+ out = out .getvalue ().strip ()
204+ print (out )
205+ self .assertEqual (out , '1' )
206+
207+ self .admin = AdminTool ()
208+ with captured_output () as (out , err ):
209+ sys .argv = ['main' , '-i' , '_test_admin' , 'create' , 'issue' ,
210+ 'title="bar foo bar"' , 'assignedto=anonymous' ]
211+ ret = self .admin .main ()
212+
213+ out = out .getvalue ().strip ()
214+ print (out )
215+ self .assertEqual (out , '2' )
216+
217+
218+ # Reopen the db closed by previous filter call
219+ # test string - one results, one value, substring
220+ self .admin = AdminTool ()
221+ with captured_output () as (out , err ):
222+ sys .argv = ['main' , '-i' , '_test_admin' , 'filter' , 'user' ,
223+ 'username=admin' ]
224+ ret = self .admin .main ()
225+
226+ out = out .getvalue ().strip ()
227+ print (out )
228+ self .assertEqual (out , "['1']" )
229+
230+ # Reopen the db closed by previous filter call
231+ # test string - two results, two values, substring
232+ self .admin = AdminTool ()
233+ with captured_output () as (out , err ):
234+ ''' a,n should return all entries that have an a and n
235+ so admin or anonymous
236+ '''
237+ sys .argv = ['main' , '-i' , '_test_admin' , 'filter' , 'user' ,
238+ 'username=a,n' ]
239+ ret = self .admin .main ()
240+
241+ out = out .getvalue ().strip ()
242+ print (out )
243+ # out can be "['2', '1']" or "['1', '2']"
244+ # so eval to real list so Equal can do a list compare
245+ self .assertEqual (sorted (eval (out )), ['1' , '2' ])
246+
247+ # Reopen the db closed by previous filter call
248+ # test string - one result, two values, substring
249+ self .admin = AdminTool ()
250+ with captured_output () as (out , err ):
251+ ''' a,y should return all entries that have an a and y
252+ so anonymous
253+ '''
254+ sys .argv = ['main' , '-i' , '_test_admin' , 'filter' , 'user' ,
255+ 'username=a,y' ]
256+ ret = self .admin .main ()
257+
258+ out = out .getvalue ().strip ()
259+ print (out )
260+ self .assertEqual (out , "['2']" )
261+
262+ # Reopen the db closed by previous filter call
263+ # test string - no results
264+ self .admin = AdminTool ()
265+ with captured_output () as (out , err ):
266+ ''' will return empty set as admin!=anonymous
267+ '''
268+ sys .argv = ['main' , '-i' , '_test_admin' , 'filter' , 'user' ,
269+ 'username=admin,anonymous' ]
270+ ret = self .admin .main ()
271+
272+ out = out .getvalue ().strip ()
273+ print (out )
274+ self .assertEqual (out , "[]" )
275+
276+ # Reopen the db closed by previous filter call
277+ # test link using ids
278+ self .admin = AdminTool ()
279+ with captured_output () as (out , err ):
280+ sys .argv = ['main' , '-i' , '_test_admin' , 'filter' , 'issue' ,
281+ 'assignedto=1,2' ]
282+ ret = self .admin .main ()
283+
284+ out = out .getvalue ().strip ()
285+ print (out )
286+ self .assertEqual (sorted (eval (out )), ['1' , '2' ])
287+
288+ # Reopen the db closed by previous filter call
289+ # test link using names
290+ self .admin = AdminTool ()
291+ with captured_output () as (out , err ):
292+ ''' will return empty set as admin!=anonymous
293+ '''
294+ sys .argv = ['main' , '-i' , '_test_admin' , 'filter' , 'issue' ,
295+ 'assignedto=admin,anonymous' ]
296+ ret = self .admin .main ()
297+
298+ out = out .getvalue ().strip ()
299+ print (out )
300+ self .assertEqual (sorted (eval (out )), ['1' , '2' ])
301+
182302 def testSpecification (self ):
183303 ''' Note the tests will fail if you run this under pdb.
184304 the context managers capture the pdb prompts and this screws
0 commit comments