Enhance CSV metadata with error tracking for mosaics and tiles

This commit is contained in:
2026-04-25 16:06:54 -04:00
parent e8d3bf7180
commit ae37c06f15
10 changed files with 406 additions and 34 deletions
+85
View File
@@ -0,0 +1,85 @@
"""Mosaic download outcomes for scans.csv (RunStats / MosaicAttempt)."""
from pathlib import Path
from unittest.mock import MagicMock
from spruce.download_result import (
DownloadResult,
PERMANENT_MISSING,
TRANSIENT,
UNKNOWN,
)
from spruce.orchestrator import _download_mosaic
_MACHINE = {"label": "M", "option_value": "v", "machine_id": "1"}
_CONFIG: dict = {
"write_exif": False,
"timeout": 10,
"request_delay": 0.0,
"machine_metadata": {},
}
def test_download_mosaic_404_permanent_class():
sess = MagicMock()
url = "http://img/RootView_Database/9/mosaic.jpg"
sess.mosaic_url.return_value = url
sess.download_file.return_value = DownloadResult(0, 404, "404", PERMANENT_MISSING)
progress = MagicMock()
progress.is_done.return_value = False
mpath = Path("/tmp/mosaic_404.jpg")
out = _download_mosaic(
sess, {}, 9, mpath, progress, _MACHINE, _CONFIG, dry_run=False
)
assert out.csv_status == "failed"
assert out.error_class == PERMANENT_MISSING
assert out.error_code == "404"
progress.mark_done.assert_not_called()
def test_download_mosaic_503_transient_class():
sess = MagicMock()
sess.mosaic_url.return_value = "http://x/m.jpg"
sess.download_file.return_value = DownloadResult(0, 503, "err", TRANSIENT)
progress = MagicMock()
progress.is_done.return_value = False
out = _download_mosaic(
sess,
{},
1,
Path("/tmp/m.jpg"),
progress,
_MACHINE,
_CONFIG,
dry_run=False,
)
assert out.error_class == TRANSIENT
assert out.error_code == "503"
def test_download_mosaic_empty_body_unknown():
sess = MagicMock()
sess.mosaic_url.return_value = "http://x/m.jpg"
sess.download_file.return_value = DownloadResult(
0, 200, "0 bytes in response body", UNKNOWN
)
progress = MagicMock()
progress.is_done.return_value = False
out = _download_mosaic(
sess,
{},
1,
Path("/tmp/m.jpg"),
progress,
_MACHINE,
_CONFIG,
dry_run=False,
)
assert out.error_class == UNKNOWN
assert "bytes" in out.error or out.error