From cc682e3e74b87bce5cd0cfe349acbaf5cddf3e38 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Thu, 2 Jul 2026 16:27:05 +0000 Subject: [PATCH] =?UTF-8?q?Abri=20survey=20creation=20trigger=20recognises?= =?UTF-8?q?=20deals=20by=20their=20associated=20Abri=20project=20id=20?= =?UTF-8?q?=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- etl/hubspot/hubspot_deal_differ.py | 12 +++++-- etl/hubspot/tests/test_hubspot_deal_differ.py | 36 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/etl/hubspot/hubspot_deal_differ.py b/etl/hubspot/hubspot_deal_differ.py index 6fbcf3432..2017487a0 100644 --- a/etl/hubspot/hubspot_deal_differ.py +++ b/etl/hubspot/hubspot_deal_differ.py @@ -1,6 +1,7 @@ from typing import Dict, List, Optional from backend.app.db.models.hubspot_deal_data import HubspotDealData +from etl.hubspot.project_data import ProjectData from etl.hubspot.utils import parse_hs_bool, parse_hs_date @@ -12,6 +13,7 @@ class HubspotDealDiffer: ] RETROFIT_DESIGN_COMPLETE = "uploaded" LODGEMENT_COMPLETE: List[str] = ["lodgement complete", "measures lodged"] + ABRI_CONDITION_ASSOCIATED_PROJECT_ID = "123456" ABRI_CONDITION_PROJECT_CODE = "Abri Condition" @staticmethod @@ -173,9 +175,11 @@ class HubspotDealDiffer: @staticmethod def check_for_abri_survey_creation( - new_deal: Dict[str, str], old_deal: HubspotDealData + new_deal: Dict[str, str], + new_project: Optional[ProjectData], + old_deal: HubspotDealData, ) -> bool: - if not HubspotDealDiffer._is_abri_condition_deal(new_deal): + if not HubspotDealDiffer._is_abri_condition_deal(new_deal, new_project): return False if old_deal.confirmed_survey_date is not None: @@ -184,7 +188,9 @@ class HubspotDealDiffer: return parse_hs_date(new_deal.get("confirmed_survey_date")) is not None @staticmethod - def _is_abri_condition_deal(new_deal: Dict[str, str]) -> bool: + def _is_abri_condition_deal( + new_deal: Dict[str, str], new_project: Optional[ProjectData] + ) -> bool: new_project_code = (new_deal.get("project_code") or "").lower() return new_project_code == HubspotDealDiffer.ABRI_CONDITION_PROJECT_CODE.lower() diff --git a/etl/hubspot/tests/test_hubspot_deal_differ.py b/etl/hubspot/tests/test_hubspot_deal_differ.py index a50634dea..ea0c3679f 100644 --- a/etl/hubspot/tests/test_hubspot_deal_differ.py +++ b/etl/hubspot/tests/test_hubspot_deal_differ.py @@ -6,6 +6,7 @@ import pytest from backend.app.db.models.hubspot_deal_data import HubspotDealData from etl.hubspot.hubspot_deal_differ import HubspotDealDiffer +from etl.hubspot.project_data import ProjectData BASE_TIME = datetime(2025, 12, 1, 12, 0, 0) @@ -366,6 +367,7 @@ def test_abri_survey_creation__date_first_set_on_abri_deal__returns_true() -> No # Act result = HubspotDealDiffer.check_for_abri_survey_creation( new_deal=new_deal, + new_project=None, old_deal=old_deal, ) @@ -391,6 +393,7 @@ def test_abri_survey_creation__date_already_set__returns_false() -> None: # Act result = HubspotDealDiffer.check_for_abri_survey_creation( new_deal=new_deal, + new_project=None, old_deal=old_deal, ) @@ -416,6 +419,7 @@ def test_abri_survey_creation__non_abri_project_code__returns_false() -> None: # Act result = HubspotDealDiffer.check_for_abri_survey_creation( new_deal=new_deal, + new_project=None, old_deal=old_deal, ) @@ -441,6 +445,7 @@ def test_abri_survey_creation__project_code_cased_differently__returns_true() -> # Act result = HubspotDealDiffer.check_for_abri_survey_creation( new_deal=new_deal, + new_project=None, old_deal=old_deal, ) @@ -476,6 +481,7 @@ def test_abri_survey_creation__no_parseable_new_date__returns_false( # Act result = HubspotDealDiffer.check_for_abri_survey_creation( new_deal=new_deal, + new_project=None, old_deal=old_deal, ) @@ -483,6 +489,36 @@ def test_abri_survey_creation__no_parseable_new_date__returns_false( assert result is False +def test_abri_survey_creation__associated_abri_project_id__returns_true() -> None: + deal_id = uuid.uuid4() + + # Arrange + old_deal = make_old_deal( + id=deal_id, + project_code="Southern Retrofit", + confirmed_survey_date=None, + ) + new_deal = make_new_deal( + deal_id, + project_code="Southern Retrofit", + confirmed_survey_date="2026-07-15", + ) + new_project = ProjectData( + project_id=HubspotDealDiffer.ABRI_CONDITION_ASSOCIATED_PROJECT_ID, + name="Abri Condition", + ) + + # Act + result = HubspotDealDiffer.check_for_abri_survey_creation( + new_deal=new_deal, + new_project=new_project, + old_deal=old_deal, + ) + + # Assert + assert result is True + + # ======================= # DB UPDATE TRIGGER TESTS # =======================