From d33c171494bccb3d113099021775dc60a380ca65 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Tue, 7 Jul 2026 09:53:42 +0000 Subject: [PATCH] =?UTF-8?q?The=20deal=20database=20gateway=20records=20a?= =?UTF-8?q?=20deal's=20OpenHousing=20job=5Fno=20=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 --- repositories/hubspot_deals/__init__.py | 0 .../deal_database_postgres_gateway.py | 22 +++++++++ tests/repositories/hubspot_deals/__init__.py | 0 .../test_deal_database_postgres_gateway.py | 48 +++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 repositories/hubspot_deals/__init__.py create mode 100644 repositories/hubspot_deals/deal_database_postgres_gateway.py create mode 100644 tests/repositories/hubspot_deals/__init__.py create mode 100644 tests/repositories/hubspot_deals/test_deal_database_postgres_gateway.py diff --git a/repositories/hubspot_deals/__init__.py b/repositories/hubspot_deals/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/repositories/hubspot_deals/deal_database_postgres_gateway.py b/repositories/hubspot_deals/deal_database_postgres_gateway.py new file mode 100644 index 000000000..56accf947 --- /dev/null +++ b/repositories/hubspot_deals/deal_database_postgres_gateway.py @@ -0,0 +1,22 @@ +"""Postgres implementation of the Abri deal-database gateway. + +First production implementation of the DealDatabaseGateway protocol used by +the AbriOrchestrator (orchestration/abri_orchestrator.py): job numbers live +on the hubspot_deal_data table, in the job_no column the scraper also +upserts from HubSpot's client_booking_reference property. +""" + +from typing import Optional + +from sqlmodel import Session + + +class DealDatabasePostgresGateway: + def __init__(self, session: Session) -> None: + self._session = session + + def record_job_no(self, deal_id: str, job_no: str) -> None: + raise NotImplementedError + + def job_no_for_deal(self, deal_id: str) -> Optional[str]: + raise NotImplementedError diff --git a/tests/repositories/hubspot_deals/__init__.py b/tests/repositories/hubspot_deals/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/repositories/hubspot_deals/test_deal_database_postgres_gateway.py b/tests/repositories/hubspot_deals/test_deal_database_postgres_gateway.py new file mode 100644 index 000000000..9e6e0c9a2 --- /dev/null +++ b/tests/repositories/hubspot_deals/test_deal_database_postgres_gateway.py @@ -0,0 +1,48 @@ +from collections.abc import Iterator + +import pytest +from sqlalchemy import Engine +from sqlmodel import Session + +from backend.app.db.models.hubspot_deal_data import HubspotDealData +from repositories.hubspot_deals.deal_database_postgres_gateway import ( + DealDatabasePostgresGateway, +) + +DEAL_ID = "9876543210" + + +@pytest.fixture +def session(db_engine: Engine) -> Iterator[Session]: + with Session(db_engine) as s: + yield s + + +def _insert_deal(session: Session, deal_id: str) -> HubspotDealData: + deal = HubspotDealData(deal_id=deal_id, dealname="49 Admers Crescent") + session.add(deal) + session.commit() + session.refresh(deal) + return deal + + +def test_record_job_no_persists_the_job_no_on_the_deal_row(session: Session) -> None: + # Arrange + deal = _insert_deal(session, DEAL_ID) + gateway = DealDatabasePostgresGateway(session=session) + + # Act + gateway.record_job_no(deal_id=DEAL_ID, job_no="AD0226519") + + # Assert + session.refresh(deal) + assert deal.job_no == "AD0226519" + + +def test_record_job_no_for_an_unknown_deal_raises(session: Session) -> None: + # Arrange + gateway = DealDatabasePostgresGateway(session=session) + + # Act / Assert + with pytest.raises(ValueError): + gateway.record_job_no(deal_id="0000000000", job_no="AD0226519")