mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-22 08:48:38 +00:00
Replace the CARDED placeholder in abandon_reason_for_outcome with the real outcome-to-code table from the client: No Answer->CARDED, Tenant Refusal->CRA (ambiguous, client follow-up pending), Not Viable->NOACCESS. Only these three outcomes trip the abandonment trigger today; any empty/unrecognised outcome raises UnmappableOutcomeError since abandon_reason is mandatory. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
from datetime import date
|
|
from typing import Optional
|
|
|
|
import pytest
|
|
|
|
from domain.abri.abandonment import (
|
|
UnmappableOutcomeError,
|
|
abandon_reason_for_outcome,
|
|
abandonment_date,
|
|
)
|
|
from domain.abri.models import AbandonReason
|
|
|
|
CONFIRMED = date(2026, 6, 24)
|
|
SUBMITTED = date(2026, 7, 1)
|
|
|
|
|
|
def test_the_confirmed_survey_date_dates_the_abandonment() -> None:
|
|
assert abandonment_date(CONFIRMED, SUBMITTED) == CONFIRMED
|
|
|
|
|
|
def test_the_last_submission_date_stands_in_without_a_confirmed_survey_date() -> None:
|
|
assert abandonment_date(None, SUBMITTED) == SUBMITTED
|
|
|
|
|
|
def test_neither_date_leaves_the_abandonment_undated() -> None:
|
|
assert abandonment_date(None, None) is None
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("outcome", "expected"),
|
|
[
|
|
("No Answer", AbandonReason.CARDED),
|
|
("NO ANSWER", AbandonReason.CARDED),
|
|
(" no answer ", AbandonReason.CARDED),
|
|
("Tenant Refusal", AbandonReason.CRA),
|
|
(" tenant refusal ", AbandonReason.CRA),
|
|
("Not Viable", AbandonReason.NOACCESS),
|
|
("not viable", AbandonReason.NOACCESS),
|
|
],
|
|
)
|
|
def test_a_triggering_outcome_maps_to_its_reason_code(
|
|
outcome: str, expected: AbandonReason
|
|
) -> None:
|
|
assert abandon_reason_for_outcome(outcome) == expected
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"outcome",
|
|
[None, "", " ", "surveyed", "epc completed", "not attempted", "cancelled / no show"],
|
|
)
|
|
def test_an_unmappable_outcome_raises(outcome: Optional[str]) -> None:
|
|
with pytest.raises(UnmappableOutcomeError):
|
|
abandon_reason_for_outcome(outcome)
|