mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
rename mcs_certificate to mcs_compliance_certificate to match existing db enum value
This commit is contained in:
parent
36f50c3bef
commit
19e40ff049
5 changed files with 87 additions and 40 deletions
|
|
@ -21,7 +21,7 @@ class FileTypeEnum(enum.Enum):
|
|||
IMPROVEMENT_OPTION_EVALUATION = "improvement_option_evaluation"
|
||||
MEDIUM_TERM_IMPROVEMENT_PLAN = "medium_term_improvement_plan"
|
||||
RETROFIT_DESIGN_DOC = "retrofit_design_doc"
|
||||
MCS_CERTIFICATE = "mcs_certificate"
|
||||
MCS_COMPLIANCE_CERTIFICATE = "mcs_compliance_certificate"
|
||||
OTHER = "other"
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class CoreFiles(Enum):
|
|||
IMPROVEMENT_OPTION_EVALUATION = "Improvement Option Evaluation"
|
||||
MEDIUM_TERM_IMPROVEMENT_PLAN = "Medium Term Improvement Plan"
|
||||
RETROFIT_DESIGN_DOC = "Retrofit Design Doc"
|
||||
MCS_CERTIFICATE = "MCS Certificate"
|
||||
MCS_COMPLIANCE_CERTIFICATE = "MCS Compliance Certificate"
|
||||
|
||||
|
||||
_CORE_FILE_TO_FILE_TYPE: dict[CoreFiles, str] = {
|
||||
|
|
@ -33,7 +33,7 @@ _CORE_FILE_TO_FILE_TYPE: dict[CoreFiles, str] = {
|
|||
CoreFiles.IMPROVEMENT_OPTION_EVALUATION: FileTypeEnum.IMPROVEMENT_OPTION_EVALUATION.value,
|
||||
CoreFiles.MEDIUM_TERM_IMPROVEMENT_PLAN: FileTypeEnum.MEDIUM_TERM_IMPROVEMENT_PLAN.value,
|
||||
CoreFiles.RETROFIT_DESIGN_DOC: FileTypeEnum.RETROFIT_DESIGN_DOC.value,
|
||||
CoreFiles.MCS_CERTIFICATE: FileTypeEnum.MCS_CERTIFICATE.value,
|
||||
CoreFiles.MCS_COMPLIANCE_CERTIFICATE: FileTypeEnum.MCS_COMPLIANCE_CERTIFICATE.value,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ def get_core_file_type(
|
|||
evidence_category is not None
|
||||
and evidence_category.lower() == "mcs compliance certificate"
|
||||
):
|
||||
return CoreFiles.MCS_CERTIFICATE
|
||||
return CoreFiles.MCS_COMPLIANCE_CERTIFICATE
|
||||
|
||||
if evidence_category is not None and evidence_category.lower() == "retrofit design":
|
||||
return CoreFiles.RETROFIT_DESIGN_DOC
|
||||
|
|
@ -64,7 +64,7 @@ def get_core_file_type(
|
|||
CoreFiles.RETROFIT_DESIGN_DOC,
|
||||
CoreFiles.IMPROVEMENT_OPTION_EVALUATION,
|
||||
CoreFiles.MEDIUM_TERM_IMPROVEMENT_PLAN,
|
||||
CoreFiles.MCS_CERTIFICATE,
|
||||
CoreFiles.MCS_COMPLIANCE_CERTIFICATE,
|
||||
}
|
||||
|
||||
for core_file in CoreFiles:
|
||||
|
|
|
|||
|
|
@ -185,15 +185,17 @@ def test_core_file_for_osm_fallback_does_not_fire_when_evidence_category_present
|
|||
assert result is None
|
||||
|
||||
|
||||
def test_core_file_for_mcs_compliance_certificate_returns_mcs_certificate() -> None:
|
||||
def test_core_file_for_mcs_compliance_certificate_returns_mcs_compliance_certificate() -> None:
|
||||
# Arrange
|
||||
filename = "MCS_cert_job123.pdf"
|
||||
|
||||
# Act
|
||||
result = get_core_file_type(filename, evidence_category="mcs compliance certificate")
|
||||
result = get_core_file_type(
|
||||
filename, evidence_category="mcs compliance certificate"
|
||||
)
|
||||
|
||||
# Assert
|
||||
assert result == CoreFiles.MCS_CERTIFICATE
|
||||
assert result == CoreFiles.MCS_COMPLIANCE_CERTIFICATE
|
||||
|
||||
|
||||
def test_core_file_for_mcs_compliance_certificate_is_case_insensitive() -> None:
|
||||
|
|
@ -201,18 +203,24 @@ def test_core_file_for_mcs_compliance_certificate_is_case_insensitive() -> None:
|
|||
filename = "some_cert.pdf"
|
||||
|
||||
# Act
|
||||
result = get_core_file_type(filename, evidence_category="MCS Compliance Certificate")
|
||||
result = get_core_file_type(
|
||||
filename, evidence_category="MCS Compliance Certificate"
|
||||
)
|
||||
|
||||
# Assert
|
||||
assert result == CoreFiles.MCS_CERTIFICATE
|
||||
assert result == CoreFiles.MCS_COMPLIANCE_CERTIFICATE
|
||||
|
||||
|
||||
def test_get_file_type_string_with_mcs_evidence_category_returns_mcs_certificate() -> None:
|
||||
def test_get_file_type_string_with_mcs_evidence_category_returns_mcs_compliance_certificate() -> (
|
||||
None
|
||||
):
|
||||
# Arrange
|
||||
filename = "some_cert.pdf"
|
||||
|
||||
# Act
|
||||
result = get_file_type_string(filename, evidence_category="MCS Compliance Certificate")
|
||||
result = get_file_type_string(
|
||||
filename, evidence_category="MCS Compliance Certificate"
|
||||
)
|
||||
|
||||
# Assert
|
||||
assert result == "mcs_certificate"
|
||||
assert result == "mcs_compliance_certificate"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,11 @@ from unittest.mock import patch
|
|||
from backend.pashub_fetcher.core_files import CoreFiles
|
||||
from backend.pashub_fetcher.evidence_file_data import EvidenceFileData
|
||||
from backend.pashub_fetcher.evidence_metadata import EvidenceMetadata
|
||||
from backend.pashub_fetcher.pashub_client import DownloadedFile, DownloadedFiles, PashubClient
|
||||
from backend.pashub_fetcher.pashub_client import (
|
||||
DownloadedFile,
|
||||
DownloadedFiles,
|
||||
PashubClient,
|
||||
)
|
||||
|
||||
|
||||
def make_metadata() -> EvidenceMetadata:
|
||||
|
|
@ -70,7 +74,10 @@ def test_group_into_core_and_other_files_returns_single_retrofit_design_doc() ->
|
|||
result = client._group_into_core_and_other_files(files)
|
||||
|
||||
# Assert
|
||||
assert result.core[CoreFiles.RETROFIT_DESIGN_DOC].file_name == "2512-OSM-H21M900-XX-DR-N-A_Lord Nelson Street 018.pdf"
|
||||
assert (
|
||||
result.core[CoreFiles.RETROFIT_DESIGN_DOC].file_name
|
||||
== "2512-OSM-H21M900-XX-DR-N-A_Lord Nelson Street 018.pdf"
|
||||
)
|
||||
|
||||
|
||||
def test_group_into_core_and_other_files_osm_candidate_wins_over_non_osm() -> None:
|
||||
|
|
@ -93,10 +100,15 @@ def test_group_into_core_and_other_files_osm_candidate_wins_over_non_osm() -> No
|
|||
result = client._group_into_core_and_other_files(files)
|
||||
|
||||
# Assert
|
||||
assert result.core[CoreFiles.RETROFIT_DESIGN_DOC].file_name == "2512-OSM-H21M900-XX-DR-N-A_Lord Nelson Street 018.pdf"
|
||||
assert (
|
||||
result.core[CoreFiles.RETROFIT_DESIGN_DOC].file_name
|
||||
== "2512-OSM-H21M900-XX-DR-N-A_Lord Nelson Street 018.pdf"
|
||||
)
|
||||
|
||||
|
||||
def test_group_into_core_and_other_files_picks_latest_when_both_candidates_have_osm() -> None:
|
||||
def test_group_into_core_and_other_files_picks_latest_when_both_candidates_have_osm() -> (
|
||||
None
|
||||
):
|
||||
# Arrange
|
||||
client = make_client()
|
||||
files = [
|
||||
|
|
@ -116,7 +128,10 @@ def test_group_into_core_and_other_files_picks_latest_when_both_candidates_have_
|
|||
result = client._group_into_core_and_other_files(files)
|
||||
|
||||
# Assert
|
||||
assert result.core[CoreFiles.RETROFIT_DESIGN_DOC].file_name == "2603-OSM-B06M901-XX-DR-N-A_Alvaston Walk 022.pdf"
|
||||
assert (
|
||||
result.core[CoreFiles.RETROFIT_DESIGN_DOC].file_name
|
||||
== "2603-OSM-B06M901-XX-DR-N-A_Alvaston Walk 022.pdf"
|
||||
)
|
||||
|
||||
|
||||
def test_group_into_core_and_other_files_classifies_mcs_cert_as_core() -> None:
|
||||
|
|
@ -133,7 +148,7 @@ def test_group_into_core_and_other_files_classifies_mcs_cert_as_core() -> None:
|
|||
result = client._group_into_core_and_other_files(files)
|
||||
|
||||
# Assert
|
||||
assert CoreFiles.MCS_CERTIFICATE in result.core
|
||||
assert CoreFiles.MCS_COMPLIANCE_CERTIFICATE in result.core
|
||||
assert result.other == []
|
||||
|
||||
|
||||
|
|
@ -157,10 +172,15 @@ def test_group_into_core_and_other_files_picks_most_recent_mcs_cert() -> None:
|
|||
result = client._group_into_core_and_other_files(files)
|
||||
|
||||
# Assert
|
||||
assert result.core[CoreFiles.MCS_CERTIFICATE].file_name == "mcs_cert_new.pdf"
|
||||
assert (
|
||||
result.core[CoreFiles.MCS_COMPLIANCE_CERTIFICATE].file_name
|
||||
== "mcs_cert_new.pdf"
|
||||
)
|
||||
|
||||
|
||||
def test_group_into_core_and_other_files_falls_back_to_latest_when_no_osm_candidates() -> None:
|
||||
def test_group_into_core_and_other_files_falls_back_to_latest_when_no_osm_candidates() -> (
|
||||
None
|
||||
):
|
||||
# Arrange
|
||||
client = make_client()
|
||||
files = [
|
||||
|
|
@ -180,7 +200,9 @@ def test_group_into_core_and_other_files_falls_back_to_latest_when_no_osm_candid
|
|||
result = client._group_into_core_and_other_files(files)
|
||||
|
||||
# Assert
|
||||
assert result.core[CoreFiles.RETROFIT_DESIGN_DOC].file_name == "retrofit_design_v2.pdf"
|
||||
assert (
|
||||
result.core[CoreFiles.RETROFIT_DESIGN_DOC].file_name == "retrofit_design_v2.pdf"
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
@ -188,7 +210,9 @@ def test_group_into_core_and_other_files_falls_back_to_latest_when_no_osm_candid
|
|||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_get_evidence_files_by_job_id_returns_downloaded_files_with_empty_other_when_include_other_false() -> None:
|
||||
def test_get_evidence_files_by_job_id_returns_downloaded_files_with_empty_other_when_include_other_false() -> (
|
||||
None
|
||||
):
|
||||
# Arrange
|
||||
client = make_client()
|
||||
files = [
|
||||
|
|
@ -233,7 +257,9 @@ def test_get_evidence_files_by_job_id_core_files_carry_evidence_category() -> No
|
|||
assert result.core[0].evidence_category == "MCS Compliance Certificate"
|
||||
|
||||
|
||||
def test_get_evidence_files_by_job_id_downloads_other_files_when_include_other_true() -> None:
|
||||
def test_get_evidence_files_by_job_id_downloads_other_files_when_include_other_true() -> (
|
||||
None
|
||||
):
|
||||
# Arrange
|
||||
client = make_client()
|
||||
files = [
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ from backend.pashub_fetcher.pashub_to_ara_trigger_request import (
|
|||
)
|
||||
from utils.sharepoint.domna_sharepoint_client import DomnaSharepointClient
|
||||
|
||||
|
||||
FAKE_JOB_LINK = "https://pashub.net/jobs/job-id-123/details"
|
||||
|
||||
|
||||
|
|
@ -291,7 +290,9 @@ def test_run_uses_coordination_client_when_pas_401_on_uprn_lookup() -> None:
|
|||
|
||||
factory = MagicMock(return_value=coord_client)
|
||||
|
||||
service = make_service(pashub_client=pas_client, coordination_client_factory=factory)
|
||||
service = make_service(
|
||||
pashub_client=pas_client, coordination_client_factory=factory
|
||||
)
|
||||
|
||||
with (
|
||||
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
|
||||
|
|
@ -317,7 +318,9 @@ def test_run_uses_coordination_client_when_pas_401_on_file_listing() -> None:
|
|||
|
||||
factory = MagicMock(return_value=coord_client)
|
||||
|
||||
service = make_service(pashub_client=pas_client, coordination_client_factory=factory)
|
||||
service = make_service(
|
||||
pashub_client=pas_client, coordination_client_factory=factory
|
||||
)
|
||||
|
||||
with (
|
||||
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
|
||||
|
|
@ -350,13 +353,17 @@ def test_run_raises_unauthorized_when_both_clients_401() -> None:
|
|||
|
||||
factory = MagicMock(return_value=coord_client)
|
||||
|
||||
service = make_service(pashub_client=pas_client, coordination_client_factory=factory)
|
||||
service = make_service(
|
||||
pashub_client=pas_client, coordination_client_factory=factory
|
||||
)
|
||||
|
||||
with pytest.raises(UnauthorizedError):
|
||||
service.run(make_request())
|
||||
|
||||
|
||||
def test_run_persists_coordination_hub_file_source_when_pas_401_on_uprn_lookup() -> None:
|
||||
def test_run_persists_coordination_hub_file_source_when_pas_401_on_uprn_lookup() -> (
|
||||
None
|
||||
):
|
||||
pas_client = MagicMock(spec=PashubClient)
|
||||
pas_client.get_uprn_by_job_id.side_effect = UnauthorizedError()
|
||||
|
||||
|
|
@ -369,7 +376,9 @@ def test_run_persists_coordination_hub_file_source_when_pas_401_on_uprn_lookup()
|
|||
factory = MagicMock(return_value=coord_client)
|
||||
fake_session = MagicMock()
|
||||
|
||||
service = make_service(pashub_client=pas_client, coordination_client_factory=factory)
|
||||
service = make_service(
|
||||
pashub_client=pas_client, coordination_client_factory=factory
|
||||
)
|
||||
|
||||
with (
|
||||
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
|
||||
|
|
@ -384,7 +393,9 @@ def test_run_persists_coordination_hub_file_source_when_pas_401_on_uprn_lookup()
|
|||
assert added[0].file_source == FileSourceEnum.COORDINATION_HUB.value
|
||||
|
||||
|
||||
def test_run_persists_coordination_hub_file_source_when_pas_401_on_file_listing() -> None:
|
||||
def test_run_persists_coordination_hub_file_source_when_pas_401_on_file_listing() -> (
|
||||
None
|
||||
):
|
||||
pas_client = MagicMock(spec=PashubClient)
|
||||
pas_client.get_evidence_files_by_job_id.side_effect = UnauthorizedError()
|
||||
|
||||
|
|
@ -396,7 +407,9 @@ def test_run_persists_coordination_hub_file_source_when_pas_401_on_file_listing(
|
|||
factory = MagicMock(return_value=coord_client)
|
||||
fake_session = MagicMock()
|
||||
|
||||
service = make_service(pashub_client=pas_client, coordination_client_factory=factory)
|
||||
service = make_service(
|
||||
pashub_client=pas_client, coordination_client_factory=factory
|
||||
)
|
||||
|
||||
with (
|
||||
patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"),
|
||||
|
|
@ -495,21 +508,21 @@ def test_run_persists_other_files_with_other_file_type() -> None:
|
|||
service.run(make_request(uprn="12345", get_other_files=True))
|
||||
|
||||
# Assert
|
||||
all_added = [
|
||||
item
|
||||
for c in fake_session.add_all.call_args_list
|
||||
for item in c[0][0]
|
||||
]
|
||||
all_added = [item for c in fake_session.add_all.call_args_list for item in c[0][0]]
|
||||
assert len(all_added) == 1
|
||||
assert all_added[0].file_type == FileTypeEnum.OTHER.value
|
||||
|
||||
|
||||
def test_run_persists_mcs_cert_with_mcs_certificate_file_type() -> None:
|
||||
def test_run_persists_mcs_cert_with_mcs_compliance_certificate_file_type() -> None:
|
||||
# Arrange
|
||||
mock_client = MagicMock(spec=PashubClient)
|
||||
mock_client.get_uprn_by_job_id.return_value = None
|
||||
mock_client.get_evidence_files_by_job_id.return_value = DownloadedFiles(
|
||||
core=[DownloadedFile("/tmp/MCS_cert.pdf", "MCS Compliance Certificate", datetime(2024, 1, 1))],
|
||||
core=[
|
||||
DownloadedFile(
|
||||
"/tmp/MCS_cert.pdf", "MCS Compliance Certificate", datetime(2024, 1, 1)
|
||||
)
|
||||
],
|
||||
other=[],
|
||||
)
|
||||
|
||||
|
|
@ -528,7 +541,7 @@ def test_run_persists_mcs_cert_with_mcs_certificate_file_type() -> None:
|
|||
# Assert
|
||||
fake_session.add_all.assert_called_once()
|
||||
added: list[Any] = fake_session.add_all.call_args[0][0]
|
||||
assert added[0].file_type == FileTypeEnum.MCS_CERTIFICATE.value
|
||||
assert added[0].file_type == FileTypeEnum.MCS_COMPLIANCE_CERTIFICATE.value
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue