mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
Merge pull request #1500 from Hestia-Homes/feature/abri-api-integration
Abri API integration: temporary project code variable for testing
This commit is contained in:
commit
86e6b83e57
6 changed files with 61 additions and 9 deletions
3
.github/workflows/_deploy_lambda.yml
vendored
3
.github/workflows/_deploy_lambda.yml
vendored
|
|
@ -109,6 +109,8 @@ on:
|
||||||
required: false
|
required: false
|
||||||
TF_VAR_abri_relay_default_resource:
|
TF_VAR_abri_relay_default_resource:
|
||||||
required: false
|
required: false
|
||||||
|
TF_VAR_test_abri_project_code_override:
|
||||||
|
required: false
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
@ -188,6 +190,7 @@ jobs:
|
||||||
TF_VAR_abri_relay_username: ${{ secrets.TF_VAR_abri_relay_username }}
|
TF_VAR_abri_relay_username: ${{ secrets.TF_VAR_abri_relay_username }}
|
||||||
TF_VAR_abri_relay_password: ${{ secrets.TF_VAR_abri_relay_password }}
|
TF_VAR_abri_relay_password: ${{ secrets.TF_VAR_abri_relay_password }}
|
||||||
TF_VAR_abri_relay_default_resource: ${{ secrets.TF_VAR_abri_relay_default_resource }}
|
TF_VAR_abri_relay_default_resource: ${{ secrets.TF_VAR_abri_relay_default_resource }}
|
||||||
|
TF_VAR_test_abri_project_code_override: ${{ secrets.TF_VAR_test_abri_project_code_override }}
|
||||||
run: |
|
run: |
|
||||||
ECR_REPO_URL_VAR=""
|
ECR_REPO_URL_VAR=""
|
||||||
if [[ -n "${{ inputs.ecr_repo }}" ]]; then
|
if [[ -n "${{ inputs.ecr_repo }}" ]]; then
|
||||||
|
|
|
||||||
4
.github/workflows/deploy_terraform.yml
vendored
4
.github/workflows/deploy_terraform.yml
vendored
|
|
@ -837,3 +837,7 @@ jobs:
|
||||||
AWS_ACCESS_KEY_ID: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
|
AWS_ACCESS_KEY_ID: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
|
||||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
|
||||||
AWS_REGION: ${{ secrets.DEV_AWS_REGION }}
|
AWS_REGION: ${{ secrets.DEV_AWS_REGION }}
|
||||||
|
# Temporary Abri end-to-end-test toggle. Unset ⇒ empty ⇒ the differ keeps
|
||||||
|
# the production stock-condition project code. Set this repo secret to a
|
||||||
|
# sandbox deal's project code to test, then delete it.
|
||||||
|
TF_VAR_test_abri_project_code_override: ${{ secrets.TF_VAR_test_abri_project_code_override }}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ data "terraform_remote_state" "shared" {
|
||||||
backend = "s3"
|
backend = "s3"
|
||||||
config = {
|
config = {
|
||||||
bucket = "assessment-model-terraform-state"
|
bucket = "assessment-model-terraform-state"
|
||||||
key = "env:/${var.stage}/terraform.tfstate"
|
key = "env:/${var.stage}/terraform.tfstate"
|
||||||
region = "eu-west-2"
|
region = "eu-west-2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -57,18 +57,20 @@ module "hubspot_deal_etl" {
|
||||||
batch_size = var.batch_size
|
batch_size = var.batch_size
|
||||||
|
|
||||||
environment = {
|
environment = {
|
||||||
STAGE = var.stage
|
STAGE = var.stage
|
||||||
LOG_LEVEL = "info"
|
LOG_LEVEL = "info"
|
||||||
DB_USERNAME = local.db_credentials.db_assessment_model_username
|
DB_USERNAME = local.db_credentials.db_assessment_model_username
|
||||||
DB_PASSWORD = local.db_credentials.db_assessment_model_password
|
DB_PASSWORD = local.db_credentials.db_assessment_model_password
|
||||||
DB_HOST = var.db_host
|
DB_HOST = var.db_host
|
||||||
DB_NAME = var.db_name
|
DB_NAME = var.db_name
|
||||||
DB_PORT = var.db_port
|
DB_PORT = var.db_port
|
||||||
HUBSPOT_API_KEY = var.hubspot_api_key
|
HUBSPOT_API_KEY = var.hubspot_api_key
|
||||||
|
|
||||||
PASHUB_TO_ARA_SQS_URL = data.terraform_remote_state.pashub_to_ara.outputs.pashub_to_ara_queue_url
|
PASHUB_TO_ARA_SQS_URL = data.terraform_remote_state.pashub_to_ara.outputs.pashub_to_ara_queue_url
|
||||||
MAGICPLAN_SQS_URL = data.terraform_remote_state.magic_plan.outputs.magic_plan_queue_url
|
MAGICPLAN_SQS_URL = data.terraform_remote_state.magic_plan.outputs.magic_plan_queue_url
|
||||||
ABRI_SQS_URL = data.terraform_remote_state.abri.outputs.abri_api_queue_url
|
ABRI_SQS_URL = data.terraform_remote_state.abri.outputs.abri_api_queue_url
|
||||||
|
|
||||||
|
TEST_ABRI_PROJECT_CODE_OVERRIDE = var.test_abri_project_code_override
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,4 +52,12 @@ variable "db_name" {
|
||||||
|
|
||||||
variable "db_port" {
|
variable "db_port" {
|
||||||
type = string
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
# Temporary end-to-end-test toggle: overrides the hardcoded Abri stock-condition
|
||||||
|
# project code the deal differ gates on, so a sandbox deal on its own project
|
||||||
|
# code fires the Abri flows. Empty (the default) keeps the production code.
|
||||||
|
variable "test_abri_project_code_override" {
|
||||||
|
type = string
|
||||||
|
default = ""
|
||||||
}
|
}
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
from backend.app.db.models.hubspot_deal_data import HubspotDealData
|
from backend.app.db.models.hubspot_deal_data import HubspotDealData
|
||||||
|
|
@ -344,8 +345,15 @@ class HubspotDealDiffer:
|
||||||
== HubspotDealDiffer.ABRI_CONDITION_ASSOCIATED_PROJECT_ID
|
== HubspotDealDiffer.ABRI_CONDITION_ASSOCIATED_PROJECT_ID
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TEST_ABRI_PROJECT_CODE_OVERRIDE lets a non-production deploy fire on a
|
||||||
|
# sandbox deal's own project code; unset (the production default) falls
|
||||||
|
# back to the real stock-condition code.
|
||||||
|
expected_code = (
|
||||||
|
os.environ.get("TEST_ABRI_PROJECT_CODE_OVERRIDE")
|
||||||
|
or HubspotDealDiffer.ABRI_CONDITION_PROJECT_CODE
|
||||||
|
)
|
||||||
new_project_code = (new_deal.get("project_code") or "").lower()
|
new_project_code = (new_deal.get("project_code") or "").lower()
|
||||||
return new_project_code == HubspotDealDiffer.ABRI_CONDITION_PROJECT_CODE.lower()
|
return new_project_code == expected_code.lower()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _has_valid_pashub_link(new_pashub_link: str) -> bool:
|
def _has_valid_pashub_link(new_pashub_link: str) -> bool:
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ from datetime import datetime, timezone
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from backend.app.db.models.hubspot_deal_data import HubspotDealData
|
from backend.app.db.models.hubspot_deal_data import HubspotDealData
|
||||||
from etl.hubspot.hubspot_deal_differ import HubspotDealDiffer
|
from etl.hubspot.hubspot_deal_differ import HubspotDealDiffer
|
||||||
|
|
||||||
|
|
@ -187,6 +189,31 @@ def test_no_message_for_a_non_abri_deal() -> None:
|
||||||
assert message is None
|
assert message is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_test_override_env_var_fires_a_deal_on_its_own_project_code(
|
||||||
|
monkeypatch: pytest.MonkeyPatch,
|
||||||
|
) -> None:
|
||||||
|
# Arrange: a sandbox deal on its own project code, with the test override
|
||||||
|
# pointing the gate at that code so it fires like a production Abri deal.
|
||||||
|
monkeypatch.setenv("TEST_ABRI_PROJECT_CODE_OVERRIDE", "TEST-SANDBOX-CODE")
|
||||||
|
old_deal = make_old_deal(project_code="TEST-SANDBOX-CODE", confirmed_survey_date=None)
|
||||||
|
new_deal = make_new_deal(
|
||||||
|
project_code="TEST-SANDBOX-CODE", confirmed_survey_date="2026-06-24"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
message = HubspotDealDiffer.check_abri_triggers_and_construct_message(
|
||||||
|
hubspot_deal_id=DEAL_ID,
|
||||||
|
new_deal=new_deal,
|
||||||
|
new_project=None,
|
||||||
|
new_listing=LISTING,
|
||||||
|
old_deal=old_deal,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert message is not None
|
||||||
|
assert message["flows"] == ["log_job"]
|
||||||
|
|
||||||
|
|
||||||
def test_a_deal_crossing_into_abandonment_builds_an_abandon_job_message() -> None:
|
def test_a_deal_crossing_into_abandonment_builds_an_abandon_job_message() -> None:
|
||||||
# Arrange: attempts reach the threshold with a negative outcome, so the
|
# Arrange: attempts reach the threshold with a negative outcome, so the
|
||||||
# deal crosses into the abandoned state and the abandon flow fires.
|
# deal crosses into the abandoned state and the abandon flow fires.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue