summaryrefslogtreecommitdiffstats
path: root/dovetail/tests/unit
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2019-04-03 05:33:24 -0400
committerxudan <xudan16@huawei.com>2019-04-03 22:25:59 -0400
commit06a0a8f2bd8ee7ce7db154c54301ec986b93b89f (patch)
tree89bd74978b9d9c4b107b4a617d557a60c95007a7 /dovetail/tests/unit
parenteb86745284805f2943d4733bb029948be760d597 (diff)
Push CI results to OPNFV test DB
In order to use OPNFV test results page to do the ayalysis of all OVP test cases, it needs to push all results generated by Dovetail CI jobs to test DB and then using http://testresults.opnfv.org/test/#/results to check all results. The following data must contain in the POST body: 1. project_name 2. case_name 3. details 4. installer 5. scenario 6. pod_name 7. build_tag 8. criteria 9. start_date 10. stop_date 11. version JIRA: DOVETAIL-767 Change-Id: I925ae249e24efd7bfb1c68a69150e9c22f0cdf36 Signed-off-by: xudan <xudan16@huawei.com>
Diffstat (limited to 'dovetail/tests/unit')
-rw-r--r--dovetail/tests/unit/cmd_config.yml4
-rw-r--r--dovetail/tests/unit/test_run.py40
-rw-r--r--dovetail/tests/unit/utils/test_dovetail_utils.py49
3 files changed, 83 insertions, 10 deletions
diff --git a/dovetail/tests/unit/cmd_config.yml b/dovetail/tests/unit/cmd_config.yml
index 4a1439f..98a2a9d 100644
--- a/dovetail/tests/unit/cmd_config.yml
+++ b/dovetail/tests/unit/cmd_config.yml
@@ -22,3 +22,7 @@ cli:
flags:
- '--report'
is_flag: 'True'
+ opnfvci:
+ flags:
+ - '--opnfv-ci'
+ is_flag: 'True'
diff --git a/dovetail/tests/unit/test_run.py b/dovetail/tests/unit/test_run.py
index 7f36d31..654d8c9 100644
--- a/dovetail/tests/unit/test_run.py
+++ b/dovetail/tests/unit/test_run.py
@@ -57,30 +57,45 @@ class RunTesting(unittest.TestCase):
logger.warning.assert_called_once_with(
"No test case will be executed.")
+ @patch('dovetail.run.datetime')
+ @patch('dovetail.run.dt_utils')
@patch('dovetail.run.dt_cfg')
@patch('dovetail.run.dt_report.Report')
@patch('dovetail.run.dt_testcase.Testcase')
@patch('dovetail.run.time')
- def test_run_test(self, mock_time, mock_testcase, mock_report,
- mock_config):
+ @patch('os.getenv')
+ 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, 84]
+ 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()])
+ 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()
@@ -101,7 +116,8 @@ class RunTesting(unittest.TestCase):
dt_run.run_test([testcase_name], True, logger)
- mock_time.time.assert_called_once_with()
+ 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))])
@@ -127,7 +143,7 @@ class RunTesting(unittest.TestCase):
dt_run.run_test([testcase_name], True, logger)
- mock_time.time.assert_called_once_with()
+ mock_time.time.assert_has_calls([call(), call(), call()])
logger.info.assert_has_calls([
call('>>[testcase]: {}'.format(testcase_name)),
call('Stop because {} failed'.format(testcase_name))])
@@ -504,14 +520,15 @@ class RunTesting(unittest.TestCase):
mock_get_list.return_value = testcase_list
kwargs_dict = {
'debug': True,
+ 'opnfv_ci': True,
'report': True,
'testsuite': 'testsuite',
'docker_tag': '2.0.0'
}
with self.assertRaises(SystemExit) as cm:
- dt_run.main([
- '--testsuite=testsuite', '--debug', '--report', '2.0.0'])
+ dt_run.main(['--testsuite=testsuite', '--debug', '--report',
+ '2.0.0', '--opnfv-ci'])
expected = cm.exception
logger_temp_obj.getLogger.assert_called_once_with()
@@ -521,7 +538,8 @@ class RunTesting(unittest.TestCase):
mock_config.dovetail_config)
mock_get_result.assert_called_once_with()
mock_clean.assert_called_once_with()
- self.assertEquals({'DEBUG': 'true'}, mock_os.environ)
+ self.assertEquals({'DEBUG': 'true', 'OPNFV_CI': 'true'},
+ mock_os.environ)
mock_create_logs.assert_called_once_with()
logger_obj.info.assert_has_calls([
call('================================================'),
@@ -587,6 +605,7 @@ class RunTesting(unittest.TestCase):
mock_get_list.return_value = None
kwargs_dict = {
'debug': True,
+ 'opnfv_ci': False,
'report': True,
'testsuite': 'testsuite',
'docker_tag': '2.0.0'
@@ -605,7 +624,8 @@ class RunTesting(unittest.TestCase):
mock_config.dovetail_config)
mock_get_result.assert_called_once_with()
mock_clean.assert_called_once_with()
- self.assertEquals({'DEBUG': 'true'}, mock_os.environ)
+ self.assertEquals({'DEBUG': 'true', 'OPNFV_CI': 'false'},
+ mock_os.environ)
mock_create_logs.assert_called_once_with()
logger_obj.info.assert_has_calls([
call('================================================'),
diff --git a/dovetail/tests/unit/utils/test_dovetail_utils.py b/dovetail/tests/unit/utils/test_dovetail_utils.py
index 33fc1ea..2635fb6 100644
--- a/dovetail/tests/unit/utils/test_dovetail_utils.py
+++ b/dovetail/tests/unit/utils/test_dovetail_utils.py
@@ -1334,3 +1334,52 @@ class DovetailUtilsTesting(unittest.TestCase):
mock_host.assert_called_once()
mock_endpoint.assert_called_once()
mock_hardware.assert_called_once()
+
+ @patch('json.dumps')
+ @patch('dovetail.utils.dovetail_utils.requests')
+ @patch('os.getenv')
+ def test_push_results_to_db(self, mock_getenv, mock_requests, mock_dumps):
+ logger = Mock()
+ case_name = 'case_name'
+ details = {'criteria': 'PASS'}
+ start_date = 'start_date'
+ stop_date = 'stop_date'
+ mock_getenv.side_effect = [
+ 'url', 'installer', 'scenario', 'pod_name', 'build_tag', 'version']
+ post_req = Mock()
+ post_req.raise_for_status.return_value = None
+ mock_requests.post.return_value = post_req
+ mock_dumps.return_value = {"project_name": "dovetail"}
+
+ dovetail_utils.push_results_to_db(
+ case_name, details, start_date, stop_date, logger)
+
+ mock_requests.post.assert_called_once_with(
+ 'url',
+ data={"project_name": "dovetail"},
+ headers={"Content-Type": "application/json"})
+ logger.debug.assert_called_once_with(
+ "The results were successfully pushed to DB.")
+
+ @patch('json.dumps')
+ @patch('dovetail.utils.dovetail_utils.requests')
+ @patch('os.getenv')
+ def test_push_results_to_db_exception(self, mock_getenv, mock_requests,
+ mock_dumps):
+ logger = Mock()
+ case_name = 'case_name'
+ details = {'criteria': 'PASS'}
+ start_date = 'start_date'
+ stop_date = 'stop_date'
+ mock_getenv.side_effect = [
+ 'url', 'installer', 'scenario', 'pod_name', 'build_tag', 'version']
+ post_req = Mock()
+ post_req.raise_for_status.side_effect = Exception()
+ mock_requests.post.return_value = post_req
+ mock_dumps.return_value = {"project_name": "dovetail"}
+ dovetail_utils.push_results_to_db(
+ case_name, details, start_date, stop_date, logger)
+
+ logger.debug.assert_not_called()
+ logger.exception.assert_called_once_with(
+ "The results cannot be pushed to DB.")