1 # Copyright (c) 2017-2018 VMware, Inc.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 from multivimbroker.pub.utils import fileutil
18 class TestFileutil(unittest.TestCase):
20 @mock.patch.object(os.path, "exists")
21 @mock.patch("os.makedirs")
22 def test_make_dirs_path_exists(self, mock_mkdir, mock_exists):
23 new_path = "/tmp/test"
24 mock_exists.return_value = True
25 fileutil.make_dirs(new_path)
26 mock_mkdir.assert_not_called()
28 @mock.patch.object(os.path, "exists")
29 @mock.patch("os.makedirs")
30 def test_make_dirs_path_not_exists(self, mock_mkdir, mock_exists):
31 new_path = "/tmp/test"
32 mock_exists.return_value = False
33 fileutil.make_dirs(new_path)
34 mock_mkdir.assert_called_once_with(new_path, 0777)
36 @mock.patch.object(os.path, "exists")
37 @mock.patch("shutil.rmtree")
38 def test_delete_dirs_success(self, mock_rmtree, mock_exists):
39 mock_exists.return_value = True
40 new_path = "/tmp/tests"
41 fileutil.delete_dirs(new_path)
42 mock_rmtree.assert_called_once_with(new_path)