Skip to content

Commit

Permalink
test progress report for chunked http-download
Browse files Browse the repository at this point in the history
This commit adds a test that verifies that
http-download progress is reported, if
no content-length header is provided.
  • Loading branch information
christian-monch committed Aug 25, 2023
1 parent 351b710 commit 87040e1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions datalad_next/url_operations/tests/test_http.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import gzip
import pytest
import requests

from ..any import AnyUrlOperations
from ..http import (
Expand Down Expand Up @@ -98,6 +99,29 @@ def test_compressed_file_stay_compressed(tmp_path):
f.read(1000)


def test_size_less_progress_reporting(http_server, monkeypatch):
test_file = (http_server.path / 'test.bin').open('wb')
test_file.seek(100000)
test_file.write(b'a')
test_file.close()

r = requests.get(http_server.url + '/test.bin', stream=True)
del r.headers['content-length']

logs = []
# patch the log_progress() used in http.py
def catch_progress(*_, **kwargs):
logs.append(kwargs)

import datalad_next.url_operations
monkeypatch.setattr(datalad_next.url_operations, 'log_progress', catch_progress)

http_handler = HttpUrlOperations()
http_handler._stream_download_from_request(r, None)
assert any('update' in kwargs for kwargs in logs)
assert any(('total', None) in kwargs.items() for kwargs in logs)


def test_header_adding():
default_headers = dict(key_1='value_1')
added_headers = dict(key_2='value_2')
Expand Down

0 comments on commit 87040e1

Please sign in to comment.