def test_delete_published_folder(published_folder):
    path, folder_name, *_ = published_folder

    response = helper.delete_resources_response(params=dict(path=path))

    check.response_has_status_code(response, 202, 204)

    with allure.step("Waiting when folder will be deleted"):
        wait(predicate=lambda: helper.get_resources_response(params=dict(
            path=path)).status_code == 404,
             timeout_seconds=30,
             sleep_seconds=(1, 2, 4))

    with allure.step("Deleted folder should be in trash folder"):
        folder_in_trash = helper.get_trash_resources(params=dict(
            path=folder_name))
        assert folder_in_trash[
            'name'] == folder_name, 'Unable to find deleted folder in trash'

    with allure.step("Deleted folder should be unpublished"):
        items = helper.get_public_resources().get('items')
        items_by_name = [
            item for item in items if item.get('name') == folder_name
        ]
        assert len(items_by_name) == 0, "Deleted file still published"
def test_delete_nonexistent_resource():
    response = helper.delete_resources_response(params=dict(
        path='nonexistent.txt'))

    check.response_has_status_code(response, 404)
    check.response_has_only_fields(response, 'message', 'description', 'error')
    check.response_has_field_with_value(response,
                                        field='error',
                                        value='DiskNotFoundError')
def test_delete_file_by_expired_user(temp_file):
    path, *_ = temp_file()

    response = helper.delete_resources_response(params=dict(path=path),
                                                by_user='******')

    check.response_has_status_code(response, 401)
    check.response_has_only_fields(response, 'message', 'description', 'error')
    check.response_has_field_with_value(response,
                                        field='error',
                                        value='UnauthorizedError')
def test_delete_folder_force_async(temp_folder):
    path, folder_name, *_ = temp_folder()

    response = helper.delete_resources_response(
        params=dict(path=path, force_async=True))
    check.response_has_status_code(response, 202)

    operation_id = helper.get_operation_id_from_response(response)
    helper.when_operation_status(operation_id=operation_id, status='success')

    with allure.step("Deleted folder should be in trash folder"):
        file_in_trash = helper.get_trash_resources(params=dict(
            path=folder_name))
        assert file_in_trash[
            'name'] == folder_name, 'Unable to find deleted folder in trash'
def test_delete_file(temp_file):
    path, file_name, *_ = temp_file()

    response = helper.delete_resources_response(params=dict(path=path))

    check.response_has_status_code(response, 202, 204)

    with allure.step("Waiting when file will be deleted"):
        wait(predicate=lambda: helper.get_resources_response(params=dict(
            path=path)).status_code == 404,
             timeout_seconds=30,
             sleep_seconds=(1, 2, 4))

    with allure.step("Deleted file should be in trash folder"):
        file_in_trash = helper.get_trash_resources(params=dict(path=file_name))
        assert file_in_trash[
            'name'] == file_name, 'Unable to find deleted file in trash'
def test_delete_file_permanently(temp_file):
    path, file_name, *_ = temp_file()

    response = helper.delete_resources_response(
        params=dict(path=path, permanently=True))
    check.response_has_status_code(response, 202, 204)

    with allure.step("Waiting when file will be deleted"):
        wait(predicate=lambda: helper.get_resources_response(params=dict(
            path=path)).status_code == 404,
             timeout_seconds=30,
             sleep_seconds=(1, 2, 4))

    with allure.step("Deleted permanently file should not be in trash folder"):
        response = helper.get_trash_resources_response(params=dict(
            path=file_name))
        assert response.status_code == 404, 'Deleted permanently file should not be in trash'