Add test_delete_dirs_failed
[multicloud/framework.git] / multivimbroker / multivimbroker / tests / test_fileutil.py
index 8eb4a52..9abd23c 100644 (file)
@@ -24,3 +24,28 @@ class TestFileutil(unittest.TestCase):
         mock_exists.return_value = True
         fileutil.make_dirs(new_path)
         mock_mkdir.assert_not_called()
+
+    @mock.patch.object(os.path, "exists")
+    @mock.patch("os.makedirs")
+    def test_make_dirs_path_not_exists(self, mock_mkdir, mock_exists):
+        new_path = "/tmp/test"
+        mock_exists.return_value = False
+        fileutil.make_dirs(new_path)
+        mock_mkdir.assert_called_once_with(new_path, 0777)
+
+    @mock.patch.object(os.path, "exists")
+    @mock.patch("shutil.rmtree")
+    def test_delete_dirs_success(self, mock_rmtree, mock_exists):
+        mock_exists.return_value = True
+        new_path = "/tmp/tests"
+        fileutil.delete_dirs(new_path)
+        mock_rmtree.assert_called_once_with(new_path)
+
+    @mock.patch.object(os.path, "exists")
+    @mock.patch("shutil.rmtree")
+    def test_delete_dirs_failed(self, mock_rmtree, mock_exists):
+        mock_exists.return_value = True
+        mock_rmtree.side_effect = [Exception("Fake exception")]
+        new_path = "/tmp/tests"
+        fileutil.delete_dirs(new_path)
+        mock_rmtree.assert_called_once_with(new_path)