summaryrefslogtreecommitdiffstats
path: root/dovetail/tests
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2018-11-24 01:44:02 -0500
committerxudan <xudan16@huawei.com>2019-01-03 22:15:40 -0500
commitb7ee5abe9b73cbc0928bf9ac080a6aecf05bcb7e (patch)
tree6825cc66028c7c085364a5cedd727cddc93b5b49 /dovetail/tests
parent78b0062ce9dc4d23b967112a0896f12cc6526e1c (diff)
Add ONAP VNF SDK verification tests
Please refer to env_config.sh.onap.sample when testing it. The guide of preparing local env for onap package validation can be found here https://gerrit.onap.org/r/#/c/75119 Change-Id: I39d6b11544847756126623a7eb3b953dc800c470 Signed-off-by: xudan <xudan16@huawei.com>
Diffstat (limited to 'dovetail/tests')
-rw-r--r--dovetail/tests/unit/test_report.py204
-rw-r--r--dovetail/tests/unit/test_test_runner.py37
-rw-r--r--dovetail/tests/unit/test_testcase.py2
3 files changed, 239 insertions, 4 deletions
diff --git a/dovetail/tests/unit/test_report.py b/dovetail/tests/unit/test_report.py
index 0f0d3eec..9f5369ec 100644
--- a/dovetail/tests/unit/test_report.py
+++ b/dovetail/tests/unit/test_report.py
@@ -34,15 +34,17 @@ class ReportTesting(unittest.TestCase):
dt_report.YardstickCrawler.logger = None
dt_report.BottlenecksCrawler.logger = None
dt_report.VnftestCrawler.logger = None
+ dt_report.OnapVtpCrawler.logger = None
dt_report.FunctestChecker.logger = None
dt_report.FunctestK8sChecker.logger = None
dt_report.YardstickChecker.logger = None
dt_report.BottlenecksChecker.logger = None
dt_report.VnftestChecker.logger = None
+ dt_report.OnapVtpChecker.logger = None
dt_report.Report.logger = None
dt_report.Report.results = {
'functest': {}, 'yardstick': {}, 'functest-k8s': {},
- 'bottlenecks': {}, 'shell': {}, 'vnftest': {}}
+ 'bottlenecks': {}, 'shell': {}, 'vnftest': {}, 'onap-vtp': {}}
def _produce_report_initial_text(self, report_data):
report_txt = ''
@@ -947,6 +949,179 @@ class ReportTesting(unittest.TestCase):
"Pass flag not found 'result'")
self.assertEquals(expected, result)
+ @patch('dovetail.report.dt_logger')
+ def test_onapvtp_crawler_create_log(self, mock_logger):
+ getlogger_obj = Mock()
+ logger_obj = Mock()
+ logger_obj.getLogger.return_value = getlogger_obj
+ mock_logger.Logger.return_value = logger_obj
+
+ dt_report.OnapVtpCrawler.create_log()
+
+ self.assertEquals(getlogger_obj, dt_report.OnapVtpCrawler.logger)
+
+ @patch('dovetail.report.os.path')
+ def test_onapvtp_crawler_crawl_not_exists(self, mock_path):
+ logger_obj = Mock()
+ dt_report.OnapVtpCrawler.logger = logger_obj
+ mock_path.exists.return_value = False
+ file_path = 'file_path'
+
+ crawler = dt_report.OnapVtpCrawler()
+ result = crawler.crawl(None, file_path)
+
+ mock_path.exists.assert_called_once_with(file_path)
+ logger_obj.error.assert_called_once_with(
+ 'Result file not found: {}'.format(file_path))
+ self.assertEquals(None, result)
+
+ @patch('__builtin__.open')
+ @patch('dovetail.report.json.loads')
+ @patch('dovetail.report.os.path')
+ def test_onapvtp_crawler_crawl_pass(self, mock_path, mock_loads,
+ mock_open):
+ dt_report.OnapVtpCrawler.logger = Mock()
+ mock_path.exists.return_value = True
+ file_path = 'file_path'
+ testcase_obj = Mock()
+ file_obj = Mock()
+ mock_open.return_value.__enter__.return_value = [file_obj]
+ data_dict = {
+ 'results': [
+ {"property": "results", "value": "{value=SUCCESS}"},
+ {"property": "build_tag", "value": "test-name"},
+ {"property": "criteria", "value": "PASS"}
+ ]
+ }
+ mock_loads.return_value = data_dict
+
+ crawler = dt_report.OnapVtpCrawler()
+ result = crawler.crawl(testcase_obj, file_path)
+ expected = {'criteria': 'PASS'}
+
+ mock_path.exists.assert_called_once_with(file_path)
+ mock_open.assert_called_once_with(file_path, 'r')
+ mock_loads.assert_called_once_with(file_obj)
+ testcase_obj.set_results.assert_called_once_with(expected)
+ self.assertEquals(expected, result)
+
+ @patch('__builtin__.open')
+ @patch('dovetail.report.json.loads')
+ @patch('dovetail.report.os.path')
+ def test_onapvtp_crawler_crawl_fail(self, mock_path, mock_loads,
+ mock_open):
+ dt_report.OnapVtpCrawler.logger = Mock()
+ mock_path.exists.return_value = True
+ file_path = 'file_path'
+ testcase_obj = Mock()
+ file_obj = Mock()
+ mock_open.return_value.__enter__.return_value = [file_obj]
+ data_dict = {
+ 'results': [
+ {"property": "results", "value": "{value=file doesn't exist}"},
+ {"property": "build_tag", "value": "test-name"},
+ {"property": "criteria", "value": "FAILED"}
+ ]
+ }
+ mock_loads.return_value = data_dict
+
+ crawler = dt_report.OnapVtpCrawler()
+ result = crawler.crawl(testcase_obj, file_path)
+ expected = {'criteria': 'FAIL'}
+
+ mock_path.exists.assert_called_once_with(file_path)
+ mock_open.assert_called_once_with(file_path, 'r')
+ mock_loads.assert_called_once_with(file_obj)
+ testcase_obj.set_results.assert_called_once_with(expected)
+ self.assertEquals(expected, result)
+
+ @patch('__builtin__.open')
+ @patch('dovetail.report.json.loads')
+ @patch('dovetail.report.os.path')
+ def test_onapvtp_crawler_crawl_no_criteria(self, mock_path, mock_loads,
+ mock_open):
+ dt_report.OnapVtpCrawler.logger = Mock()
+ mock_path.exists.return_value = True
+ file_path = 'file_path'
+ testcase_obj = Mock()
+ file_obj = Mock()
+ mock_open.return_value.__enter__.return_value = [file_obj]
+ data_dict = {
+ 'results': [
+ {"property": "results", "value": "{value=file doesn't exist}"},
+ {"property": "build_tag", "value": "test-name"},
+ {"property": "error_criteria", "value": "FAILED"}
+ ]
+ }
+ mock_loads.return_value = data_dict
+
+ crawler = dt_report.OnapVtpCrawler()
+ result = crawler.crawl(testcase_obj, file_path)
+ expected = {'criteria': 'FAIL'}
+
+ mock_path.exists.assert_called_once_with(file_path)
+ mock_open.assert_called_once_with(file_path, 'r')
+ mock_loads.assert_called_once_with(file_obj)
+ dt_report.OnapVtpCrawler.logger.error.assert_called_once_with(
+ 'There is no property criteria.')
+ testcase_obj.set_results.assert_called_once_with(expected)
+ self.assertEquals(expected, result)
+
+ @patch('__builtin__.open')
+ @patch('dovetail.report.json.loads')
+ @patch('dovetail.report.os.path')
+ def test_onapvtp_crawler_crawl_exception(self, mock_path, mock_loads,
+ mock_open):
+ dt_report.OnapVtpCrawler.logger = Mock()
+ mock_path.exists.return_value = True
+ file_path = 'file_path'
+ testcase_obj = Mock()
+ file_obj = Mock()
+ mock_open.return_value.__enter__.return_value = [file_obj]
+ data_dict = {
+ 'error_results': [
+ {"property": "results", "value": "{value=file doesn't exist}"},
+ {"property": "build_tag", "value": "test-name"},
+ {"property": "error_criteria", "value": "FAILED"}
+ ]
+ }
+ mock_loads.return_value = data_dict
+
+ crawler = dt_report.OnapVtpCrawler()
+ result = crawler.crawl(testcase_obj, file_path)
+ expected = {'criteria': 'FAIL'}
+
+ mock_path.exists.assert_called_once_with(file_path)
+ mock_open.assert_called_once_with(file_path, 'r')
+ mock_loads.assert_called_once_with(file_obj)
+ dt_report.OnapVtpCrawler.logger.exception.assert_called_once_with(
+ "Pass flag not found 'results'")
+ testcase_obj.set_results.assert_called_once_with(expected)
+ self.assertEquals(expected, result)
+
+ @patch('__builtin__.open')
+ @patch('dovetail.report.json.loads')
+ @patch('dovetail.report.os.path')
+ def test_onapvtp_crawler_crawl_value_error(self, mock_path, mock_loads,
+ mock_open):
+ dt_report.OnapVtpCrawler.logger = Mock()
+ mock_path.exists.return_value = True
+ file_path = 'file_path'
+ testcase_obj = Mock()
+ file_obj = Mock()
+ mock_open.return_value.__enter__.return_value = [file_obj]
+ mock_loads.side_effect = ValueError('No JSON object could be decoded')
+
+ crawler = dt_report.OnapVtpCrawler()
+ result = crawler.crawl(testcase_obj, file_path)
+ expected = {'criteria': 'FAIL'}
+
+ mock_path.exists.assert_called_once_with(file_path)
+ mock_open.assert_called_once_with(file_path, 'r')
+ mock_loads.assert_called_once_with(file_obj)
+ testcase_obj.set_results.assert_called_once_with(expected)
+ self.assertEquals(expected, result)
+
def test_crawler_factory(self):
result = dt_report.CrawlerFactory.create('shell')
self.assertEquals(dt_report.ShellCrawler, result.__class__)
@@ -1157,3 +1332,30 @@ class ReportTesting(unittest.TestCase):
def test_checker_factory_none(self):
self.assertEquals(None, dt_report.CheckerFactory.create('other'))
+
+ @patch('dovetail.report.dt_logger')
+ def test_onapvtp_checker_create_log(self, mock_logger):
+ getlogger_obj = Mock()
+ logger_obj = Mock()
+ logger_obj.getLogger.return_value = getlogger_obj
+ mock_logger.Logger.return_value = logger_obj
+
+ dt_report.OnapVtpChecker.create_log()
+
+ self.assertEquals(getlogger_obj, dt_report.OnapVtpChecker.logger)
+
+ def test_onapvtp_check_result_none(self):
+ testcase_obj = Mock()
+ result = {}
+
+ dt_report.OnapVtpChecker.check(testcase_obj, result)
+
+ testcase_obj.passed.assert_called_once_with('FAIL')
+
+ def test_onapvtp_check_result(self):
+ testcase_obj = Mock()
+ result = {'criteria': 'PASS'}
+
+ dt_report.OnapVtpChecker.check(testcase_obj, result)
+
+ testcase_obj.passed.assert_called_once_with('PASS')
diff --git a/dovetail/tests/unit/test_test_runner.py b/dovetail/tests/unit/test_test_runner.py
index 2570ec76..4b5c00bb 100644
--- a/dovetail/tests/unit/test_test_runner.py
+++ b/dovetail/tests/unit/test_test_runner.py
@@ -323,7 +323,7 @@ class TestRunnerTesting(unittest.TestCase):
@patch('dovetail.test_runner.os')
def test_add_testcase_info(self, mock_os, mock_config):
mock_os.getenv.side_effect = ['os_insecure', 'dovetail_home', 'debug',
- 'os_cacert']
+ 'os_cacert', 'host_url', 'csar_file']
mock_os.environ = {'DEPLOY_SCENARIO': 'deploy_scenario'}
mock_config.dovetail_config = {'build_tag': 'build_tag'}
@@ -332,7 +332,8 @@ class TestRunnerTesting(unittest.TestCase):
'testcase': 'testcase_name', 'os_insecure': 'os_insecure',
'deploy_scenario': 'deploy_scenario',
'dovetail_home': 'dovetail_home', 'debug': 'debug',
- 'build_tag': 'build_tag', 'cacert': 'os_cacert'}
+ 'build_tag': 'build_tag', 'cacert': 'os_cacert',
+ 'host_url': 'host_url', 'csar_file': 'csar_file'}
result = t_runner.FunctestRunner._add_testcase_info(self.testcase)
self.testcase.validate_testcase.assert_called_once_with()
@@ -639,3 +640,35 @@ class TestRunnerTesting(unittest.TestCase):
'pod_file': 'two',
'full_task_yaml': 'full_value'},
result)
+
+ @patch('dovetail.test_runner.dt_utils')
+ @patch('dovetail.test_runner.os.path')
+ @patch('dovetail.test_runner.dt_cfg')
+ def test_init_onapvtprunner_no_env_file(self, mock_config, mock_path,
+ mock_utils):
+ t_runner.OnapVtpRunner.create_log()
+ mock_path.join.side_effect = ['env_file']
+ mock_config.dovetail_config = {'config_dir': 'one', 'env_file': 'two'}
+ mock_path.isfile.return_value = False
+
+ docker_runner = t_runner.OnapVtpRunner(self.testcase)
+
+ mock_path.join.assert_has_calls([call('one', 'two')])
+ mock_path.isfile.assert_called_once()
+ docker_runner.logger.error.assert_called_once_with(
+ 'File env_file does not exist.')
+
+ @patch('dovetail.test_runner.dt_utils')
+ @patch('dovetail.test_runner.os.path')
+ @patch('dovetail.test_runner.dt_cfg')
+ def test_init_onapvtprunner(self, mock_config, mock_path, mock_utils):
+ t_runner.OnapVtpRunner.create_log()
+ mock_path.join.side_effect = ['env_file']
+ mock_config.dovetail_config = {'config_dir': 'one', 'env_file': 'two'}
+ mock_path.isfile.return_value = True
+
+ t_runner.OnapVtpRunner(self.testcase)
+
+ mock_path.join.assert_has_calls([call('one', 'two')])
+ mock_path.isfile.assert_called_once()
+ mock_utils.source_env.assert_called_once_with('env_file')
diff --git a/dovetail/tests/unit/test_testcase.py b/dovetail/tests/unit/test_testcase.py
index c3eb683e..7224c1ae 100644
--- a/dovetail/tests/unit/test_testcase.py
+++ b/dovetail/tests/unit/test_testcase.py
@@ -113,7 +113,7 @@ class TestcaseTesting(unittest.TestCase):
self.assertEquals(True, result)
def test_str(self):
- testcase = tcase.Testcase(self.testcase_yaml)
+ testcase = tcase.OnapVtpTestcase(self.testcase_yaml)
result = testcase.__str__()