mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Other files persisted to DB with file_type OTHER 🟥
This commit is contained in:
parent
ecca84294a
commit
af61c362b2
1 changed files with 37 additions and 1 deletions
|
|
@ -3,7 +3,7 @@ from typing import Any, Callable, Optional
|
|||
from unittest.mock import MagicMock, call, patch
|
||||
|
||||
|
||||
from backend.app.db.models.uploaded_file import FileSourceEnum
|
||||
from backend.app.db.models.uploaded_file import FileSourceEnum, FileTypeEnum
|
||||
from backend.pashub_fetcher.pashub_client import (
|
||||
DownloadedFiles,
|
||||
PashubClient,
|
||||
|
|
@ -434,6 +434,42 @@ def test_run_uploads_other_files_to_s3_when_get_other_files_true() -> None:
|
|||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# run(): get_other_files=True → other files persisted with file_type OTHER
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_run_persists_other_files_with_other_file_type() -> None:
|
||||
# Arrange
|
||||
mock_client = MagicMock(spec=PashubClient)
|
||||
mock_client.get_uprn_by_job_id.return_value = None
|
||||
mock_client.get_evidence_files_by_job_id.return_value = make_downloaded(
|
||||
core=[],
|
||||
other=["/tmp/unknown_file.pdf"],
|
||||
)
|
||||
|
||||
fake_session = MagicMock()
|
||||
service = make_service(pashub_client=mock_client)
|
||||
|
||||
# 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"),
|
||||
):
|
||||
mock_db.return_value.__enter__.return_value = fake_session
|
||||
service.run(make_request(uprn="12345", get_other_files=True))
|
||||
|
||||
# Assert
|
||||
all_added = [
|
||||
item
|
||||
for c in fake_session.add_all.call_args_list
|
||||
for item in c[0][0]
|
||||
]
|
||||
assert len(all_added) == 1
|
||||
assert all_added[0].file_type == FileTypeEnum.OTHER.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