def _create_dir(dir_path, dir_type): try: EdgeUtils.mkdir_if_needed(dir_path) except OSError as ex: msg = 'Error creating {0} directory {1}'.format(dir_type, dir_path) log.error(msg) raise edgectl.errors.EdgeFileAccessError(msg, dir_path)
def test_mkdir_if_needed_when_dir_does_not_exist(self, mock_mkdirs): """ Test a valid invocation of API mkdir_if_needed when dir to be made does not exist """ # arrange dir_path = 'blah' # act EdgeUtils.mkdir_if_needed(dir_path) # assert mock_mkdirs.assert_called_with(dir_path)
def test_mkdir_if_needed_when_dir_exists(self, mock_mkdirs): """ Test a valid invocation of API mkdir_if_needed when dir to be made already exists """ # arrange dir_path = 'blah' mock_mkdirs.side_effect = OSError(errno.EEXIST, 'Directory exists.') # act EdgeUtils.mkdir_if_needed(dir_path) # assert mock_mkdirs.assert_called_with(dir_path)
def test_mkdir_if_needed_raises_oserror_when_mkdir_fails( self, mock_mkdirs): """ Tests invocation of API mkdir_if_needed raises OSError when makedirs raises OSError""" # arrange dir_path = 'blah' mock_mkdirs.side_effect = OSError(errno.EACCES, 'Directory permission error') # act, assert with self.assertRaises(OSError): EdgeUtils.mkdir_if_needed(dir_path)