aboutsummaryrefslogtreecommitdiffstats
path: root/functest
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2016-12-17 10:59:52 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2016-12-17 11:07:33 +0100
commit6f798d51022c7709f678ae996a3a9b13de090aa0 (patch)
tree0578d1b3141a450dbb98d4cc0640582af5d45e6c /functest
parent96047f5cd8427bdacfcb911cd95a68bfba845db5 (diff)
Cover ODLResultVisitor
It adds unit tests to cover ODLResultVisitor and then increases the coverage to 78%. It also fixes a nit in details pushed to DB. Change-Id: Ie4c31df67b5197c4273ee835242153e74b50601d Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest')
-rwxr-xr-xfunctest/opnfv_tests/sdn/odl/odl.py2
-rw-r--r--functest/tests/unit/odl/test_odl.py35
2 files changed, 36 insertions, 1 deletions
diff --git a/functest/opnfv_tests/sdn/odl/odl.py b/functest/opnfv_tests/sdn/odl/odl.py
index 706b0dad8..0905e55cc 100755
--- a/functest/opnfv_tests/sdn/odl/odl.py
+++ b/functest/opnfv_tests/sdn/odl/odl.py
@@ -35,7 +35,7 @@ class ODLResultVisitor(ResultVisitor):
output['name'] = test.name
output['parent'] = test.parent.name
output['status'] = test.status
- output['startime'] = test.starttime
+ output['starttime'] = test.starttime
output['endtime'] = test.endtime
output['critical'] = test.critical
output['text'] = test.message
diff --git a/functest/tests/unit/odl/test_odl.py b/functest/tests/unit/odl/test_odl.py
index 0deef6bde..d8c7f84ec 100644
--- a/functest/tests/unit/odl/test_odl.py
+++ b/functest/tests/unit/odl/test_odl.py
@@ -13,7 +13,9 @@ import mock
import os
import unittest
+from keystoneauth1.exceptions import auth_plugins
from robot.errors import RobotError
+from robot.result import testcase
from functest.core import testcase_base
from functest.opnfv_tests.sdn.odl import odl
@@ -43,6 +45,33 @@ class ODLTesting(unittest.TestCase):
os.environ["OS_TENANT_NAME"] = self._os_tenantname
self.test = odl.ODLTests()
+ def test_empty_visitor(self):
+ visitor = odl.ODLResultVisitor()
+ self.assertFalse(visitor.get_data())
+
+ def test_visitor(self):
+ visitor = odl.ODLResultVisitor()
+ data = {'name': 'foo',
+ 'parent': 'bar',
+ 'status': 'PASS',
+ 'starttime': "20161216 16:00:00.000",
+ 'endtime': "20161216 16:00:01.000",
+ 'elapsedtime': 1000,
+ 'text': 'Hello, World!',
+ 'critical': True}
+ test = testcase.TestCase(name=data['name'],
+ status=data['status'],
+ message=data['text'],
+ starttime=data['starttime'],
+ endtime=data['endtime'])
+ test.parent = mock.Mock()
+ config = {'name': data['parent'],
+ 'criticality.test_is_critical.return_value': data[
+ 'critical']}
+ test.parent.configure_mock(**config)
+ visitor.visit_test(test)
+ self.assertEqual(visitor.get_data(), [data])
+
@mock.patch('fileinput.input', side_effect=Exception())
def test_set_robotframework_vars_failed(self, *args):
self.assertFalse(self.test.set_robotframework_vars())
@@ -247,6 +276,12 @@ class ODLTesting(unittest.TestCase):
ospassword=self._os_password, ostenantname=self._os_tenantname,
osusername=self._os_username)
+ def test_run_exception(self):
+ with mock.patch('functest.utils.openstack_utils.get_endpoint',
+ side_effect=auth_plugins.MissingAuthPlugin()):
+ self.assertEqual(self.test.run(),
+ testcase_base.TestcaseBase.EX_RUN_ERROR)
+
def test_run_missing_os_username(self):
self._test_run_missing_env_var("OS_USERNAME")