mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Coordination Hub fallback stores correct file_source in DB 🟥
This commit is contained in:
parent
b2e896f4eb
commit
dc3543ac5f
2 changed files with 29 additions and 1 deletions
|
|
@ -25,6 +25,7 @@ class FileTypeEnum(enum.Enum):
|
|||
|
||||
class FileSourceEnum(enum.Enum):
|
||||
PAS_HUB = "pas hub"
|
||||
COORDINATION_HUB = "coordination_hub"
|
||||
SHAREPOINT = "sharepoint"
|
||||
HUBSPOT = "hubspot"
|
||||
ECMK = "ecmk"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import pytest
|
||||
from typing import Callable, Optional
|
||||
from typing import Any, Callable, Optional
|
||||
from unittest.mock import MagicMock, call, patch
|
||||
|
||||
|
||||
from backend.app.db.models.uploaded_file import FileSourceEnum
|
||||
from backend.pashub_fetcher.pashub_client import PashubClient, UnauthorizedError
|
||||
from backend.pashub_fetcher.pashub_service import PashubService
|
||||
from backend.pashub_fetcher.pashub_to_ara_trigger_request import (
|
||||
|
|
@ -306,6 +307,32 @@ def test_run_raises_unauthorized_when_both_clients_401() -> None:
|
|||
service.run(make_request())
|
||||
|
||||
|
||||
def test_run_persists_coordination_hub_file_source_when_pas_401_on_uprn_lookup() -> None:
|
||||
pas_client = MagicMock(spec=PashubClient)
|
||||
pas_client.get_uprn_by_job_id.side_effect = UnauthorizedError()
|
||||
|
||||
coord_client = MagicMock(spec=PashubClient)
|
||||
coord_client.get_uprn_by_job_id.return_value = "99999"
|
||||
coord_client.get_core_evidence_files_by_job_id.return_value = ["/tmp/a.pdf"]
|
||||
|
||||
factory = MagicMock(return_value=coord_client)
|
||||
fake_session = MagicMock()
|
||||
|
||||
service = make_service(pashub_client=pas_client, coordination_client_factory=factory)
|
||||
|
||||
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"),
|
||||
):
|
||||
mock_db.return_value.__enter__.return_value = fake_session
|
||||
service.run(make_request())
|
||||
|
||||
fake_session.add_all.assert_called_once()
|
||||
added: list[Any] = fake_session.add_all.call_args[0][0]
|
||||
assert added[0].file_source == FileSourceEnum.COORDINATION_HUB.value
|
||||
|
||||
|
||||
def test_run_warns_and_continues_when_site_notes_parsing_fails() -> None:
|
||||
mock_client = MagicMock(spec=PashubClient)
|
||||
mock_client.get_uprn_by_job_id.return_value = None
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue