mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Cheapest compliant plan selected even when not in the priority list 🟩
This commit is contained in:
parent
b916551921
commit
bfb0d79da6
1 changed files with 53 additions and 47 deletions
|
|
@ -15,67 +15,73 @@ def created_at_datetime() -> datetime:
|
|||
return datetime.now()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def identical_plan_record(created_at_datetime: datetime, default: bool) -> PlanRecord:
|
||||
def make_plan_record(
|
||||
created_at: datetime, default: bool, cost_of_works: float = 500.0
|
||||
) -> PlanRecord:
|
||||
return PlanRecord(
|
||||
property_id=1,
|
||||
portfolio_id=1,
|
||||
created_at=created_at_datetime,
|
||||
created_at=created_at,
|
||||
is_default=default,
|
||||
post_epc_rating=Epc.C,
|
||||
cost_of_works=500.0,
|
||||
cost_of_works=cost_of_works,
|
||||
)
|
||||
|
||||
|
||||
def make_plan_record(created_at_datetime: datetime, default: bool) -> PlanRecord:
|
||||
return PlanRecord(
|
||||
property_id=1,
|
||||
portfolio_id=1,
|
||||
created_at=created_at_datetime,
|
||||
is_default=default,
|
||||
post_epc_rating=Epc.C,
|
||||
cost_of_works=500.0,
|
||||
def make_scenario(name: str, created_at: datetime, is_default: bool) -> Scenario:
|
||||
record = ScenarioRecord(
|
||||
name=name,
|
||||
created_at=created_at,
|
||||
housing_type="",
|
||||
goal=PortfolioGoal.INCREASING_EPC,
|
||||
goal_value="C",
|
||||
trigger_file_path="",
|
||||
multi_plan=False,
|
||||
is_default=is_default,
|
||||
)
|
||||
return Scenario(record=record, id=1 if is_default else 2)
|
||||
|
||||
|
||||
def make_plan(
|
||||
created_at: datetime, default: bool, cost_of_works: float = 500.0, name: str = ""
|
||||
) -> Plan:
|
||||
scenario = make_scenario(name, created_at, default)
|
||||
plan_id = 1 if default else 2
|
||||
return Plan(
|
||||
record=make_plan_record(created_at, default, cost_of_works),
|
||||
scenario=scenario,
|
||||
id=plan_id,
|
||||
)
|
||||
|
||||
|
||||
def test_prioritised_plan_selected(created_at_datetime: datetime) -> None:
|
||||
# arrange
|
||||
epc_c_scenario_record = ScenarioRecord(
|
||||
name="EPC C",
|
||||
created_at=created_at_datetime,
|
||||
housing_type="",
|
||||
goal=PortfolioGoal.INCREASING_EPC,
|
||||
goal_value="C",
|
||||
trigger_file_path="",
|
||||
multi_plan=False,
|
||||
is_default=True,
|
||||
)
|
||||
epc_c_scenario = Scenario(record=epc_c_scenario_record, id=1)
|
||||
epc_c_plan = Plan(
|
||||
record=make_plan_record(created_at_datetime, True),
|
||||
scenario=epc_c_scenario,
|
||||
id=1,
|
||||
)
|
||||
|
||||
minor_works_scenario_record = ScenarioRecord(
|
||||
name="EPC C - Minor Works",
|
||||
created_at=created_at_datetime,
|
||||
housing_type="",
|
||||
goal=PortfolioGoal.INCREASING_EPC,
|
||||
goal_value="C",
|
||||
trigger_file_path="",
|
||||
multi_plan=False,
|
||||
is_default=False,
|
||||
)
|
||||
minor_works_scenario = Scenario(record=minor_works_scenario_record, id=2)
|
||||
minor_works_plan = Plan(
|
||||
record=make_plan_record(created_at_datetime, False),
|
||||
scenario=minor_works_scenario,
|
||||
id=2,
|
||||
)
|
||||
|
||||
epc_c_plan = make_plan(created_at_datetime, True, name="EPC C")
|
||||
minor_works_plan = make_plan(created_at_datetime, False, name="EPC C - Minor Works")
|
||||
plan_priority_order: List[int] = [2, 1]
|
||||
|
||||
expected_default_plan_id = 2
|
||||
|
||||
# act
|
||||
actual_default_plan = choose_cheapest_relevant_plan(
|
||||
plans=[epc_c_plan, minor_works_plan],
|
||||
plan_priority_order=plan_priority_order,
|
||||
)
|
||||
|
||||
# assert
|
||||
assert actual_default_plan.id == expected_default_plan_id
|
||||
|
||||
|
||||
def test_cheapest_plan_returned_if_not_in_priority_list(
|
||||
created_at_datetime: datetime,
|
||||
) -> None:
|
||||
# arrange
|
||||
epc_c_plan = make_plan(
|
||||
created_at_datetime, True, cost_of_works=1000.0, name="EPC C"
|
||||
)
|
||||
minor_works_plan = make_plan(
|
||||
created_at_datetime, False, cost_of_works=100.0, name="EPC C - Minor Works"
|
||||
)
|
||||
plan_priority_order: List[int] = [1, 3]
|
||||
expected_default_plan_id = 2
|
||||
|
||||
# act
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue