def test_run_test_no_list(self, mock_report): logger = Mock() mock_report.return_value = Mock() dt_run.run_test([], False, logger) logger.warning.assert_called_once_with( "No test case will be executed.")
def test_run_test(self, mock_getenv, mock_time, mock_testcase, mock_report, mock_config, mock_utils, mock_datetime): logger = Mock() report_obj = Mock() mock_report.return_value = report_obj mock_time.time.side_effect = [42, 43, 83, 84] datetime_obj = Mock() mock_datetime.fromtimestamp.return_value = datetime_obj datetime_obj.strftime.side_effect = ['1969-12-31 19:00:43', '1969-12-31 19:01:23'] testcase_name = 'testcase' testcase_obj = Mock() mock_testcase.get.return_value = testcase_obj mock_config.dovetail_config = {'stop': True} mock_getenv.return_value = 'true' report_obj.check_tc_result.return_value = {'criteria': 'PASS'} mock_utils.push_results_to_db.return_value = True dt_run.run_test([testcase_name], True, logger) mock_time.time.assert_has_calls([call(), call(), call(), call()]) logger.info.assert_called_once_with( '>>[testcase]: {}'.format(testcase_name)) mock_testcase.get.assert_called_once_with(testcase_name) testcase_obj.run.assert_called_once_with() report_obj.check_tc_result.assert_called_once_with(testcase_obj) mock_utils.push_results_to_db.assert_called_once_with( case_name=testcase_name, start_date='1969-12-31 19:00:43', stop_date='1969-12-31 19:01:23', details={'criteria': 'PASS'}, logger=logger) report_obj.generate.assert_called_once_with([testcase_name], 42) report_obj.save_logs.assert_called_once_with()
def test_run_test_fail(self, mock_time, mock_testcase, mock_report, mock_config): logger = Mock() report_obj = Mock() mock_report.return_value = report_obj testcase_name = 'testcase' testcase_obj = Mock() mock_testcase.get.return_value = testcase_obj mock_config.dovetail_config = {'stop': True} report_obj.check_tc_result.return_value = {'criteria': 'FAIL'} dt_run.run_test([testcase_name], True, logger) mock_time.time.assert_has_calls( [call(), call(), call().__float__(), call(), call().__float__()]) logger.info.assert_has_calls([ call('>>[testcase]: {}'.format(testcase_name)), call('Stop because {} failed'.format(testcase_name)) ]) mock_testcase.get.assert_called_once_with(testcase_name) testcase_obj.run.assert_called_once_with() report_obj.check_tc_result.assert_called_once_with(testcase_obj)