mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Add hubspot_deal_id required field to MagicPlanTriggerRequest 🟩
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
74b3a7f297
commit
4a9cabe197
4 changed files with 11 additions and 8 deletions
|
|
@ -28,7 +28,7 @@ if __name__ == "__main__":
|
|||
event = {
|
||||
"Records": [
|
||||
{
|
||||
"body": '{"address": "2 Laburnum Way Bromley BR2 8BZ"}',
|
||||
"body": '{"address": "2 Laburnum Way Bromley BR2 8BZ", "hubspot_deal_id": "local-test-deal"}',
|
||||
"messageId": "local-test",
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -7,4 +7,5 @@ class MagicPlanTriggerRequest(BaseModel):
|
|||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
address: str
|
||||
hubspot_deal_id: str
|
||||
uprn: Optional[str] = None
|
||||
|
|
|
|||
|
|
@ -6,17 +6,18 @@ from backend.magic_plan.magic_plan_trigger_request import MagicPlanTriggerReques
|
|||
|
||||
def test_valid_payload_with_address_only() -> None:
|
||||
# Arrange
|
||||
payload = {"address": "123 High St London SW1A 1AA"}
|
||||
payload = {"address": "123 High St London SW1A 1AA", "hubspot_deal_id": "123456789"}
|
||||
# Act
|
||||
req = MagicPlanTriggerRequest.model_validate(payload)
|
||||
# Assert
|
||||
assert req.address == "123 High St London SW1A 1AA"
|
||||
assert req.hubspot_deal_id == "123456789"
|
||||
assert req.uprn is None
|
||||
|
||||
|
||||
def test_valid_payload_with_uprn() -> None:
|
||||
# Arrange
|
||||
payload = {"address": "123 High St London SW1A 1AA", "uprn": "100023336956"}
|
||||
payload = {"address": "123 High St London SW1A 1AA", "hubspot_deal_id": "123456789", "uprn": "100023336956"}
|
||||
# Act
|
||||
req = MagicPlanTriggerRequest.model_validate(payload)
|
||||
# Assert
|
||||
|
|
@ -25,7 +26,7 @@ def test_valid_payload_with_uprn() -> None:
|
|||
|
||||
def test_missing_address_raises() -> None:
|
||||
# Arrange
|
||||
payload = {"uprn": "100023336956"}
|
||||
payload = {"hubspot_deal_id": "123456789", "uprn": "100023336956"}
|
||||
# Act / Assert
|
||||
with pytest.raises(ValidationError):
|
||||
MagicPlanTriggerRequest.model_validate(payload)
|
||||
|
|
@ -33,7 +34,7 @@ def test_missing_address_raises() -> None:
|
|||
|
||||
def test_extra_fields_ignored() -> None:
|
||||
# Arrange
|
||||
payload = {"address": "123 High St London SW1A 1AA", "unknown_field": "whatever"}
|
||||
payload = {"address": "123 High St London SW1A 1AA", "hubspot_deal_id": "123456789", "unknown_field": "whatever"}
|
||||
# Act
|
||||
req = MagicPlanTriggerRequest.model_validate(payload)
|
||||
# Assert
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ def handler(body: dict[str, Any], context: Any) -> None:
|
|||
logger.info(
|
||||
f"Triggering MagicPlan fetcher for HubSpot deal ID {hubspot_deal_id}"
|
||||
)
|
||||
_trigger_magicplan_fetcher(sqs_client, hubspot_deal, listing)
|
||||
_trigger_magicplan_fetcher(sqs_client, hubspot_deal, listing, hubspot_deal_id)
|
||||
else:
|
||||
# Deal already in db, check whether anything has changed
|
||||
logger.info(
|
||||
|
|
@ -110,16 +110,17 @@ def handler(body: dict[str, Any], context: Any) -> None:
|
|||
logger.info(
|
||||
f"Triggering MagicPlan fetcher for HubSpot deal ID {hubspot_deal_id}"
|
||||
)
|
||||
_trigger_magicplan_fetcher(sqs_client, hubspot_deal, listing)
|
||||
_trigger_magicplan_fetcher(sqs_client, hubspot_deal, listing, hubspot_deal_id)
|
||||
|
||||
print("done")
|
||||
|
||||
|
||||
def _trigger_magicplan_fetcher(
|
||||
sqs_client: Any, hubspot_deal: Dict[str, str], listing: Optional[dict[str, str]]
|
||||
sqs_client: Any, hubspot_deal: Dict[str, str], listing: Optional[dict[str, str]], hubspot_deal_id: str
|
||||
) -> None:
|
||||
message_body = {
|
||||
"address": hubspot_deal.get("dealname"),
|
||||
"hubspot_deal_id": hubspot_deal_id,
|
||||
"uprn": listing.get("national_uprn") if listing else None,
|
||||
}
|
||||
response = sqs_client.send_message(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue