mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-27 23:35:01 +00:00
Parse a Calico workbook and drop rows with no covering type 🟥
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
61a12c43a0
commit
7308979825
2 changed files with 76 additions and 0 deletions
13
infrastructure/condition/parsing/calico_parser.py
Normal file
13
infrastructure/condition/parsing/calico_parser.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from typing import BinaryIO, List
|
||||
|
||||
from domain.condition.records.calico.calico_property import CalicoProperty
|
||||
from infrastructure.condition.parsing.parser import Parser
|
||||
from repositories.condition.uprn_lookup import UprnLookup
|
||||
|
||||
|
||||
class CalicoParser(Parser):
|
||||
def __init__(self, uprn_lookup: UprnLookup) -> None:
|
||||
self._uprn_lookup = uprn_lookup
|
||||
|
||||
def parse(self, file_stream: BinaryIO) -> List[CalicoProperty]:
|
||||
raise NotImplementedError
|
||||
63
tests/condition/parsing/test_calico_parser.py
Normal file
63
tests/condition/parsing/test_calico_parser.py
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
from datetime import date
|
||||
from io import BytesIO
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from openpyxl import Workbook
|
||||
|
||||
from infrastructure.condition.parsing.calico_parser import CalicoParser
|
||||
from repositories.condition.uprn_lookup import UprnLookup
|
||||
|
||||
HEADERS = [
|
||||
"Asset Reference",
|
||||
"Asset Type",
|
||||
"Address",
|
||||
"Path",
|
||||
"Type",
|
||||
"Fitted / Renewed Date",
|
||||
"Quantity",
|
||||
"Remaining Life",
|
||||
]
|
||||
|
||||
|
||||
class FakeUprnLookup(UprnLookup):
|
||||
def __init__(self, mapping: Dict[str, int]) -> None:
|
||||
self._mapping = mapping
|
||||
|
||||
def get_property_ref_to_uprn_lookup(self) -> Dict[str, int]:
|
||||
return self._mapping
|
||||
|
||||
|
||||
def _workbook(rows: List[List[object]]) -> BytesIO:
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
assert ws is not None
|
||||
ws.append(HEADERS)
|
||||
for row in rows:
|
||||
ws.append(row)
|
||||
buffer = BytesIO()
|
||||
wb.save(buffer)
|
||||
buffer.seek(0)
|
||||
return buffer
|
||||
|
||||
|
||||
def test_calico_parser_drops_rows_with_no_covering_type():
|
||||
# Arrange
|
||||
workbook = _workbook(
|
||||
[
|
||||
[443, "HOUSE", "31 Venice Avenue", "Roof Covering", "Concrete Tiles",
|
||||
date(1998, 4, 1), 55, 36],
|
||||
[438, "FLAT", "137 Brownhill Avenue", "Roof Covering", None,
|
||||
date(2000, 4, 1), 0, 973],
|
||||
]
|
||||
)
|
||||
parser = CalicoParser(FakeUprnLookup({"443": 100093305101, "438": 100093388053}))
|
||||
|
||||
# Act
|
||||
properties = parser.parse(workbook)
|
||||
|
||||
# Assert
|
||||
all_assets = [asset for prop in properties for asset in prop.assets]
|
||||
references: List[int] = [asset.asset_reference for asset in all_assets]
|
||||
coverings: List[Optional[str]] = [asset.covering_type for asset in all_assets]
|
||||
assert references == [443]
|
||||
assert coverings == ["Concrete Tiles"]
|
||||
Loading…
Add table
Reference in a new issue