From 15e37ef0e043f98ef14639ef77bd07188930c027 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Mon, 1 Jun 2026 15:09:49 +0000 Subject: [PATCH] =?UTF-8?q?`get=5Fevidence=5Ffiles=5Fby=5Fjob=5Fid`=20retu?= =?UTF-8?q?rns=20`DownloadedFiles`=20with=20empty=20`other`=20when=20`incl?= =?UTF-8?q?ude=5Fother=3DFalse`=20=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/pashub_fetcher/pashub_client.py | 10 +++++ .../tests/test_pashub_client.py | 38 ++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/backend/pashub_fetcher/pashub_client.py b/backend/pashub_fetcher/pashub_client.py index 26061e3e..0234d0af 100644 --- a/backend/pashub_fetcher/pashub_client.py +++ b/backend/pashub_fetcher/pashub_client.py @@ -18,6 +18,11 @@ class _EvidenceFileGroups(NamedTuple): other: List[EvidenceFileData] +class DownloadedFiles(NamedTuple): + core: List[str] + other: List[str] + + class UnauthorizedError(Exception): pass @@ -75,6 +80,11 @@ class PashubClient: return saved_files + def get_evidence_files_by_job_id( + self, job_id: str, include_other: bool = False + ) -> DownloadedFiles: + raise NotImplementedError + def get_uprn_by_job_id(self, job_id: str) -> Optional[str]: logger.info(f"Getting UPRN for job ID {job_id}") url = f"{self.base}/jobs/{job_id}" diff --git a/backend/pashub_fetcher/tests/test_pashub_client.py b/backend/pashub_fetcher/tests/test_pashub_client.py index aa6943c2..fa23378d 100644 --- a/backend/pashub_fetcher/tests/test_pashub_client.py +++ b/backend/pashub_fetcher/tests/test_pashub_client.py @@ -1,9 +1,18 @@ # pyright: reportPrivateUsage=false from typing import Optional +from unittest.mock import patch from backend.pashub_fetcher.core_files import CoreFiles from backend.pashub_fetcher.evidence_file_data import EvidenceFileData -from backend.pashub_fetcher.pashub_client import PashubClient +from backend.pashub_fetcher.evidence_metadata import EvidenceMetadata +from backend.pashub_fetcher.pashub_client import DownloadedFiles, PashubClient + + +def make_metadata() -> EvidenceMetadata: + return EvidenceMetadata( + container_name="my-container", + blob_uri="https://storage.example.com/blob?sas=token", + ) def make_client() -> PashubClient: @@ -131,3 +140,30 @@ def test_group_into_core_and_other_files_falls_back_to_latest_when_no_osm_candid # Assert assert result.core[CoreFiles.RETROFIT_DESIGN_DOC].file_name == "retrofit_design_v2.pdf" + + +# --------------------------------------------------------------------------- +# get_evidence_files_by_job_id +# --------------------------------------------------------------------------- + + +def test_get_evidence_files_by_job_id_returns_downloaded_files_with_empty_other_when_include_other_false() -> None: + # Arrange + client = make_client() + files = [ + make_file(file_name="SiteNote_001.pdf"), + make_file(file_name="unknown_doc.pdf"), + ] + + # Act + with ( + patch.object(client, "_get_evidence_list", return_value=files), + patch.object(client, "_get_evidence_metadata", return_value=make_metadata()), + patch.object(client, "_download_file"), + ): + result = client.get_evidence_files_by_job_id("job-1", include_other=False) + + # Assert + assert isinstance(result, DownloadedFiles) + assert result.core == ["/tmp/SiteNote_001.pdf"] + assert result.other == []