diff --git a/backend/pashub_fetcher/handler/requirements.txt b/backend/pashub_fetcher/handler/requirements.txt index ba235c7f..17d80d90 100644 --- a/backend/pashub_fetcher/handler/requirements.txt +++ b/backend/pashub_fetcher/handler/requirements.txt @@ -11,3 +11,4 @@ pytz boto3==1.35.44 pandas==2.2.2 numpy<2.0 +pymupdf diff --git a/backend/pashub_fetcher/local_handler/invoke_local_lambda.py b/backend/pashub_fetcher/local_handler/invoke_local_lambda.py index 5248a874..90381a0c 100644 --- a/backend/pashub_fetcher/local_handler/invoke_local_lambda.py +++ b/backend/pashub_fetcher/local_handler/invoke_local_lambda.py @@ -14,7 +14,7 @@ payload = { { "pashub_link": "https://google.co.uk", "uprn": "123456", - "hubspot_deal_id": "498926855369", + "hubspot_deal_id": "1", } ) } 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/tests/test_hubspot_data_to_db.py b/etl/hubspot/tests/test_hubspot_data_to_db.py new file mode 100644 index 00000000..339e0377 --- /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="MOCK_DEAL_ID", 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="MOCK_DEAL_ID", 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"