test/test_delete_temporary_files.py
def download_with_exception(mock_requests, output_file_path, mock_server_config, file):
    """
    Simulates downloading a file of the given size: "true_file_size".
    During the transfer, an exception happens and the temporary file is either deleted
    or kept, depending on the TEMPORARY_FILES_SHOULD_BE_DELETED flag.
    """

    number_of_retries = 2
    not_enough_bytes = int(expected_file_size / 3 - 1000)
    content = bytearray(os.urandom(not_enough_bytes))
    output_dir = os.path.dirname(output_file_path)

    # First, normal GET request:
    mock_requests.add(responses.GET, f'{mock_server_config.url_api}/files/{file.id}', body=content, status=200)
    # Then all the retry attempt:
    for _ in range(number_of_retries):
        mock_requests.add(responses.GET, f'{mock_server_config.url_api}/files/{file.id}', body=content, status=200)

    with pytest.raises(Exception) as context_manager:
        file.download_file_retry(1, output_dir, None, number_of_retries, 0.1)

    exception_message = str(context_manager.value)
    assert re.compile(r'Slice error: received=\d+, requested=\d+').search(exception_message)

    display_file_name = os.path.basename(output_file_path)
    downloaded_file = f'{output_dir}/{test_file_id}/{display_file_name}'
    assert not os.path.exists(downloaded_file)

    Simulates downloading a file of the given size: "true_file_size".
    During the transfer, an exception happens and the temporary file is either deleted
    or kept, depending on the TEMPORARY_FILES_SHOULD_BE_DELETED flag.
    
Simulates downloading a file of the given size: "true_file_size".
During the transfer, an exception happens and the temporary file is either deleted
or kept, depending on the TEMPORARY_FILES_SHOULD_BE_DELETED flag.
Simulates downloading a file of the given size : " true_file_size " . During the transfer an exception happens and the temporary file is either deleted or kept depending on the TEMPORARY_FILES_SHOULD_BE_DELETED flag .
def download_with_exception(mock_requests, output_file_path, mock_server_config, file):
    number_of_retries = 2
    not_enough_bytes = int(expected_file_size / 3 - 1000)
    content = bytearray(os.urandom(not_enough_bytes))
    output_dir = os.path.dirname(output_file_path)
    mock_requests.add(responses.GET, f'{mock_server_config.url_api}/files/{file.id}', body=content, status=200)
    for _ in range(number_of_retries):
        mock_requests.add(responses.GET, f'{mock_server_config.url_api}/files/{file.id}', body=content, status=200)
    with pytest.raises(Exception) as context_manager:
        file.download_file_retry(1, output_dir, None, number_of_retries, 0.1)
    exception_message = str(context_manager.value)
    assert re.compile(r'Slice error: received=\d+, requested=\d+').search(exception_message)
    display_file_name = os.path.basename(output_file_path)
    downloaded_file = f'{output_dir}/{test_file_id}/{display_file_name}'
    assert not os.path.exists(downloaded_file)
def download_with_exception ( mock_requests , output_file_path , mock_server_config , file ) : number_of_retries = 2 not_enough_bytes = int ( expected_file_size / 3 - 1000 ) content = bytearray ( os . urandom ( not_enough_bytes ) ) output_dir = os . path . dirname ( output_file_path ) mock_requests . add ( responses . GET , f'{mock_server_config.url_api}/files/{file.id}' , body = content , status = 200 ) for _ in range ( number_of_retries ) : mock_requests . add ( responses . GET , f'{mock_server_config.url_api}/files/{file.id}' , body = content , status = 200 ) with pytest . raises ( Exception ) as context_manager : file . download_file_retry ( 1 , output_dir , None , number_of_retries , 0.1 ) exception_message = str ( context_manager . value ) assert re . compile ( r'Slice error: received=\d+, requested=\d+' ) . search ( exception_message ) display_file_name = os . path . basename ( output_file_path ) downloaded_file = f'{output_dir}/{test_file_id}/{display_file_name}' assert not os . path . exists ( downloaded_file )
Simulates downloading a file of the given size: "true_file_size".
Simulates downloading a file of the given size : " true_file_size " .
"""
    Simulates downloading a file of the given size: "true_file_size".
    During the transfer, an exception happens and the temporary file is either deleted
    or kept, depending on the TEMPORARY_FILES_SHOULD_BE_DELETED flag.
    """ # First, normal GET request: # Then all the retry attempt:
mock_requests
output_file_path
mock_server_config
file