Files
finn-mcp/tests/test_eiendom_no.py
T
2026-05-16 06:54:17 +00:00

45 lines
1.4 KiB
Python

from finn_eiendom.eiendom_no import (
build_unit_vector,
decode_unit_vector,
parse_eiendom_unit_json,
parse_similar_units_json,
resolve_unit_from_finn_url,
)
from tests.fixtures import (
SAMPLE_EIENDOM_SIMILAR_UNITS_JSON,
SAMPLE_EIENDOM_UNIT_JSON,
)
def test_parse_eiendom_unit_json():
unit = parse_eiendom_unit_json(SAMPLE_EIENDOM_UNIT_JSON["units"][0])
assert unit.unit_code == "c-gxw-xmyum-s2a"
assert unit.address == "Fernerveien 42, 0554 Oslo"
assert unit.estimated_selling_price == 7650000
assert unit.listing_sqm_price == 93500
def test_unit_vector_roundtrip():
unit = parse_eiendom_unit_json(SAMPLE_EIENDOM_UNIT_JSON["units"][0])
vector = build_unit_vector(unit)
decoded = decode_unit_vector(vector)
assert decoded["ptype"] == "APARTMENT"
assert decoded["area"] == 77
assert decoded["price"] == 7200000
assert isinstance(decoded, dict)
assert decoded["lon"] == unit.lng
def test_parse_similar_units_json():
comps = parse_similar_units_json(SAMPLE_EIENDOM_SIMILAR_UNITS_JSON)
assert len(comps) == 2
assert comps[0].unit_code == "c-recent-1"
assert comps[1].selling_price == 7350000
def test_resolve_unit_from_finn_url():
unit_code = resolve_unit_from_finn_url(
"https://www.finn.no/realestate/homes/ad.html?finnkode=462400360"
)
assert unit_code == "462400360"