Apply the DDD import rewrite to the orchestrator and its test 🟪

The previous commit staged these two files at `git mv` time but never
staged the edits that followed, so they landed with their pre-refactor
content: `class PashubService` and `from backend.pashub_fetcher...`
imports that no longer resolve. Local runs passed because the working
tree was correct; CI collected the committed tree and failed with
ModuleNotFoundError: No module named 'backend.pashub_fetcher'.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Daniel Roth 2026-07-22 13:40:07 +00:00
parent ae1da26558
commit 9933c678a9
2 changed files with 85 additions and 85 deletions

View file

@ -11,15 +11,15 @@ from infrastructure.postgres.uploaded_file_table import (
)
from backend.documents_parser.db_writer import save_epc_property_data
from backend.documents_parser.parser import parse_site_notes_pdf
from backend.pashub_fetcher.core_files import get_file_type_string
from backend.pashub_fetcher.pashub_client import (
from infrastructure.pashub_fetcher.core_file_types import get_file_type_string
from infrastructure.pashub_fetcher.pashub_client import (
DownloadedFile,
DownloadedFiles,
PashubClient,
RdSapSummary,
UnauthorizedError,
)
from backend.pashub_fetcher.pashub_to_ara_trigger_request import (
from applications.pashub_fetcher.pashub_to_ara_trigger_request import (
PashubToAraTriggerRequest,
)
from datatypes.epc.domain.epc import Epc
@ -63,7 +63,7 @@ class _FileUploadRecord(NamedTuple):
uprn: Optional[int]
class PashubService:
class PashubFetcherOrchestrator:
def __init__(
self,
pashub_client: PashubClient,

View file

@ -5,15 +5,15 @@ from unittest.mock import MagicMock, call, patch
from infrastructure.postgres.uploaded_file_table import FileSourceEnum, FileTypeEnum
from backend.pashub_fetcher.pashub_client import (
from infrastructure.pashub_fetcher.pashub_client import (
DownloadedFile,
DownloadedFiles,
PashubClient,
RdSapSummary,
UnauthorizedError,
)
from backend.pashub_fetcher.pashub_service import PashubService
from backend.pashub_fetcher.pashub_to_ara_trigger_request import (
from orchestration.pashub_fetcher_orchestrator import PashubFetcherOrchestrator
from applications.pashub_fetcher.pashub_to_ara_trigger_request import (
PashubToAraTriggerRequest,
)
from datatypes.epc.domain.epc import Epc
@ -101,8 +101,8 @@ def make_service(
sharepoint_client: Optional[DomnaSharepointClient] = None,
s3_bucket: str = "test-bucket",
coordination_client_factory: Optional[Callable[[], PashubClient]] = None,
) -> PashubService:
return PashubService(
) -> PashubFetcherOrchestrator:
return PashubFetcherOrchestrator(
pashub_client=pashub_client or MagicMock(spec=PashubClient),
sharepoint_client=sharepoint_client or MagicMock(spec=DomnaSharepointClient),
s3_bucket=s3_bucket,
@ -134,7 +134,7 @@ def test_run_returns_file_paths() -> None:
service = make_service(pashub_client=mock_client)
with patch("backend.pashub_fetcher.pashub_service.os.remove"):
with patch("orchestration.pashub_fetcher_orchestrator.os.remove"):
result = service.run(make_request())
assert result == ["/tmp/a.pdf", "/tmp/b.pdf"]
@ -157,7 +157,7 @@ def test_run_returns_core_and_other_file_paths() -> None:
service = make_service(pashub_client=mock_client)
# Act
with patch("backend.pashub_fetcher.pashub_service.os.remove"):
with patch("orchestration.pashub_fetcher_orchestrator.os.remove"):
result = service.run(make_request(get_other_files=True))
# Assert
@ -179,8 +179,8 @@ def test_run_skips_upload_when_no_uprn_and_no_deal_id() -> None:
service = make_service(pashub_client=mock_client)
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3") as mock_s3,
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3") as mock_s3,
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
service.run(make_request(uprn=None, hubspot_deal_id=None))
@ -202,9 +202,9 @@ def test_run_uploads_files_to_s3_using_uprn_path() -> None:
service = make_service(pashub_client=mock_client, s3_bucket="my-bucket")
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3") as mock_s3,
patch("backend.pashub_fetcher.pashub_service.db_session"),
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3") as mock_s3,
patch("orchestration.pashub_fetcher_orchestrator.db_session"),
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
service.run(make_request(uprn="12345"))
@ -241,9 +241,9 @@ def test_run_persists_uploaded_file_records_to_db() -> None:
service = make_service(pashub_client=mock_client)
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
patch("backend.pashub_fetcher.pashub_service.db_session") as mock_db,
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3"),
patch("orchestration.pashub_fetcher_orchestrator.db_session") as mock_db,
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
mock_db.return_value.__enter__.return_value = fake_session
service.run(make_request(uprn="12345"))
@ -271,9 +271,9 @@ def test_run_uses_hubspot_deal_id_path_when_no_uprn() -> None:
service = make_service(pashub_client=mock_client, s3_bucket="my-bucket")
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3") as mock_s3,
patch("backend.pashub_fetcher.pashub_service.db_session"),
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3") as mock_s3,
patch("orchestration.pashub_fetcher_orchestrator.db_session"),
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
service.run(make_request(uprn=None, hubspot_deal_id="deal-abc"))
@ -305,16 +305,16 @@ def test_run_parses_and_saves_site_notes_for_rd_sap_site_note_file() -> None:
service = make_service(pashub_client=mock_client)
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3"),
patch(
"backend.pashub_fetcher.pashub_service.parse_site_notes_pdf",
"orchestration.pashub_fetcher_orchestrator.parse_site_notes_pdf",
return_value=parsed,
) as mock_parse,
patch(
"backend.pashub_fetcher.pashub_service.save_epc_property_data"
"orchestration.pashub_fetcher_orchestrator.save_epc_property_data"
) as mock_save,
patch("backend.pashub_fetcher.pashub_service.db_session") as mock_db,
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.db_session") as mock_db,
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
fake_session.add_all = MagicMock(
side_effect=lambda files: setattr(files[0], "id", fake_uploaded_file_id)
@ -355,9 +355,9 @@ def test_run_uses_coordination_client_when_pas_401_on_uprn_lookup() -> None:
)
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
patch("backend.pashub_fetcher.pashub_service.db_session"),
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3"),
patch("orchestration.pashub_fetcher_orchestrator.db_session"),
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
result = service.run(make_request())
@ -383,9 +383,9 @@ def test_run_uses_coordination_client_when_pas_401_on_file_listing() -> None:
)
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
patch("backend.pashub_fetcher.pashub_service.db_session"),
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3"),
patch("orchestration.pashub_fetcher_orchestrator.db_session"),
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
result = service.run(make_request(uprn="12345"))
@ -441,9 +441,9 @@ def test_run_persists_coordination_hub_file_source_when_pas_401_on_uprn_lookup()
)
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
patch("backend.pashub_fetcher.pashub_service.db_session") as mock_db,
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3"),
patch("orchestration.pashub_fetcher_orchestrator.db_session") as mock_db,
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
mock_db.return_value.__enter__.return_value = fake_session
service.run(make_request())
@ -472,9 +472,9 @@ def test_run_persists_coordination_hub_file_source_when_pas_401_on_file_listing(
)
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
patch("backend.pashub_fetcher.pashub_service.db_session") as mock_db,
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3"),
patch("orchestration.pashub_fetcher_orchestrator.db_session") as mock_db,
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
mock_db.return_value.__enter__.return_value = fake_session
service.run(make_request(uprn="12345"))
@ -501,7 +501,7 @@ def test_run_deletes_other_temp_files_when_get_other_files_true() -> None:
service = make_service(pashub_client=mock_client)
# Act
with patch("backend.pashub_fetcher.pashub_service.os.remove") as mock_remove:
with patch("orchestration.pashub_fetcher_orchestrator.os.remove") as mock_remove:
service.run(make_request(get_other_files=True))
# Assert
@ -527,9 +527,9 @@ def test_run_uploads_other_files_to_s3_when_get_other_files_true() -> None:
# Act
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3") as mock_s3,
patch("backend.pashub_fetcher.pashub_service.db_session"),
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3") as mock_s3,
patch("orchestration.pashub_fetcher_orchestrator.db_session"),
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
service.run(make_request(uprn="12345", get_other_files=True))
@ -560,9 +560,9 @@ def test_run_persists_other_files_with_other_file_type() -> None:
# Act
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
patch("backend.pashub_fetcher.pashub_service.db_session") as mock_db,
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3"),
patch("orchestration.pashub_fetcher_orchestrator.db_session") as mock_db,
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
mock_db.return_value.__enter__.return_value = fake_session
service.run(make_request(uprn="12345", get_other_files=True))
@ -591,9 +591,9 @@ def test_run_persists_mcs_cert_with_mcs_compliance_certificate_file_type() -> No
# Act
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
patch("backend.pashub_fetcher.pashub_service.db_session") as mock_db,
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3"),
patch("orchestration.pashub_fetcher_orchestrator.db_session") as mock_db,
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
mock_db.return_value.__enter__.return_value = fake_session
service.run(make_request(uprn="12345"))
@ -626,7 +626,7 @@ def test_sharepoint_uploads_all_files_to_property_folder() -> None:
service = make_service(pashub_client=mock_client, sharepoint_client=mock_sharepoint)
# Act
with patch("backend.pashub_fetcher.pashub_service.os.remove"):
with patch("orchestration.pashub_fetcher_orchestrator.os.remove"):
service.run(
make_request(
sharepoint_link="Retrofit/Properties",
@ -661,8 +661,8 @@ def test_sharepoint_skips_upload_when_folder_not_found() -> None:
# Act
with (
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("backend.pashub_fetcher.pashub_service.logger") as mock_logger,
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.logger") as mock_logger,
):
service.run(
make_request(
@ -684,14 +684,14 @@ def test_sharepoint_skips_upload_when_sharepoint_client_is_none() -> None:
core=["/tmp/core.pdf"]
)
service = PashubService(
service = PashubFetcherOrchestrator(
pashub_client=mock_client,
sharepoint_client=None,
s3_bucket="test-bucket",
)
# Act — should not raise AttributeError on None._sharepoint_client
with patch("backend.pashub_fetcher.pashub_service.os.remove"):
with patch("orchestration.pashub_fetcher_orchestrator.os.remove"):
result = service.run(
make_request(
sharepoint_link="Retrofit/Properties",
@ -713,17 +713,17 @@ def test_run_warns_and_continues_when_site_notes_parsing_fails() -> None:
service = make_service(pashub_client=mock_client)
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3"),
patch(
"backend.pashub_fetcher.pashub_service.parse_site_notes_pdf",
"orchestration.pashub_fetcher_orchestrator.parse_site_notes_pdf",
side_effect=ValueError("corrupt pdf"),
),
patch(
"backend.pashub_fetcher.pashub_service.save_epc_property_data"
"orchestration.pashub_fetcher_orchestrator.save_epc_property_data"
) as mock_save,
patch("backend.pashub_fetcher.pashub_service.db_session"),
patch("backend.pashub_fetcher.pashub_service.logger") as mock_logger,
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.db_session"),
patch("orchestration.pashub_fetcher_orchestrator.logger") as mock_logger,
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
result = service.run(make_request(uprn="12345"))
@ -764,16 +764,16 @@ def test_run_overlays_full_lodged_performance_onto_saved_site_notes() -> None:
# Act
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3"),
patch(
"backend.pashub_fetcher.pashub_service.parse_site_notes_pdf",
"orchestration.pashub_fetcher_orchestrator.parse_site_notes_pdf",
return_value=parsed,
),
patch(
"backend.pashub_fetcher.pashub_service.save_epc_property_data"
"orchestration.pashub_fetcher_orchestrator.save_epc_property_data"
) as mock_save,
patch("backend.pashub_fetcher.pashub_service.db_session"),
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.db_session"),
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
service.run(make_request(uprn="12345"))
@ -799,16 +799,16 @@ def test_run_overlays_only_present_fields_when_summary_partial() -> None:
# Act
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3"),
patch(
"backend.pashub_fetcher.pashub_service.parse_site_notes_pdf",
"orchestration.pashub_fetcher_orchestrator.parse_site_notes_pdf",
return_value=parsed,
),
patch(
"backend.pashub_fetcher.pashub_service.save_epc_property_data"
"orchestration.pashub_fetcher_orchestrator.save_epc_property_data"
) as mock_save,
patch("backend.pashub_fetcher.pashub_service.db_session"),
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.db_session"),
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
service.run(make_request(uprn="12345"))
@ -828,12 +828,12 @@ def test_run_raises_and_skips_persistence_when_summary_fetch_fails() -> None:
# Act / Assert
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3") as mock_s3,
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3") as mock_s3,
patch(
"backend.pashub_fetcher.pashub_service.save_epc_property_data"
"orchestration.pashub_fetcher_orchestrator.save_epc_property_data"
) as mock_save,
patch("backend.pashub_fetcher.pashub_service.db_session"),
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.db_session"),
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
with pytest.raises(RuntimeError):
service.run(make_request(uprn="12345"))
@ -849,9 +849,9 @@ def test_run_does_not_fetch_summary_for_evidence_only_job() -> None:
# Act
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
patch("backend.pashub_fetcher.pashub_service.db_session"),
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3"),
patch("orchestration.pashub_fetcher_orchestrator.db_session"),
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
service.run(make_request(uprn="12345"))
@ -879,16 +879,16 @@ def test_run_fetches_summary_from_coordination_client_on_primary_auth_failure()
# Act
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3"),
patch(
"backend.pashub_fetcher.pashub_service.parse_site_notes_pdf",
"orchestration.pashub_fetcher_orchestrator.parse_site_notes_pdf",
return_value=parsed,
),
patch(
"backend.pashub_fetcher.pashub_service.save_epc_property_data"
"orchestration.pashub_fetcher_orchestrator.save_epc_property_data"
) as mock_save,
patch("backend.pashub_fetcher.pashub_service.db_session"),
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.db_session"),
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
service.run(make_request(uprn="12345"))
@ -911,9 +911,9 @@ def test_run_uploads_to_sharepoint_even_when_summary_fetch_fails() -> None:
# Act / Assert
with (
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
patch("backend.pashub_fetcher.pashub_service.db_session"),
patch("backend.pashub_fetcher.pashub_service.os.remove"),
patch("orchestration.pashub_fetcher_orchestrator.upload_file_to_s3"),
patch("orchestration.pashub_fetcher_orchestrator.db_session"),
patch("orchestration.pashub_fetcher_orchestrator.os.remove"),
):
with pytest.raises(RuntimeError):
service.run(