fix: complete PPI and KaKs reference handoff
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import http.client
|
||||
import zipfile
|
||||
|
||||
|
||||
@@ -73,5 +74,51 @@ def test_reference_bundle_download_reports_progress_events(tmp_path, monkeypatch
|
||||
assert "validate_ids" in phases
|
||||
assert phases[-1] == "completed"
|
||||
assert manifest["requested_stages"] == ["ppi"]
|
||||
assert manifest["requested_file_types"] == ["pep"]
|
||||
assert "cds" not in manifest["files"]
|
||||
assert manifest["requested_file_types"] == ["pep", "cds"]
|
||||
assert "cds" in manifest["files"]
|
||||
|
||||
|
||||
def test_reference_bundle_download_retries_incomplete_read(tmp_path, monkeypatch):
|
||||
from apps.web import pipeline_backend as backend
|
||||
|
||||
payload = b"complete archive"
|
||||
calls = {"count": 0}
|
||||
|
||||
class FakeResponse:
|
||||
def __init__(self, *, incomplete: bool):
|
||||
self.incomplete = incomplete
|
||||
self.headers = {"Content-Length": str(len(payload))}
|
||||
self._sent = False
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *_args):
|
||||
return False
|
||||
|
||||
def read(self, _size):
|
||||
if self.incomplete:
|
||||
raise http.client.IncompleteRead(b"partial", len(payload))
|
||||
if self._sent:
|
||||
return b""
|
||||
self._sent = True
|
||||
return payload
|
||||
|
||||
def fake_urlopen(_url, timeout):
|
||||
calls["count"] += 1
|
||||
return FakeResponse(incomplete=calls["count"] == 1)
|
||||
|
||||
monkeypatch.setattr(backend.urllib.request, "urlopen", fake_urlopen)
|
||||
monkeypatch.setattr(backend.time, "sleep", lambda _seconds: None)
|
||||
output_path = tmp_path / "reference.zip"
|
||||
|
||||
downloaded = backend._download_url_to_file(
|
||||
"https://example.invalid/reference.zip",
|
||||
output_path,
|
||||
attempts=2,
|
||||
)
|
||||
|
||||
assert calls["count"] == 2
|
||||
assert downloaded == len(payload)
|
||||
assert output_path.read_bytes() == payload
|
||||
assert not output_path.with_suffix(".zip.part").exists()
|
||||
|
||||
Reference in New Issue
Block a user