blocks-transformer/test_block.py

90 lines
3.1 KiB
Python
Raw Normal View History

2026-05-20 13:24:17 -04:00
import json
2025-03-12 16:16:45 +00:00
import unittest
2026-05-20 13:24:17 -04:00
from pathlib import Path
2025-03-12 16:16:45 +00:00
from block import __main__
2026-05-20 13:24:17 -04:00
BASE_DIR = Path(__file__).resolve().parent
data = {
"hd_score_m1": 1173.0,
"hd_score_g1": 1203.0,
"hd_score_s1": 1240.0,
"hd_score_s2": 0,
"hd_score_s3": 0,
"hd_score_iso_m2": 1001.0,
"hd_score_g2": 0.0,
}
def score_data(**overrides):
values = {
"hd_score_m1": 1100.0,
"hd_score_g1": 0.0,
"hd_score_s1": 0.0,
"hd_score_s2": 0.0,
"hd_score_s3": 0.0,
"hd_score_iso_m2": 1001.0,
"hd_score_g2": 0.0,
"hd_score_s4": 0.0,
}
values.update(overrides)
return values
2025-03-12 16:16:45 +00:00
class TestBlock(unittest.TestCase):
def test_main_success(self):
2026-05-20 13:24:17 -04:00
block_result = __main__(**data)
self.assertIsInstance(block_result, dict, "Result should be a dictionary.")
self.assertIn("hd_score", block_result, "Result dictionary should contain 'hd_score' if success.")
def test_s4_sets_review_application_when_no_decline(self):
block_result = __main__(**score_data(hd_score_s4=1191))
self.assertEqual(block_result["hd_score"], 1191)
self.assertEqual(block_result["recommended_action"], "Review Application")
self.assertEqual(block_result["hd_action_reasoncode"], "S4 Velocity Triggered")
self.assertIn("Review Application", block_result["description"])
def test_s4_review_can_use_top_of_reserved_band(self):
block_result = __main__(**score_data(hd_score_s4=1200))
self.assertEqual(block_result["hd_score"], 1200)
self.assertEqual(block_result["recommended_action"], "Review Application")
def test_decline_precedence_beats_s4_review(self):
block_result = __main__(**score_data(hd_score_s1=1225, hd_score_s4=1200))
self.assertEqual(block_result["hd_score"], 1225)
self.assertEqual(block_result["recommended_action"], "Decline Application")
self.assertEqual(block_result["hd_action_reasoncode"], "S1 Triggered")
def test_non_s4_pass_score_in_reserved_band_shifts_down(self):
block_result = __main__(**score_data(hd_score_m1=1195, hd_score_s4=0))
self.assertEqual(block_result["hd_score"], 1185)
self.assertEqual(block_result["recommended_action"], "Pass Application")
self.assertEqual(block_result["hd_action_reasoncode"], "Pass")
def test_non_s4_pass_score_below_reserved_band_stays_same(self):
block_result = __main__(**score_data(hd_score_m1=1190, hd_score_s4=0))
self.assertEqual(block_result["hd_score"], 1190)
self.assertEqual(block_result["recommended_action"], "Pass Application")
def test_request_schema_adds_s4_and_response_schema_is_unchanged(self):
request_schema = json.loads((BASE_DIR / "request_schema.json").read_text())
response_schema = json.loads((BASE_DIR / "response_schema.json").read_text())
2025-03-12 16:16:45 +00:00
2026-05-20 13:24:17 -04:00
self.assertEqual(request_schema["properties"]["hd_score_s4"]["type"], ["number", "null"])
self.assertEqual(
set(response_schema["properties"]),
{"hd_score", "recommended_action", "description", "hd_action_reasoncode"},
)
2025-03-12 16:16:45 +00:00
if __name__ == "__main__":
unittest.main()