mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
The deal database gateway records a deal's OpenHousing job_no 🟥
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
903ef62ef7
commit
d33c171494
4 changed files with 70 additions and 0 deletions
0
repositories/hubspot_deals/__init__.py
Normal file
0
repositories/hubspot_deals/__init__.py
Normal file
22
repositories/hubspot_deals/deal_database_postgres_gateway.py
Normal file
22
repositories/hubspot_deals/deal_database_postgres_gateway.py
Normal file
|
|
@ -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
|
||||
0
tests/repositories/hubspot_deals/__init__.py
Normal file
0
tests/repositories/hubspot_deals/__init__.py
Normal file
|
|
@ -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")
|
||||
Loading…
Add table
Reference in a new issue