Esempio n. 1
0
 def _delete_dir(dir_path, dir_type):
     try:
         EdgeUtils.delete_dir(dir_path)
     except OSError as ex:
         msg = 'Error deleting {0} directory {1}'.format(dir_type, dir_path)
         log.error(msg)
         raise edgectl.errors.EdgeFileAccessError(msg, dir_path)
Esempio n. 2
0
    def test_delete_dir_raises_oserror_when_rmtree_fails(
            self, mock_exists, mock_rmtree):
        """ Tests invocation of API delete_dir raises OSError when rmtree raises OSError"""
        # arrange
        dir_path = 'blah'
        mock_exists.return_value = True
        mock_rmtree.side_effect = OSError('rmtree error')

        # act, assert
        with self.assertRaises(OSError):
            EdgeUtils.delete_dir(dir_path)
Esempio n. 3
0
    def test_delete_dir_when_dir_does_not_exist(self, mock_exists,
                                                mock_rmtree):
        """ Test a valid invocation of API delete_dir when dir to be deleted does not exist"""
        # arrange
        dir_path = 'blah'
        mock_exists.return_value = False

        # act
        EdgeUtils.delete_dir(dir_path)

        # assert
        mock_exists.assert_called_with(dir_path)
        mock_rmtree.assert_not_called()
Esempio n. 4
0
    def test_delete_dir_when_dir_exists(self, mock_exists, mock_rmtree):
        """ Test a valid invocation of API delete_dir when dir to be deleted exists"""
        # arrange
        dir_path = 'blah'
        mock_exists.return_value = True

        # act
        EdgeUtils.delete_dir(dir_path)

        # assert
        mock_exists.assert_called_with(dir_path)
        mock_rmtree.assert_called_with(
            dir_path, onerror=EdgeUtils._remove_readonly_callback)