mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
fix orchestration tests
This commit is contained in:
parent
1b673622e2
commit
648e726ca2
1 changed files with 22 additions and 18 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import json
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from typing import Any, Optional
|
||||
from unittest.mock import ANY, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
|
@ -75,24 +75,28 @@ def _make_request(
|
|||
)
|
||||
|
||||
|
||||
def _patch_db() -> tuple[patch, patch, patch]: # type: ignore[type-arg]
|
||||
def _patch_db() -> tuple[Any, Any, Any]:
|
||||
return (
|
||||
patch("orchestration.magic_plan_orchestrator.PostgresConfig"),
|
||||
patch("orchestration.magic_plan_orchestrator.make_engine"),
|
||||
patch("orchestration.magic_plan_orchestrator.make_session"),
|
||||
patch("orchestration.magic_plan_orchestrator.transactional_session"),
|
||||
)
|
||||
|
||||
|
||||
# --- no match ---
|
||||
|
||||
|
||||
def test_run_raises_when_no_plan_found(mock_client: MagicMock) -> None:
|
||||
def test_run_returns_none_when_no_plan_found(mock_client: MagicMock) -> None:
|
||||
# Arrange
|
||||
mock_client.get_plans.return_value.plans = []
|
||||
mock_client.get_plans.return_value = []
|
||||
service = _make_service(mock_client)
|
||||
# Act / Assert
|
||||
with pytest.raises(ValueError, match="No MagicPlan found"):
|
||||
service.run(_make_request(address="99 Nowhere Road London SW1A 1AA"))
|
||||
with patch(
|
||||
"orchestration.magic_plan_orchestrator.find_matching_plan",
|
||||
return_value=None,
|
||||
):
|
||||
result = service.run(_make_request(address="99 Nowhere Road London SW1A 1AA"))
|
||||
assert result is None
|
||||
|
||||
|
||||
# --- match found ---
|
||||
|
|
@ -258,8 +262,8 @@ def test_run_creates_uploaded_file_record(
|
|||
return_value=plan_summary,
|
||||
), patch(
|
||||
"orchestration.magic_plan_orchestrator.MagicPlanPostgresRepository"
|
||||
), p_config, p_engine, p_session as mock_make_session:
|
||||
mock_make_session.return_value = mock_session
|
||||
), p_config, p_engine, p_session as mock_transactional_session:
|
||||
mock_transactional_session.return_value.__enter__.return_value = mock_session
|
||||
# Act
|
||||
service.run(request)
|
||||
# Assert
|
||||
|
|
@ -268,16 +272,16 @@ def test_run_creates_uploaded_file_record(
|
|||
(obj for obj in added_objects if isinstance(obj, UploadedFile)), None
|
||||
)
|
||||
assert uploaded_file is not None
|
||||
assert uploaded_file.file_source == FileSourceEnum.MAGIC_PLAN.value
|
||||
assert uploaded_file.file_type == FileTypeEnum.MAGIC_PLAN_JSON.value
|
||||
assert uploaded_file.s3_file_bucket == S3_BUCKET
|
||||
assert FileSourceEnum.MAGIC_PLAN.value == uploaded_file.file_source
|
||||
assert FileTypeEnum.MAGIC_PLAN_JSON.value == uploaded_file.file_type
|
||||
assert S3_BUCKET == uploaded_file.s3_file_bucket
|
||||
assert (
|
||||
uploaded_file.s3_file_key
|
||||
== f"documents/uprn/100023336956/magic_plan_{plan_summary.id}.json.gz"
|
||||
f"documents/uprn/100023336956/magic_plan_{plan_summary.id}.json.gz"
|
||||
== uploaded_file.s3_file_key
|
||||
)
|
||||
assert uploaded_file.s3_upload_timestamp is not None
|
||||
assert uploaded_file.uprn == 100023336956
|
||||
assert uploaded_file.hubspot_deal_id == "deal-789"
|
||||
assert 100023336956 == uploaded_file.uprn
|
||||
assert "deal-789" == uploaded_file.hubspot_deal_id
|
||||
|
||||
|
||||
def test_run_passes_flushed_uploaded_file_id_to_save(
|
||||
|
|
@ -307,8 +311,8 @@ def test_run_passes_flushed_uploaded_file_id_to_save(
|
|||
), patch(
|
||||
"orchestration.magic_plan_orchestrator.MagicPlanPostgresRepository",
|
||||
return_value=mock_repo,
|
||||
), p_config, p_engine, p_session as mock_make_session:
|
||||
mock_make_session.return_value = mock_session
|
||||
), p_config, p_engine, p_session as mock_transactional_session:
|
||||
mock_transactional_session.return_value.__enter__.return_value = mock_session
|
||||
# Act
|
||||
service.run(_make_request())
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue