mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
add pashub functions to orchestrator tests, and rename existing magicplan ones
This commit is contained in:
parent
9501146ec8
commit
71aadfe78d
1 changed files with 90 additions and 6 deletions
|
|
@ -9,7 +9,9 @@ from etl.hubspot.scripts.scraper.main import handler
|
||||||
DEAL_NAME = "123 Main Street"
|
DEAL_NAME = "123 Main Street"
|
||||||
UPRN = "12345678"
|
UPRN = "12345678"
|
||||||
DEAL_ID = "999"
|
DEAL_ID = "999"
|
||||||
|
PASHUB_LINK = "https://pashub.example.com/deal/999"
|
||||||
MAGICPLAN_QUEUE_URL = "https://sqs.eu-west-2.amazonaws.com/123/magic-plan-dev"
|
MAGICPLAN_QUEUE_URL = "https://sqs.eu-west-2.amazonaws.com/123/magic-plan-dev"
|
||||||
|
PASHUB_QUEUE_URL = "https://sqs.test/pashub"
|
||||||
|
|
||||||
|
|
||||||
def make_hubspot_deal(**kwargs: Any) -> Dict[str, Any]:
|
def make_hubspot_deal(**kwargs: Any) -> Dict[str, Any]:
|
||||||
|
|
@ -52,7 +54,7 @@ def run_handler(
|
||||||
)
|
)
|
||||||
mock_boto3.client.return_value = mock_sqs
|
mock_boto3.client.return_value = mock_sqs
|
||||||
mock_settings.return_value.MAGICPLAN_SQS_URL = MAGICPLAN_QUEUE_URL
|
mock_settings.return_value.MAGICPLAN_SQS_URL = MAGICPLAN_QUEUE_URL
|
||||||
mock_settings.return_value.PASHUB_TO_ARA_SQS_URL = "https://sqs.test/pashub"
|
mock_settings.return_value.PASHUB_TO_ARA_SQS_URL = PASHUB_QUEUE_URL
|
||||||
|
|
||||||
handler.__wrapped__({"hubspot_deal_id": DEAL_ID}, "")
|
handler.__wrapped__({"hubspot_deal_id": DEAL_ID}, "")
|
||||||
|
|
||||||
|
|
@ -64,7 +66,7 @@ def run_handler(
|
||||||
# ====================================
|
# ====================================
|
||||||
|
|
||||||
|
|
||||||
def test_new_deal__outcome_is_surveyed__triggers_magicplan() -> None:
|
def test_new_deal_surveyed__sends_magicplan_sqs() -> None:
|
||||||
# Arrange
|
# Arrange
|
||||||
hubspot_deal = make_hubspot_deal(outcome="surveyed")
|
hubspot_deal = make_hubspot_deal(outcome="surveyed")
|
||||||
listing = {"national_uprn": UPRN}
|
listing = {"national_uprn": UPRN}
|
||||||
|
|
@ -81,7 +83,7 @@ def test_new_deal__outcome_is_surveyed__triggers_magicplan() -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_new_deal__outcome_is_not_surveyed__does_not_trigger_magicplan() -> None:
|
def test_new_deal_not_surveyed__no_magicplan_sqs() -> None:
|
||||||
# Arrange
|
# Arrange
|
||||||
hubspot_deal = make_hubspot_deal(outcome="assessed")
|
hubspot_deal = make_hubspot_deal(outcome="assessed")
|
||||||
|
|
||||||
|
|
@ -92,7 +94,7 @@ def test_new_deal__outcome_is_not_surveyed__does_not_trigger_magicplan() -> None
|
||||||
mock_sqs.send_message.assert_not_called()
|
mock_sqs.send_message.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_new_deal__outcome_is_surveyed__no_listing__magicplan_message_uprn_is_null() -> None:
|
def test_new_deal_surveyed_no_listing__magicplan_sqs_uprn_is_null() -> None:
|
||||||
# Arrange
|
# Arrange
|
||||||
hubspot_deal = make_hubspot_deal(outcome="surveyed")
|
hubspot_deal = make_hubspot_deal(outcome="surveyed")
|
||||||
|
|
||||||
|
|
@ -113,7 +115,7 @@ def test_new_deal__outcome_is_surveyed__no_listing__magicplan_message_uprn_is_nu
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
|
|
||||||
def test_existing_deal__outcome_transitions_to_surveyed__triggers_magicplan() -> None:
|
def test_existing_deal_surveyed_transition__sends_magicplan_sqs() -> None:
|
||||||
# Arrange
|
# Arrange
|
||||||
db_deal = make_db_deal(outcome="assessed")
|
db_deal = make_db_deal(outcome="assessed")
|
||||||
hubspot_deal = make_hubspot_deal(outcome="surveyed")
|
hubspot_deal = make_hubspot_deal(outcome="surveyed")
|
||||||
|
|
@ -131,7 +133,7 @@ def test_existing_deal__outcome_transitions_to_surveyed__triggers_magicplan() ->
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_existing_deal__outcome_already_surveyed__unrelated_change__does_not_trigger_magicplan() -> None:
|
def test_existing_deal_already_surveyed__no_magicplan_sqs() -> None:
|
||||||
# Arrange
|
# Arrange
|
||||||
db_deal = make_db_deal(outcome="surveyed", dealname="Old Name")
|
db_deal = make_db_deal(outcome="surveyed", dealname="Old Name")
|
||||||
hubspot_deal = make_hubspot_deal(outcome="surveyed", dealname="New Name")
|
hubspot_deal = make_hubspot_deal(outcome="surveyed", dealname="New Name")
|
||||||
|
|
@ -141,3 +143,85 @@ def test_existing_deal__outcome_already_surveyed__unrelated_change__does_not_tri
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
mock_sqs.send_message.assert_not_called()
|
mock_sqs.send_message.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
# ====================================
|
||||||
|
# NEW DEAL PATH - PasHub trigger
|
||||||
|
# ====================================
|
||||||
|
|
||||||
|
|
||||||
|
def test_new_deal_with_pashub_link__sends_pashub_sqs() -> None:
|
||||||
|
# Arrange
|
||||||
|
hubspot_deal = make_hubspot_deal(pashub_link=PASHUB_LINK)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
mock_sqs = run_handler(hubspot_deal=hubspot_deal, db_deal=None, listing=None)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
mock_sqs.send_message.assert_called_once_with(
|
||||||
|
QueueUrl=PASHUB_QUEUE_URL,
|
||||||
|
MessageBody=json.dumps(
|
||||||
|
{
|
||||||
|
"pashub_link": PASHUB_LINK,
|
||||||
|
"address": None,
|
||||||
|
"hubspot_deal_id": DEAL_ID,
|
||||||
|
"sharepoint_link": None,
|
||||||
|
"uprn": None,
|
||||||
|
"landlord_property_id": None,
|
||||||
|
"deal_stage": None,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_new_deal_no_pashub_link__no_pashub_sqs() -> None:
|
||||||
|
# Arrange
|
||||||
|
hubspot_deal = make_hubspot_deal()
|
||||||
|
|
||||||
|
# Act
|
||||||
|
mock_sqs = run_handler(hubspot_deal=hubspot_deal, db_deal=None, listing=None)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
mock_sqs.send_message.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
# ==========================================
|
||||||
|
# EXISTING DEAL PATH - PasHub trigger
|
||||||
|
# ==========================================
|
||||||
|
|
||||||
|
|
||||||
|
def test_existing_deal_pashub_link_added__sends_pashub_sqs() -> None:
|
||||||
|
# Arrange
|
||||||
|
db_deal = make_db_deal(pashub_link=None)
|
||||||
|
hubspot_deal = make_hubspot_deal(pashub_link=PASHUB_LINK)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
mock_sqs = run_handler(hubspot_deal=hubspot_deal, db_deal=db_deal, listing=None)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
mock_sqs.send_message.assert_called_once_with(
|
||||||
|
QueueUrl=PASHUB_QUEUE_URL,
|
||||||
|
MessageBody=json.dumps(
|
||||||
|
{
|
||||||
|
"pashub_link": PASHUB_LINK,
|
||||||
|
"address": None,
|
||||||
|
"hubspot_deal_id": DEAL_ID,
|
||||||
|
"sharepoint_link": None,
|
||||||
|
"uprn": None,
|
||||||
|
"landlord_property_id": None,
|
||||||
|
"deal_stage": None,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_existing_deal_pashub_link_unchanged__no_pashub_sqs() -> None:
|
||||||
|
# Arrange
|
||||||
|
db_deal = make_db_deal(pashub_link=PASHUB_LINK, dealname="Old Name")
|
||||||
|
hubspot_deal = make_hubspot_deal(pashub_link=PASHUB_LINK, dealname="New Name")
|
||||||
|
|
||||||
|
# Act
|
||||||
|
mock_sqs = run_handler(hubspot_deal=hubspot_deal, db_deal=db_deal, listing=None)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
mock_sqs.send_message.assert_not_called()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue