comparison test/test_admin.py @ 6186:81babf5a4494

Test for cli. Command partial match, Bad command, bad args.
author John Rouillard <rouilj@ieee.org>
date Thu, 04 Jun 2020 12:06:34 -0400
parents 49f599f187e1
children 32ebffbae49a
comparison
equal deleted inserted replaced
6185:1cb2375015f0 6186:81babf5a4494
272 out = out.getvalue().strip() 272 out = out.getvalue().strip()
273 print(out) 273 print(out)
274 # out can be "['2', '1']" or "['1', '2']" 274 # out can be "['2', '1']" or "['1', '2']"
275 # so eval to real list so Equal can do a list compare 275 # so eval to real list so Equal can do a list compare
276 self.assertEqual(sorted(eval(out)), ['1', '2']) 276 self.assertEqual(sorted(eval(out)), ['1', '2'])
277
278 def testCliParse(self):
279 ''' Note the tests will fail if you run this under pdb.
280 the context managers capture the pdb prompts and this screws
281 up the stdout strings with (pdb) prefixed to the line.
282 '''
283 import sys
284
285 self.admin=AdminTool()
286 self.install_init()
287
288 # test partial command lookup fin -> calls find
289
290 with captured_output() as (out, err):
291 ''' assignedto is not a valid property=value, so
292 report error.
293 '''
294 sys.argv=['main', '-i', '_test_admin', 'fin', 'issue',
295 'assignedto=1']
296 ret = self.admin.main()
297
298 out = out.getvalue().strip()
299 print(out)
300 expected="[ '1' ]"
301 self.assertTrue(expected, out)
302
303 # Reopen the db closed by previous call
304 self.admin=AdminTool()
305 # test multiple matches
306 with captured_output() as (out, err):
307 ''' assignedto is not a valid property=value, so
308 report error.
309 '''
310 sys.argv=['main', '-i', '_test_admin', 'f', 'issue',
311 'assignedto']
312 ret = self.admin.main()
313
314 out = out.getvalue().strip()
315 print(out)
316 expected='Multiple commands match "f": filter, find'
317 self.assertEqual(expected, out)
318
319 # Reopen the db closed by previous call
320 self.admin=AdminTool()
321 # test broken command lookup xyzzy is not a valid command
322 with captured_output() as (out, err):
323 ''' assignedto is not a valid property=value, so
324 report error.
325 '''
326 sys.argv=['main', '-i', '_test_admin', 'xyzzy', 'issue',
327 'assignedto']
328 ret = self.admin.main()
329
330 out = out.getvalue().strip()
331 print(out)
332 expected=('Unknown command "xyzzy" '
333 '("help commands" for a list)')
334 self.assertEqual(expected, out)
335
336
337 # Reopen the db closed by previous call
338 self.admin=AdminTool()
339 # test for keyword=value check
340 with captured_output() as (out, err):
341 ''' assignedto is not a valid property=value, so
342 report error.
343 '''
344 sys.argv=['main', '-i', '_test_admin', 'find', 'issue',
345 'assignedto']
346 ret = self.admin.main()
347
348 out = out.getvalue().strip()
349 print(out)
350 expected='Error: argument "assignedto" not propname=value'
351 self.assertTrue(expected in out)
277 352
278 def testFilter(self): 353 def testFilter(self):
279 ''' Note the tests will fail if you run this under pdb. 354 ''' Note the tests will fail if you run this under pdb.
280 the context managers capture the pdb prompts and this screws 355 the context managers capture the pdb prompts and this screws
281 up the stdout strings with (pdb) prefixed to the line. 356 up the stdout strings with (pdb) prefixed to the line.

Roundup Issue Tracker: http://roundup-tracker.org/