mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Testing utils.filesystem.mkdir
- creating single folder - creating folder with parent - creating folder with specific owner - creating existing folder do not fail if using force=True - existance of folder prevent creation if not using force - no permission prevent creating folder Update filesyste.mkdir to not raise FileExistsError when force=True is used as parameter.
This commit is contained in:
parent
47b6a8c0cb
commit
53f55bf100
1 changed files with 26 additions and 0 deletions
|
@ -587,6 +587,17 @@ def test_mkdir_cannot_create_folder_if_it_exist(exists):
|
||||||
filesystem.mkdir(folder)
|
filesystem.mkdir(folder)
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch('os.path.exists')
|
||||||
|
@mock.patch('os.mkdir')
|
||||||
|
def test_mkdir_cannot_create_folder_if_no_permission(mkdir, exists):
|
||||||
|
folder = 'folder'
|
||||||
|
mkdir.side_effect = PermissionError
|
||||||
|
exists.return_value = False
|
||||||
|
|
||||||
|
with pytest.raises(OSError):
|
||||||
|
filesystem.mkdir(folder)
|
||||||
|
|
||||||
|
|
||||||
@mock.patch('os.path.exists')
|
@mock.patch('os.path.exists')
|
||||||
@mock.patch('os.mkdir')
|
@mock.patch('os.mkdir')
|
||||||
def test_mkdir_create_folder_if_does_not_exist(mkdir, exists):
|
def test_mkdir_create_folder_if_does_not_exist(mkdir, exists):
|
||||||
|
@ -641,6 +652,21 @@ def test_mkdir_create_folder_with_parents_if_necessary(mkdir, split, exists):
|
||||||
mkdir.assert_has_calls(calls)
|
mkdir.assert_has_calls(calls)
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch('os.path.exists')
|
||||||
|
@mock.patch('os.path.split')
|
||||||
|
@mock.patch('os.mkdir')
|
||||||
|
def test_mkdir_create_folder_with_parents_with_trailing_slash(mkdir, split, exists):
|
||||||
|
foldername = 'parent/folder/'
|
||||||
|
exists.side_effect = [False, False, False, False] # folder and parent do not exist
|
||||||
|
split.side_effect = [('parent/folder', ''), ('parent', 'folder'), ('', 'parent')]
|
||||||
|
|
||||||
|
filesystem.mkdir(foldername, parents=True)
|
||||||
|
|
||||||
|
calls = [mock.call('parent', 0o777),
|
||||||
|
mock.call('parent/folder/', 0o777)]
|
||||||
|
mkdir.assert_has_calls(calls)
|
||||||
|
|
||||||
|
|
||||||
@mock.patch('os.path.exists')
|
@mock.patch('os.path.exists')
|
||||||
@mock.patch('os.path.split')
|
@mock.patch('os.path.split')
|
||||||
@mock.patch('os.mkdir')
|
@mock.patch('os.mkdir')
|
||||||
|
|
Loading…
Add table
Reference in a new issue