mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-19 08:53:17 +00:00
94 lines
2.4 KiB
Python
94 lines
2.4 KiB
Python
from __future__ import annotations
|
|
|
|
import openpyxl
|
|
import pytest
|
|
|
|
from domain.magicplan.models import (
|
|
Door,
|
|
DoorVentilation,
|
|
Floor,
|
|
Plan,
|
|
Room,
|
|
Window,
|
|
WindowVentilation,
|
|
)
|
|
from domain.magicplan.ventilation_audit import populate_sheet
|
|
|
|
|
|
def _make_window(with_ventilation: bool = True) -> Window:
|
|
vent = (
|
|
WindowVentilation(
|
|
opening_type="Hinged",
|
|
num_openings=1,
|
|
pct_openable=50,
|
|
trickle_vent_area_mm2=1000,
|
|
num_trickle_vents=2,
|
|
)
|
|
if with_ventilation
|
|
else None
|
|
)
|
|
return Window(width_m=1.0, height_m=1.2, area_m2=1.2, ventilation=vent)
|
|
|
|
|
|
def _make_door(with_ventilation: bool = True) -> Door:
|
|
vent = DoorVentilation(undercut_mm=10.0) if with_ventilation else None
|
|
return Door(width_mm=800.0, height_mm=2000.0, ventilation=vent)
|
|
|
|
|
|
def _make_plan(
|
|
num_rooms: int = 1,
|
|
num_windows_per_room: int = 1,
|
|
num_doors_per_room: int = 1,
|
|
) -> Plan:
|
|
rooms = [
|
|
Room(
|
|
name=f"Room {i}",
|
|
width_m=3.0,
|
|
length_m=4.0,
|
|
area_m2=12.0,
|
|
windows=[_make_window() for _ in range(num_windows_per_room)],
|
|
doors=[_make_door() for _ in range(num_doors_per_room)],
|
|
)
|
|
for i in range(num_rooms)
|
|
]
|
|
return Plan(
|
|
uid="test-uid",
|
|
name="Test Plan",
|
|
address="1 Test St",
|
|
postcode="TE1 1ST",
|
|
floors=[Floor(level=0, name="Ground", rooms=rooms)],
|
|
)
|
|
|
|
|
|
def _blank_sheet() -> object:
|
|
return openpyxl.Workbook().active
|
|
|
|
|
|
def test_raises_when_rooms_exceed_50() -> None:
|
|
# Arrange
|
|
plan = _make_plan(num_rooms=51, num_windows_per_room=0, num_doors_per_room=0)
|
|
sheet = _blank_sheet()
|
|
|
|
# Act / Assert
|
|
with pytest.raises(ValueError, match="50"):
|
|
populate_sheet(sheet, plan)
|
|
|
|
|
|
def test_raises_when_windows_exceed_50() -> None:
|
|
# Arrange
|
|
plan = _make_plan(num_rooms=1, num_windows_per_room=51, num_doors_per_room=0)
|
|
sheet = _blank_sheet()
|
|
|
|
# Act / Assert
|
|
with pytest.raises(ValueError, match="50"):
|
|
populate_sheet(sheet, plan)
|
|
|
|
|
|
def test_raises_when_doors_exceed_50() -> None:
|
|
# Arrange
|
|
plan = _make_plan(num_rooms=1, num_windows_per_room=0, num_doors_per_room=51)
|
|
sheet = _blank_sheet()
|
|
|
|
# Act / Assert
|
|
with pytest.raises(ValueError, match="50"):
|
|
populate_sheet(sheet, plan)
|