mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
Resolve a property's display address from its landlord_property_id 🟥
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
79fa46d97c
commit
456d4dffe7
2 changed files with 65 additions and 0 deletions
30
repositories/property/landlord_address_resolver.py
Normal file
30
repositories/property/landlord_address_resolver.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
"""Resolves a property's display address from its `landlord_property_id`
|
||||
(ADR-0060), for naming the folders in a Download Package.
|
||||
|
||||
The address lives on the FE-owned `property` table (`uploaded_files` carries no
|
||||
`property_id` — a known future gap). Addresses for the whole requested set are
|
||||
loaded once at construction; `address_for` is then a lookup with a safe
|
||||
fallback for a `landlord_property_id` that has no property row or address.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Sequence
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlmodel import Session, col
|
||||
|
||||
from infrastructure.postgres.property_table import PropertyRow
|
||||
|
||||
|
||||
class LandlordAddressResolver:
|
||||
_FALLBACK = "address unavailable"
|
||||
|
||||
def __init__(
|
||||
self, session: Session, landlord_property_ids: Sequence[str]
|
||||
) -> None:
|
||||
self._session = session
|
||||
self._ids = list(landlord_property_ids)
|
||||
|
||||
def address_for(self, landlord_property_id: str) -> str:
|
||||
raise NotImplementedError
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
from collections.abc import Iterator
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import Engine
|
||||
from sqlmodel import Session
|
||||
|
||||
from infrastructure.postgres.property_table import PropertyRow
|
||||
from repositories.property.landlord_address_resolver import LandlordAddressResolver
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def session(db_engine: Engine) -> Iterator[Session]:
|
||||
with Session(db_engine) as s:
|
||||
yield s
|
||||
|
||||
|
||||
def test_resolves_known_addresses_and_falls_back_for_unknowns(
|
||||
session: Session,
|
||||
) -> None:
|
||||
# arrange — two properties with addresses; a third id has no property row.
|
||||
session.add(
|
||||
PropertyRow(portfolio_id=1, landlord_property_id="LP1", address="12 Oak Street")
|
||||
)
|
||||
session.add(
|
||||
PropertyRow(portfolio_id=1, landlord_property_id="LP2", address="9 Elm Road")
|
||||
)
|
||||
session.flush()
|
||||
|
||||
# act
|
||||
resolver = LandlordAddressResolver(session, ["LP1", "LP2", "LP3"])
|
||||
|
||||
# assert
|
||||
assert resolver.address_for("LP1") == "12 Oak Street"
|
||||
assert resolver.address_for("LP2") == "9 Elm Road"
|
||||
assert resolver.address_for("LP3") == "address unavailable"
|
||||
Loading…
Add table
Reference in a new issue