77from political_event_tracking_research .official_event_import import (
88 OfficialRecord ,
99 import_official_events ,
10+ load_official_records ,
1011 normalize_records ,
1112)
1213
@@ -28,6 +29,66 @@ def test_import_official_events_normalizes_to_event_schema(tmp_path: Path) -> No
2829 assert rows [- 2 ]["event_id" ] == "official-issuer-release-demo-issuer-evt3"
2930 assert rows [- 1 ]["event_id" ] == "official-financial-media-demo-media-evt5"
3031 assert rows [- 1 ]["confidence" ] == "low"
32+ assert set (rows [0 ]) == {
33+ "event_id" ,
34+ "event_date" ,
35+ "symbol" ,
36+ "event_type" ,
37+ "direction" ,
38+ "confidence" ,
39+ "source_url" ,
40+ "notes" ,
41+ }
42+
43+
44+ def test_load_official_records_defaults_entity_fields_for_legacy_csv (tmp_path : Path ) -> None :
45+ input_path = tmp_path / "legacy.csv"
46+ input_path .write_text (
47+ "record_id,record_date,symbol,source_type,event_type,direction,source_url,summary\n "
48+ "legacy-1,2026-01-10,EVT1,government_filing,disclosure_buy,bullish,"
49+ "https://www.sec.gov/example/legacy-1,Legacy record.\n " ,
50+ encoding = "utf-8" ,
51+ )
52+
53+ record = load_official_records (input_path )[0 ]
54+
55+ assert record .entity_match_type == "unverified"
56+ assert record .match_evidence == ""
57+ assert record .relationship_type == "unverified"
58+
59+
60+ @pytest .mark .parametrize ("value" , ["issuer" , "direct_beneficiary" , "industry_context" , "unverified" ])
61+ def test_new_entity_fields_accept_allowed_values (tmp_path : Path , value : str ) -> None :
62+ input_path = tmp_path / "entity-fields.csv"
63+ input_path .write_text (
64+ "record_id,record_date,symbol,source_type,event_type,direction,source_url,summary,"
65+ "entity_match_type,match_evidence,relationship_type\n "
66+ "entity-1,2026-01-10,EVT1,government_filing,disclosure_buy,bullish,"
67+ f"https://www.sec.gov/example/entity-1,Entity record.,{ value } ,SEC filing,{ value } \n " ,
68+ encoding = "utf-8" ,
69+ )
70+
71+ rows = normalize_records (load_official_records (input_path ))
72+
73+ assert rows [0 ]["event_id" ] == "official-government-filing-entity-1"
74+
75+
76+ @pytest .mark .parametrize ("field" , ["entity_match_type" , "relationship_type" ])
77+ @pytest .mark .parametrize ("value" , ["" , " " , "not-allowed" ])
78+ def test_new_entity_fields_fail_closed_for_blank_or_invalid_values (tmp_path : Path , field : str , value : str ) -> None :
79+ input_path = tmp_path / f"invalid-{ field } .csv"
80+ entity_match_type = value if field == "entity_match_type" else "issuer"
81+ relationship_type = value if field == "relationship_type" else "issuer"
82+ input_path .write_text (
83+ "record_id,record_date,symbol,source_type,event_type,direction,source_url,summary,"
84+ "entity_match_type,match_evidence,relationship_type\n "
85+ f"entity-1,2026-01-10,EVT1,government_filing,disclosure_buy,bullish,"
86+ f"https://www.sec.gov/example/entity-1,Entity record.,{ entity_match_type } ,SEC filing,{ relationship_type } \n " ,
87+ encoding = "utf-8" ,
88+ )
89+
90+ with pytest .raises (ValueError ):
91+ normalize_records (load_official_records (input_path ))
3192
3293
3394def test_government_records_reject_non_gov_urls () -> None :
0 commit comments