feat: add APK download progress bar
This commit is contained in:
@@ -393,8 +393,10 @@ class TestFdroidSource:
|
||||
download_url="https://example.com/x.apk",
|
||||
expected_sha256=sha,
|
||||
)
|
||||
result = source.download_apk(release, cache)
|
||||
progress = mock.Mock()
|
||||
result = source.download_apk(release, cache, progress=progress)
|
||||
assert result == cache.cached_path(app_entry.app_id, sha)
|
||||
progress.assert_not_called()
|
||||
|
||||
def test_download_apk_sha256_mismatch(self, app_entry: sideload.AppEntry, cache: sideload.DownloadCache):
|
||||
apk_data = b"real-content"
|
||||
@@ -1293,6 +1295,52 @@ class TestUtilities:
|
||||
assert dest.read_bytes() == data
|
||||
assert not dest.with_suffix(".apk.tmp").exists()
|
||||
|
||||
def test_atomic_download_reports_content_length_progress(self, tmp_path: Path):
|
||||
data = b"downloaded-content"
|
||||
response = _mock_urlopen_response(data)
|
||||
response.headers = {"Content-Length": str(len(data))}
|
||||
updates = []
|
||||
with _mock_download_opener(response):
|
||||
result = sideload._atomic_download(
|
||||
"https://example.com/x.apk",
|
||||
tmp_path / "test.apk",
|
||||
progress=lambda downloaded, total: updates.append((downloaded, total)),
|
||||
)
|
||||
assert result.read_bytes() == data
|
||||
assert updates[0] == (0, len(data))
|
||||
assert updates[-1] == (len(data), len(data))
|
||||
|
||||
def test_atomic_download_reports_indeterminate_progress(self, tmp_path: Path):
|
||||
data = b"downloaded-content"
|
||||
response = _mock_urlopen_response(data)
|
||||
response.headers = {}
|
||||
updates = []
|
||||
with _mock_download_opener(response):
|
||||
result = sideload._atomic_download(
|
||||
"https://example.com/x.apk",
|
||||
tmp_path / "test.apk",
|
||||
expected_size=None,
|
||||
progress=lambda downloaded, total: updates.append((downloaded, total)),
|
||||
)
|
||||
assert result.read_bytes() == data
|
||||
assert updates[0] == (0, None)
|
||||
assert updates[-1] == (len(data), None)
|
||||
|
||||
def test_atomic_download_uses_expected_size_without_content_length(self, tmp_path: Path):
|
||||
data = b"downloaded-content"
|
||||
response = _mock_urlopen_response(data)
|
||||
response.headers = {}
|
||||
updates = []
|
||||
with _mock_download_opener(response):
|
||||
sideload._atomic_download(
|
||||
"https://example.com/x.apk",
|
||||
tmp_path / "test.apk",
|
||||
expected_size=len(data),
|
||||
progress=lambda downloaded, total: updates.append((downloaded, total)),
|
||||
)
|
||||
assert updates[0] == (0, len(data))
|
||||
assert updates[-1] == (len(data), len(data))
|
||||
|
||||
def test_atomic_download_cleans_up_on_error(self, tmp_path: Path):
|
||||
dest = tmp_path / "file.apk"
|
||||
with _mock_download_opener(error=RuntimeError("fail")):
|
||||
|
||||
Reference in New Issue
Block a user