mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-27 23:35:01 +00:00
Map PasHub RdSAP Summary response to as-surveyed performance values 🟥
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3dd86f296d
commit
85482cdf9e
2 changed files with 56 additions and 2 deletions
|
|
@ -29,6 +29,12 @@ class DownloadedFiles(NamedTuple):
|
|||
other: List[DownloadedFile]
|
||||
|
||||
|
||||
class RdSapSummary(NamedTuple):
|
||||
pre_sap_rating: Optional[float]
|
||||
pre_current_co2_emissions: Optional[float]
|
||||
pre_current_energy_consumption: Optional[float]
|
||||
|
||||
|
||||
class UnauthorizedError(Exception):
|
||||
pass
|
||||
|
||||
|
|
@ -126,6 +132,9 @@ class PashubClient:
|
|||
)
|
||||
return None
|
||||
|
||||
def get_rdsap_summary_by_job_id(self, job_id: str) -> RdSapSummary:
|
||||
raise NotImplementedError
|
||||
|
||||
def _group_into_core_and_other_files(
|
||||
self,
|
||||
files: List[EvidenceFileData],
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
# pyright: reportPrivateUsage=false
|
||||
from typing import Optional
|
||||
from unittest.mock import patch
|
||||
from typing import Any, Optional
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from backend.pashub_fetcher.core_files import CoreFiles
|
||||
from backend.pashub_fetcher.evidence_file_data import EvidenceFileData
|
||||
|
|
@ -9,6 +12,8 @@ from backend.pashub_fetcher.pashub_client import (
|
|||
DownloadedFile,
|
||||
DownloadedFiles,
|
||||
PashubClient,
|
||||
RdSapSummary,
|
||||
UnauthorizedError,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -278,3 +283,43 @@ def test_get_evidence_files_by_job_id_downloads_other_files_when_include_other_t
|
|||
# Assert
|
||||
assert [df.file_path for df in result.core] == ["/tmp/SiteNote_001.pdf"]
|
||||
assert [df.file_path for df in result.other] == ["/tmp/unknown_doc.pdf"]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# get_rdsap_summary_by_job_id
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def make_response(
|
||||
status_code: int = 200,
|
||||
payload: Optional[dict[str, Any]] = None,
|
||||
raise_on_status: Optional[Exception] = None,
|
||||
) -> MagicMock:
|
||||
response = MagicMock()
|
||||
response.status_code = status_code
|
||||
response.json.return_value = payload if payload is not None else {}
|
||||
if raise_on_status is not None:
|
||||
response.raise_for_status.side_effect = raise_on_status
|
||||
return response
|
||||
|
||||
|
||||
def test_get_rdsap_summary_maps_pre_performance_fields() -> None:
|
||||
# Arrange
|
||||
client = make_client()
|
||||
payload = {
|
||||
"preSapRating": 78.00,
|
||||
"preSapBand": 50,
|
||||
"preCurrentEnergyConsumption": 117.00,
|
||||
"preCurrentCo2Emissions": 1.70,
|
||||
}
|
||||
|
||||
# Act
|
||||
client.session.get = MagicMock(return_value=make_response(payload=payload))
|
||||
result = client.get_rdsap_summary_by_job_id("job-1")
|
||||
|
||||
# Assert
|
||||
assert result == RdSapSummary(
|
||||
pre_sap_rating=78.00,
|
||||
pre_current_co2_emissions=1.70,
|
||||
pre_current_energy_consumption=117.00,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue