diff options
Diffstat (limited to 'functest/tests')
-rw-r--r-- | functest/tests/unit/ci/test_generate_report.py | 8 | ||||
-rw-r--r-- | functest/tests/unit/core/test_testcase.py | 33 | ||||
-rw-r--r-- | functest/tests/unit/core/test_vnf.py (renamed from functest/tests/unit/core/test_vnf_base.py) | 6 | ||||
-rw-r--r-- | functest/tests/unit/odl/test_odl.py | 29 |
4 files changed, 65 insertions, 11 deletions
diff --git a/functest/tests/unit/ci/test_generate_report.py b/functest/tests/unit/ci/test_generate_report.py index 13361c1d..2c5ce2ea 100644 --- a/functest/tests/unit/ci/test_generate_report.py +++ b/functest/tests/unit/ci/test_generate_report.py @@ -28,16 +28,16 @@ class GenerateReportTesting(unittest.TestCase): @mock.patch('functest.ci.generate_report.urllib2.urlopen', side_effect=urllib2.URLError('no host given')) def test_get_results_from_db_fail(self, mock_method): - url = "%s/results?build_tag=%s" % (ft_utils.get_db_url(), - CONST.__getattribute__('BUILD_TAG')) + url = "%s?build_tag=%s" % (ft_utils.get_db_url(), + CONST.__getattribute__('BUILD_TAG')) self.assertIsNone(gen_report.get_results_from_db()) mock_method.assert_called_once_with(url) @mock.patch('functest.ci.generate_report.urllib2.urlopen', return_value={'results': []}) def test_get_results_from_db_success(self, mock_method): - url = "%s/results?build_tag=%s" % (ft_utils.get_db_url(), - CONST.__getattribute__('BUILD_TAG')) + url = "%s?build_tag=%s" % (ft_utils.get_db_url(), + CONST.__getattribute__('BUILD_TAG')) self.assertEqual(gen_report.get_results_from_db(), None) mock_method.assert_called_once_with(url) diff --git a/functest/tests/unit/core/test_testcase.py b/functest/tests/unit/core/test_testcase.py index 17329ea3..b25ce226 100644 --- a/functest/tests/unit/core/test_testcase.py +++ b/functest/tests/unit/core/test_testcase.py @@ -189,6 +189,39 @@ class TestCaseTesting(unittest.TestCase): self.test.stop_time = 180 self.assertEqual(self.test.get_duration(), "02:59") + def test_str_project_name_ko(self): + self.test.project_name = None + self.assertIn("INVALID OBJECT", str(self.test)) + + def test_str_case_name_ko(self): + self.test.case_name = None + self.assertIn("INVALID OBJECT", str(self.test)) + + def test_str_pass(self): + duration = '01:01' + with mock.patch.object(self.test, 'get_duration', + return_value=duration), \ + mock.patch.object(self.test, 'is_successful', + return_value=testcase.TestCase.EX_OK): + message = str(self.test) + self.assertIn(self._project_name, message) + self.assertIn(self._case_name, message) + self.assertIn(duration, message) + self.assertIn('PASS', message) + + def test_str_fail(self): + duration = '00:59' + with mock.patch.object(self.test, 'get_duration', + return_value=duration), \ + mock.patch.object( + self.test, 'is_successful', + return_value=testcase.TestCase.EX_TESTCASE_FAILED): + message = str(self.test) + self.assertIn(self._project_name, message) + self.assertIn(self._case_name, message) + self.assertIn(duration, message) + self.assertIn('FAIL', message) + if __name__ == "__main__": unittest.main(verbosity=2) diff --git a/functest/tests/unit/core/test_vnf_base.py b/functest/tests/unit/core/test_vnf.py index 540cf610..f348c0db 100644 --- a/functest/tests/unit/core/test_vnf_base.py +++ b/functest/tests/unit/core/test_vnf.py @@ -10,7 +10,7 @@ import logging import unittest -from functest.core import vnf_base +from functest.core import vnf class VnfBaseTesting(unittest.TestCase): @@ -18,8 +18,8 @@ class VnfBaseTesting(unittest.TestCase): logging.disable(logging.CRITICAL) def setUp(self): - self.test = vnf_base.VnfOnBoardingBase(project='functest', - case_name='aaa') + self.test = vnf.VnfOnBoarding(project='functest', + case_name='aaa') self.test.project = "functest" self.test.start_time = "1" self.test.stop_time = "5" diff --git a/functest/tests/unit/odl/test_odl.py b/functest/tests/unit/odl/test_odl.py index f3d37c65..d7ce70c7 100644 --- a/functest/tests/unit/odl/test_odl.py +++ b/functest/tests/unit/odl/test_odl.py @@ -109,6 +109,9 @@ class ODLParseResultTesting(ODLTesting): """The class testing ODLTests.parse_results().""" # pylint: disable=missing-docstring + _config = {'name': 'dummy', 'starttime': '20161216 16:00:00.000', + 'endtime': '20161216 16:00:01.000'} + @mock.patch('robot.api.ExecutionResult', side_effect=DataError) def test_raises_exc(self, mock_method): with self.assertRaises(DataError): @@ -116,15 +119,13 @@ class ODLParseResultTesting(ODLTesting): mock_method.assert_called_once_with( os.path.join(odl.ODLTests.res_dir, 'output.xml')) - def test_ok(self): - config = {'name': 'dummy', 'starttime': '20161216 16:00:00.000', - 'endtime': '20161216 16:00:01.000', 'status': 'PASS'} + def _test_result(self, config, result): suite = mock.Mock() suite.configure_mock(**config) with mock.patch('robot.api.ExecutionResult', return_value=mock.Mock(suite=suite)): self.test.parse_results() - self.assertEqual(self.test.result, config['status']) + self.assertEqual(self.test.result, result) self.assertEqual(self.test.start_time, timestamp_to_secs(config['starttime'])) self.assertEqual(self.test.stop_time, @@ -132,6 +133,26 @@ class ODLParseResultTesting(ODLTesting): self.assertEqual(self.test.details, {'description': config['name'], 'tests': []}) + def test_null_passed(self): + self._config.update({'statistics.critical.passed': 0, + 'statistics.critical.total': 20}) + self._test_result(self._config, 0) + + def test_no_test(self): + self._config.update({'statistics.critical.passed': 20, + 'statistics.critical.total': 0}) + self._test_result(self._config, 0) + + def test_half_success(self): + self._config.update({'statistics.critical.passed': 10, + 'statistics.critical.total': 20}) + self._test_result(self._config, 50) + + def test_success(self): + self._config.update({'statistics.critical.passed': 20, + 'statistics.critical.total': 20}) + self._test_result(self._config, 100) + class ODLRobotTesting(ODLTesting): |