blocks-transformer/test_block.py

68 lines
54 KiB
Python
Raw Normal View History

2025-03-12 16:12:18 +00:00
import unittest
2025-11-23 23:22:32 -05:00
2025-03-12 16:12:18 +00:00
from block import __main__
2025-11-23 23:22:32 -05:00
# First row from UAT-Data-Aug2025-Mid-Hashed-Filtered.csv
2025-03-12 16:12:18 +00:00
input_json = {
2025-11-23 23:22:32 -05:00
"application_key": "4228646A-17A0-4FD6-B42E-14FAB4DFEFEB",
"application_timestamp": "2025-08-07 17:17:28.563 UTC",
"application_ssn": "7aaab71d9a569704e3f7b56748796287a16e473813801612d4755d7e0c7a6069",
"application_email_address": "6624a576b892148be68c738f6ae40d603a26e3df0255c852dc80db99426cea91",
"application_bank_account_number": "372062fbf78fdc10c05934feb695f98501c4737c98bbc5c3b5854ddd026f39fd",
"application_is_rejected": 'false',
"application_date_of_birth": "1956-05-24",
"EventType": "account_creation",
"RiskRating": "low",
"TmxSummaryReasonCode": "Level_1_Link_Accept",
"DigitalIdConfidence": 7975.0,
"TrueIpGeo": "US",
"Blob": "{\"account_address_city\":\"cresskill\",\"account_address_state\":\"nj\",\"account_address_street1\":\"26 hillside ave\",\"account_address_zip\":\"07626\",\"account_date_of_birth\":\"19560524\",\"account_email\":\"judithsarsten@gmail.com\",\"account_email_activities\":[\"_WATCH\"],\"account_email_attributes\":[\"CONSUMER\",\"_WATCH\"],\"account_email_domain\":\"gmail.com\",\"account_email_first_seen\":\"2024-07-05\",\"account_email_last_event\":\"2025-08-07\",\"account_email_last_update\":\"2025-08-07\",\"account_email_result\":\"success\",\"account_email_score\":\"0\",\"account_email_worst_score\":\"0\",\"account_first_name\":\"paul\",\"account_last_name\":\"sarsten\",\"account_login\":\"judithsarsten@gmail.com\",\"account_login_first_seen\":\"2025-01-01\",\"account_login_last_event\":\"2025-08-07\",\"account_login_last_update\":\"2025-08-07\",\"account_login_result\":\"success\",\"account_login_score\":\"0\",\"account_login_worst_score\":\"0\",\"account_name\":\"paul_sarsten\",\"account_name_attributes\":[\"_CHALLENGED\",\"_CHALLENGE_PASSED\",\"_TRUSTED_CONF\"],\"account_name_first_seen\":\"2022-02-08\",\"account_name_last_event\":\"2025-08-07\",\"account_name_last_update\":\"2025-08-07\",\"account_name_result\":\"success\",\"account_name_score\":\"0\",\"account_name_worst_score\":\"0\",\"account_telephone\":\"7277442639\",\"account_telephone_attributes\":[\"_AUTH_PASSED\",\"_CHALLENGED\",\"_CHALLENGE_PASSED\",\"_TRUSTED_CONF\"],\"account_telephone_country_code\":\"1\",\"account_telephone_first_seen\":\"2016-07-23\",\"account_telephone_geo\":\"US\",\"account_telephone_is_possible\":\"yes\",\"account_telephone_is_valid\":\"yes\",\"account_telephone_last_event\":\"2025-08-07\",\"account_telephone_last_update\":\"2025-08-07\",\"account_telephone_result\":\"success\",\"account_telephone_score\":\"0\",\"account_telephone_type\":\"FIXED_LINE_OR_MOBILE\",\"account_telephone_worst_score\":\"0\",\"agent_publickey_hash\":\"124b5040c6ee972232c98449376bbd627a3c3965\",\"agent_publickey_hash_first_seen\":\"2025-06-10\",\"agent_publickey_hash_last_event\":\"2025-08-07\",\"agent_publickey_hash_last_update\":\"2025-08-07\",\"agent_publickey_hash_result\":\"success\",\"agent_publickey_hash_score\":\"0\",\"agent_publickey_hash_type\":\"web:ecdsa\",\"agent_publickey_hash_worst_score\":\"0\",\"agent_type\":\"browser_mobile\",\"api_call_datetime\":\"2025-08-07 22:17:26.588\",\"api_caller_ip\":\"52.89.158.201\",\"api_caller_ip_geo\":\"US\",\"api_type\":\"session-query\",\"api_version\":\"16.3.1\",\"audio_context\":\"c8c2968991f681c34564385a81232b4bc23c46e18ac5657aa5b36958dddb5b3d\",\"bb_assessment\":\"478.51\",\"bb_assessment_rating\":\"neutral\",\"bb_bot_rating\":\"low\",\"bb_bot_score\":\"500.00\",\"bb_fraud_rating\":\"neutral\",\"bb_fraud_score\":\"500.00\",\"behaviosec.confidence\":\"0.0000\",\"behaviosec.data_integrity_reasons\":[\"metadata_summary_missing\",\"missing_header_data\"],\"behaviosec.event_weight\":\"0.00\",\"behaviosec.pointing_device\":[\"touchscreen\"],\"behaviosec.population_profile.raw_features\":{\"targets\":{\"IFRAME#a-ir5xhw5uc1q9\":{\"foc2b\":2198}},\"tActive\":5857,\"accRes\":0,\"mouseRes\":500,\"actRes\":985.51,\"tAction\":5688,\"winFoc\":1,\"keyRes\":0},\"behaviosec.reasons\":[\"new_subprofile\"],\"behaviosec.recognition_ratio\":\"0.0000\",\"behaviosec.remote_access_description_codes\":[\"test_unavailable\"],\"behaviosec.score\":\"500.0000\",\"behaviosec.userid\":\"judithsarsten@gmail.com\",\"browser\":\"Safari\",\"browser_language\":\"en-US,en;q=0.9\",\"browser_string\":\"Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Mobile/15E148 Safari/604.1\",\"browser_string_hash\":\"d52b74bd7763d5be6124f6a92cffe00a\",\"browser_version\":\"18.5\",\"browser_version_detailed\":\"18.5\",\"canvas_hash\":\"88f9b4c9d9b841ec7f86644d55948acfdc1223b7\",\"challenger_policy\":\"FraudScoreCardModel\",\"challenger_policy_score\":\"-76\",\"challenger_reason_code\":[\"HabemcoFraudScore_76\",\"HabemcoFraudScore_75\",\"HabemcoFraudScore_74\",\"HabemcoFraudSc
"DeviceId": "687405088933de20256860cc92dfece41d3923ff593468a4946a8ff44c83157a",
"FuzzyDeviceId": "687405088933de20256860cc92dfece41d3923ff593468a4946a8ff44c83157a",
"ownhome": None,
"employmentstatus": "Retired benefits",
"lengthatjob": 24.0,
"payfrequency": "Bi-Weekly",
"lengthatbank": None,
"educationlevel": None,
"monthsatresidence": None,
"state": "NJ",
"zip": 7626.0,
"ReasonCode": "--- BehavioSec reasons ---, BehavioSec user profile not yet trained, BehavioSec new subplofile, Data integrity: metadata summary missing, --- BehavioSec anomaly detection ---, --- Persona rules ---, Typing detected, Behaviosec Policy, TMX Policy, Email Agt GT 3Months (Global), 5 Emails per Input IP/DY (Global), 5 Emails per True IP/DY (Global), Multiple Emails per Device/IP, SmartID Age GT 3Months (Global), Device/IP Tagged Risky 10x/90Days, 5x SmartID per DigitalID Month (Global), TrueIP InputIP Mismatch, OS Anomaly, Screen Res Anomaly, Transparent Proxy, Proxy True IP Region Mismatch, Acc Address IP State Mismatch, Email InputIP 500mi/hr (Global), DID 5 NAO/WK (Global), TMX : Pass, Emailage Policy, Emailage, Very Low Risk Band (Fraud Score 1 to 100), Low Risk/Phone Owner Match, Emailage : Pass, Overall Decision, Pass"
}
2025-03-12 16:12:18 +00:00
class TestBlock(unittest.TestCase):
2025-11-23 23:22:32 -05:00
def test_main_matches_uat_first_row(self):
result = __main__(**input_json)
self.assertIsInstance(result, dict)
for key in [
"application_key",
"application_timestamp",
"deviceid",
"fuzzydeviceid",
"application_email_address",
"action",
"digital_id_first_seen",
"summary_risk_score",
"cpu_clock",
"account_login_first_seen",
"account_telephone_first_seen",
"true_ip_first_seen",
"ssn_hash_first_seen",
"account_email_attributes",
"tps_ip_latitude",
"tps_ip_longitude",
"hd_score_iso_m2"
]:
self.assertIn(key, result)
# self.assertAlmostEqual(float(result["hd_score_m1"]), 1145.0, delta=1.0)
# self.assertAlmostEqual(float(result["hd_score_m2"]), 1182.0, delta=1.0)
# self.assertAlmostEqual(float(result["hd_score_iso_m2"]), 1061.0, delta=1.0)
# THX payload is flattened; no nested thx dict should remain
2025-03-12 16:12:18 +00:00
if __name__ == "__main__":
unittest.main()