mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import pytest
|
|
|
|
from backend.magic_plan.models import parse_displayable_fields
|
|
|
|
|
|
SECTION_TITLE_FIELD = {
|
|
"id": "measures.section.title",
|
|
"type_as_string": "sectionTitle",
|
|
"value": {"has_value": False, "value": ""},
|
|
}
|
|
|
|
CEILING_HEIGHT_FIELD = {
|
|
"id": "ceilingHeight",
|
|
"type_as_string": "distance",
|
|
"value": {"has_value": True, "value": "2.45"},
|
|
}
|
|
|
|
NO_VALUE_FIELD = {
|
|
"id": "label",
|
|
"type_as_string": "text",
|
|
"value": {"has_value": False, "value": ""},
|
|
}
|
|
|
|
|
|
class TestParseDisplayableFields:
|
|
|
|
def test_excludes_section_titles(self) -> None:
|
|
result = parse_displayable_fields([SECTION_TITLE_FIELD])
|
|
assert result == {}
|
|
|
|
def test_excludes_fields_without_value(self) -> None:
|
|
result = parse_displayable_fields([NO_VALUE_FIELD])
|
|
assert result == {}
|
|
|
|
def test_includes_field_with_value(self) -> None:
|
|
result = parse_displayable_fields([CEILING_HEIGHT_FIELD])
|
|
assert "ceiling_height" in result
|
|
assert result["ceiling_height"] == "2.45"
|
|
|
|
def test_snake_cases_camel_key(self) -> None:
|
|
result = parse_displayable_fields([CEILING_HEIGHT_FIELD])
|
|
assert "ceiling_height" in result
|
|
assert "ceilingHeight" not in result
|
|
|
|
def test_mixed_fields(self) -> None:
|
|
result = parse_displayable_fields([SECTION_TITLE_FIELD, CEILING_HEIGHT_FIELD, NO_VALUE_FIELD])
|
|
assert result == {"ceiling_height": "2.45"}
|
|
|
|
def test_empty_list(self) -> None:
|
|
assert parse_displayable_fields([]) == {}
|