Merge "Enable tempest offline by use_custom_images=True"
[functest.git] / functest / tests / unit / core / test_testcase.py
index d017e41..0a6f0c9 100644 (file)
@@ -20,12 +20,9 @@ __author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
 
 
 class TestCaseTesting(unittest.TestCase):
-
     """The class testing TestCase."""
     # pylint: disable=missing-docstring,too-many-public-methods
 
-    logging.disable(logging.CRITICAL)
-
     _case_name = "base"
     _project_name = "functest"
     _published_result = "PASS"
@@ -191,11 +188,13 @@ class TestCaseTesting(unittest.TestCase):
 
     def test_str_project_name_ko(self):
         self.test.project_name = None
-        self.assertIn("INVALID OBJECT", str(self.test))
+        self.assertIn("<functest.core.testcase.TestCase object at",
+                      str(self.test))
 
     def test_str_case_name_ko(self):
         self.test.case_name = None
-        self.assertIn("INVALID OBJECT", str(self.test))
+        self.assertIn("<functest.core.testcase.TestCase object at",
+                      str(self.test))
 
     def test_str_pass(self):
         duration = '01:01'
@@ -222,6 +221,56 @@ class TestCaseTesting(unittest.TestCase):
         self.assertIn(duration, message)
         self.assertIn('FAIL', message)
 
+    def test_create_snapshot(self):
+        self.assertEqual(self.test.create_snapshot(),
+                         testcase.TestCase.EX_OK)
+
+    def test_clean(self):
+        self.assertEqual(self.test.clean(), None)
+
+
+class OSGCTestCaseTesting(unittest.TestCase):
+    """The class testing OSGCTestCase."""
+    # pylint: disable=missing-docstring
+
+    def setUp(self):
+        self.test = testcase.OSGCTestCase()
+
+    @mock.patch('functest.utils.openstack_snapshot.main',
+                side_effect=Exception)
+    def test_create_snapshot_exc(self, mock_method=None):
+        self.assertEqual(self.test.create_snapshot(),
+                         testcase.TestCase.EX_RUN_ERROR)
+        mock_method.assert_called_once_with()
+
+    @mock.patch('functest.utils.openstack_snapshot.main', return_value=-1)
+    def test_create_snapshot_ko(self, mock_method=None):
+        self.assertEqual(self.test.create_snapshot(),
+                         testcase.TestCase.EX_RUN_ERROR)
+        mock_method.assert_called_once_with()
+
+    @mock.patch('functest.utils.openstack_snapshot.main', return_value=0)
+    def test_create_snapshot_env(self, mock_method=None):
+        self.assertEqual(self.test.create_snapshot(),
+                         testcase.TestCase.EX_OK)
+        mock_method.assert_called_once_with()
+
+    @mock.patch('functest.utils.openstack_clean.main', side_effect=Exception)
+    def test_clean_exc(self, mock_method=None):
+        self.assertEqual(self.test.clean(), None)
+        mock_method.assert_called_once_with()
+
+    @mock.patch('functest.utils.openstack_clean.main', return_value=-1)
+    def test_clean_ko(self, mock_method=None):
+        self.assertEqual(self.test.clean(), None)
+        mock_method.assert_called_once_with()
+
+    @mock.patch('functest.utils.openstack_clean.main', return_value=0)
+    def test_clean(self, mock_method=None):
+        self.assertEqual(self.test.clean(), None)
+        mock_method.assert_called_once_with()
+
 
 if __name__ == "__main__":
+    logging.disable(logging.CRITICAL)
     unittest.main(verbosity=2)