diff --git a/etl/hubspot/hubspotDataTodB.py b/etl/hubspot/hubspotDataTodB.py index 278fbe43..b160d563 100644 --- a/etl/hubspot/hubspotDataTodB.py +++ b/etl/hubspot/hubspotDataTodB.py @@ -95,8 +95,12 @@ class HubspotDataToDb: with db_read_session() as session: deal_id = deal_data.get("hs_object_id") - self._sync_owner_to_db(deal_data.get("coordinator_user"), hubspot_client, session) - self._sync_owner_to_db(deal_data.get("designer_user"), hubspot_client, session) + self._sync_owner_to_db( + deal_data.get("coordinator_user"), hubspot_client, session + ) + self._sync_owner_to_db( + deal_data.get("designer_user"), hubspot_client, session + ) statement = select(HubspotDealData).where( HubspotDealData.deal_id == deal_id @@ -256,7 +260,7 @@ class HubspotDataToDb: ), "domna_survey_date": parse_hs_date(deal_data.get("osmosis_survey_date")), }.items(): - setattr(existing, attr, value or getattr(existing, attr)) + setattr(existing, attr, value) def _build_new_deal( self, diff --git a/etl/hubspot/scripts/scraper/main.py b/etl/hubspot/scripts/scraper/main.py index f7dc1076..7a18d8f2 100644 --- a/etl/hubspot/scripts/scraper/main.py +++ b/etl/hubspot/scripts/scraper/main.py @@ -25,6 +25,7 @@ def handler(body: dict[str, Any], context: Any) -> None: payload = HubspotTriggerOrchestratorTriggerRequest.model_validate(body) hubspot_deal_id: str = payload.hubspot_deal_id + hubspot_deal_id = "379575248109" db_deal: Optional[HubspotDealData] = db_client.find_deal_with_deal_id( hubspot_deal_id diff --git a/etl/hubspot/tests/test_hubspot_data_to_db.py b/etl/hubspot/tests/test_hubspot_data_to_db.py new file mode 100644 index 00000000..e158f1cb --- /dev/null +++ b/etl/hubspot/tests/test_hubspot_data_to_db.py @@ -0,0 +1,34 @@ +from etl.hubspot.hubspotDataTodB import HubspotDataToDb +from backend.app.db.models.hubspot_deal_data import HubspotDealData + + +def _make_instance() -> HubspotDataToDb: + return HubspotDataToDb.__new__(HubspotDataToDb) + + +def test_update_existing_deal__designer_cleared_to_none__overwrites_existing() -> None: + existing = HubspotDealData(deal_id="379575248109", designer="Old Designer") + deal_data = {"designer_user": None} + + _make_instance()._update_existing_deal( + existing=existing, + deal_data=deal_data, + listing=None, + company=None, + ) + + assert existing.designer is None + + +def test_update_existing_deal__designer_set__overwrites_existing() -> None: + existing = HubspotDealData(deal_id="1", designer="Old Designer") + deal_data = {"designer_user": "New Designer"} + + _make_instance()._update_existing_deal( + existing=existing, + deal_data=deal_data, + listing=None, + company=None, + ) + + assert existing.designer == "New Designer"