mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-27 23:35:01 +00:00
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:
parent
56534617de
commit
4e291e4184
3 changed files with 69 additions and 0 deletions
19
repositories/condition/property_reference_reader.py
Normal file
19
repositories/condition/property_reference_reader.py
Normal 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]:
|
||||
...
|
||||
18
repositories/condition/property_uprn_lookup.py
Normal file
18
repositories/condition/property_uprn_lookup.py
Normal 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
|
||||
32
tests/condition/lookups/test_property_uprn_lookup.py
Normal file
32
tests/condition/lookups/test_property_uprn_lookup.py
Normal 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}
|
||||
Loading…
Add table
Reference in a new issue