def test_execute_nongating(self, t_run): config = {"host_string": "127.0.0.1", "user": "******"} r1 = Result("result1") r1.return_code = 127 t_run.return_value=r1 res, negative = tunirlib.execute(config, '## ls') self.assertEqual(res, "result1") self.assertEqual(negative, "dontcare")
def test_main(self,p_br, p_run,p_kill, p_exit, p_sleep): res = StupidProcess() p_br.return_value = res r1 = Result("result1") r1.return_code = 0 r2 = Result("result2") r2.return_code = 0 values = [r1, r2] p_run.side_effect = values # Now let us construct the args args = StupidArgs() with captured_output() as (out, err): main(args) self.assertIn("Passed:1", out.getvalue()) self.assertIn("Job status: True", out.getvalue()) self.assertTrue(p_kill.called) self.assertTrue(p_exit.called)
def test_updateresult(self): r1 = Result("result1") r1.return_code = 0 r2 = Result("result2") r2.return_code = 127 r3 = Result("result3") r3.return_code = 1 values = [(r1, 'no', 'ls'), (r2, 'yes', '@@ sudo reboot'), (r3, 'dontcare', '## ping foo')] for res, negative, command in values: tunirlib.update_result(res, command, negative) res = [True, True, False] for out, result in zip(tunirlib.STR.iteritems(), res): self.assertEqual(out[1]['status'], result)