mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
test mapping second api response round dimensions to 2 decimal places 🟩
This commit is contained in:
parent
c530f014de
commit
079f7e3397
2 changed files with 70 additions and 1 deletions
File diff suppressed because one or more lines are too long
|
|
@ -3,7 +3,6 @@ from pathlib import Path
|
|||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from pytest import approx
|
||||
|
||||
from datatypes.magicplan.api.response import MagicPlan
|
||||
from datatypes.magicplan.domain.mapper import map_plan
|
||||
|
|
@ -11,6 +10,7 @@ from datatypes.magicplan.domain.models import Plan
|
|||
|
||||
FIXTURE_DIR = Path(__file__).parents[4] / "backend" / "magic_plan"
|
||||
PLAN_ID = "a7285ed1-878d-47eb-8aa6-85ef9e187516"
|
||||
PLAN_ID_2 = "9f9889ff-793e-4e9a-a6f0-e22f5b0f5365"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
|
@ -104,3 +104,71 @@ def test_kitchen_has_doors(plan: Plan):
|
|||
def test_door_width_is_float(plan: Plan):
|
||||
door = plan.floors[0].rooms[0].doors[0]
|
||||
assert isinstance(door.width, float)
|
||||
|
||||
|
||||
# --- Fixture 2: magicplan_api_plan_response_example_2.json ---
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def raw_data_2() -> dict[str, Any]:
|
||||
payload = json.loads(
|
||||
(FIXTURE_DIR / "magicplan_api_plan_response_example_2.json").read_text()
|
||||
)
|
||||
return payload["data"]
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def plan2(raw_data_2: dict[str, Any]) -> Plan:
|
||||
return map_plan(MagicPlan.model_validate(raw_data_2))
|
||||
|
||||
|
||||
def test_plan2_uid(plan2: Plan):
|
||||
assert plan2.uid == PLAN_ID_2
|
||||
|
||||
|
||||
def test_plan2_floor_count(plan2: Plan):
|
||||
assert len(plan2.floors) == 3
|
||||
|
||||
|
||||
def test_plan2_first_room_name(plan2: Plan):
|
||||
assert plan2.floors[0].rooms[0].name == "Toilet"
|
||||
|
||||
|
||||
def test_plan2_room_area_rounded_to_2dp(plan2: Plan):
|
||||
room = plan2.floors[0].rooms[0]
|
||||
assert room.area == 0.96
|
||||
|
||||
|
||||
def test_plan2_room_dimensions_parsed_from_string(plan2: Plan):
|
||||
room = plan2.floors[0].rooms[0]
|
||||
assert room.width == pytest.approx(1.12)
|
||||
assert room.length == pytest.approx(0.86)
|
||||
|
||||
|
||||
def test_plan2_room_with_no_windows(plan2: Plan):
|
||||
hall = plan2.floors[0].rooms[1]
|
||||
assert hall.name == "Hall"
|
||||
assert hall.windows == []
|
||||
|
||||
|
||||
def test_plan2_window_dimensions_rounded_to_2dp(plan2: Plan):
|
||||
window = plan2.floors[0].rooms[0].windows[0]
|
||||
assert window.width == 0.39
|
||||
assert window.height == 0.67
|
||||
assert window.area == 0.26
|
||||
|
||||
|
||||
def test_plan2_window_opening_type_casement(plan2: Plan):
|
||||
window = plan2.floors[0].rooms[0].windows[0]
|
||||
assert window.opening_type == "casement"
|
||||
|
||||
|
||||
def test_plan2_window_opening_type_hung(plan2: Plan):
|
||||
bathroom1 = plan2.floors[1].rooms[1]
|
||||
assert bathroom1.name == "Bathroom 1"
|
||||
assert bathroom1.windows[0].opening_type == "hung"
|
||||
|
||||
|
||||
def test_plan2_door_width_rounded_to_2dp(plan2: Plan):
|
||||
door = plan2.floors[0].rooms[0].doors[0]
|
||||
assert door.width == 0.71
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue