Add unit tests for feature 97/32897/3
authorCédric Ollivier <cedric.ollivier@orange.com>
Sun, 2 Apr 2017 08:29:51 +0000 (10:29 +0200)
committerCédric Ollivier <cedric.ollivier@orange.com>
Tue, 4 Apr 2017 13:16:52 +0000 (15:16 +0200)
They partially cover feature but already highlight bugs.
Several tests are skipped to allow merging. Their decorators could be
removed as soon as feature is fixed.

I think bad-continuation is false positive so it's disabled (pep8 and
flake8 return ok).

JIRA: FUNCTEST-779

Change-Id: I89b9e2ec0388eea2471d941b2c653deca7fbddf6
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
functest/tests/unit/core/test_feature.py [new file with mode: 0644]
run_unit_tests.sh

diff --git a/functest/tests/unit/core/test_feature.py b/functest/tests/unit/core/test_feature.py
new file mode 100644 (file)
index 0000000..0ed178a
--- /dev/null
@@ -0,0 +1,108 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2017 Orange and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# pylint: disable=missing-docstring
+
+import logging
+import unittest
+
+import mock
+
+from functest.core import feature
+from functest.core import testcase
+from functest.utils import constants
+
+
+class FeatureInitTesting(unittest.TestCase):
+
+    logging.disable(logging.CRITICAL)
+
+    @unittest.skip("JIRA: FUNCTEST-780")
+    def test_init_with_wrong_repo(self):
+        with self.assertRaises(ValueError):
+            feature.Feature(repo='foo')
+
+    def test_init(self):
+        barometer = feature.Feature(repo='dir_repo_barometer')
+        self.assertEqual(barometer.project_name, "functest")
+        self.assertEqual(barometer.case_name, "")
+        self.assertEqual(
+            barometer.repo,
+            constants.CONST.__getattribute__('dir_repo_barometer'))
+
+
+class FeatureTesting(unittest.TestCase):
+
+    logging.disable(logging.CRITICAL)
+
+    def setUp(self):
+        self.feature = feature.Feature(repo='dir_repo_barometer')
+
+    @unittest.skip("JIRA: FUNCTEST-781")
+    def test_prepare_ko(self):
+        # pylint: disable=bad-continuation
+        with mock.patch.object(
+                self.feature, 'prepare',
+                return_value=testcase.TestCase.EX_RUN_ERROR) as mock_object:
+            self.assertEqual(self.feature.run(),
+                             testcase.TestCase.EX_RUN_ERROR)
+            mock_object.assert_called_once_with()
+
+    @unittest.skip("JIRA: FUNCTEST-781")
+    def test_prepare_exc(self):
+        with mock.patch.object(self.feature, 'prepare',
+                               side_effect=Exception) as mock_object:
+            self.assertEqual(self.feature.run(),
+                             testcase.TestCase.EX_RUN_ERROR)
+            mock_object.assert_called_once_with()
+
+    @unittest.skip("JIRA: FUNCTEST-781")
+    def test_post_ko(self):
+        # pylint: disable=bad-continuation
+        with mock.patch.object(
+                self.feature, 'post',
+                return_value=testcase.TestCase.EX_RUN_ERROR) as mock_object:
+            self.assertEqual(self.feature.run(),
+                             testcase.TestCase.EX_RUN_ERROR)
+            mock_object.assert_called_once_with()
+
+    @unittest.skip("JIRA: FUNCTEST-781")
+    def test_post_exc(self):
+        with mock.patch.object(self.feature, 'post',
+                               side_effect=Exception) as mock_object:
+            self.assertEqual(self.feature.run(),
+                             testcase.TestCase.EX_RUN_ERROR)
+            mock_object.assert_called_once_with()
+
+    @unittest.skip("JIRA: FUNCTEST-778")
+    def test_execute_ko(self):
+        with mock.patch.object(self.feature, 'execute',
+                               return_value=1) as mock_object:
+            self.assertEqual(self.feature.run(),
+                             testcase.TestCase.EX_RUN_ERROR)
+            mock_object.assert_called_once_with()
+
+    @unittest.skip("JIRA: FUNCTEST-778")
+    def test_execute_exc(self):
+        with mock.patch.object(self.feature, 'execute',
+                               side_effect=Exception) as mock_object:
+            self.assertEqual(self.feature.run(),
+                             testcase.TestCase.EX_RUN_ERROR)
+            mock_object.assert_called_once_with()
+
+    def test_run(self):
+        with mock.patch.object(self.feature, 'execute',
+                               return_value=0) as mock_object:
+            self.assertEqual(self.feature.run(),
+                             testcase.TestCase.EX_OK)
+            mock_object.assert_called_once_with()
+
+
+if __name__ == "__main__":
+    unittest.main(verbosity=2)
index 0ed1f7b..917c8ee 100755 (executable)
@@ -40,7 +40,7 @@ nosetests --with-xunit \
          --cover-tests \
          --cover-package=functest.ci \
          --cover-package=functest.cli \
-         --cover-package=functest.core.testcase \
+         --cover-package=functest.core \
          --cover-package=functest.opnfv_tests.sdn.odl.odl \
          --cover-package=functest.opnfv_tests.vnf.ims \
          --cover-package=functest.utils \