Resolve landlord references to UPRNs, excluding unresolved rows 🟥

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-13 15:03:55 +00:00
parent 56534617de
commit 4e291e4184
3 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,19 @@
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import List, Optional
@dataclass(frozen=True)
class PropertyReference:
"""A property's landlord reference and resolved UPRN, as held in the
``property`` table. ``uprn`` is nullable a property whose UPRN has not been
resolved yet cannot receive condition rows."""
landlord_property_id: Optional[str]
uprn: Optional[int]
class PropertyReferenceReader(ABC):
@abstractmethod
def references_for_portfolio(self, portfolio_id: int) -> List[PropertyReference]:
...

View file

@ -0,0 +1,18 @@
from typing import Dict
from repositories.condition.property_reference_reader import PropertyReferenceReader
from repositories.condition.uprn_lookup import UprnLookup
class PropertyUprnLookup(UprnLookup):
"""Resolves a landlord property reference to a UPRN from the ``property``
table, scoped to one portfolio (ADR-0064)."""
def __init__(
self, reader: PropertyReferenceReader, portfolio_id: int
) -> None:
self._reader = reader
self._portfolio_id = portfolio_id
def get_property_ref_to_uprn_lookup(self) -> Dict[str, int]:
raise NotImplementedError

View file

@ -0,0 +1,32 @@
from typing import List
from repositories.condition.property_reference_reader import (
PropertyReference,
PropertyReferenceReader,
)
from repositories.condition.property_uprn_lookup import PropertyUprnLookup
class FakePropertyReferenceReader(PropertyReferenceReader):
def __init__(self, references: List[PropertyReference]) -> None:
self._references = references
def references_for_portfolio(self, portfolio_id: int) -> List[PropertyReference]:
return self._references
def test_property_uprn_lookup_excludes_rows_with_no_uprn():
# Arrange
reader = FakePropertyReferenceReader(
[
PropertyReference(landlord_property_id="443", uprn=100093305101),
PropertyReference(landlord_property_id="999", uprn=None),
]
)
lookup = PropertyUprnLookup(reader, portfolio_id=824)
# Act
mapping = lookup.get_property_ref_to_uprn_lookup()
# Assert
assert mapping == {"443": 100093305101}