import pytest from leads.classify import TIER_ORDER, classify, group_key, norm_display def tier(name): return classify(group_key(norm_display(name).upper())) @pytest.mark.parametrize("name, expected", [ ("Kestrel Bay Holdings LLC", "BUSINESS"), ("Halvard Harbor Holdings, L.L.C.", "BUSINESS"), ("Home Goods USA Inc", "BUSINESS"), ("Bramble Roofing LLC", "TRADE"), ("Meriden Electric Co", "TRADE"), ("Halvard Electric and Power Company", "UTILITY"), ("Northgate Railway", "UTILITY"), ("City of Port Halvard", "GOVERNMENT"), ("Marrowfield Housing Authority", "GOVERNMENT"), ("Ashgrove Industrial Development Authority", "GOVERNMENT"), ("USA", "GOVERNMENT"), ("First Church of Ashgrove", "RELIGIOUS"), ("Linden Ridge Homeowners Association", "HOA"), ("Quillon Family Trust", "TRUST"), ("Selby Truste", "TRUST"), ("Ostrander & Sons", "AMBIGUOUS"), ("J & J Auto Services", "AMBIGUOUS"), ("412 Wren Street", "AMBIGUOUS"), ("Ostrander David G & Ostrander Karla", "INDIVIDUAL"), ("Pellworth Anna M", "INDIVIDUAL"), ]) def test_tiers(name, expected): assert tier(name) == expected @pytest.mark.parametrize("name", ["Trusty Owen P", "Upchurch Ellis R", "Corporan Dale"]) def test_surnames_are_not_caught_by_substring(name): assert tier(name) == "INDIVIDUAL" def test_trust_word_inside_a_company_name_stays_business(): assert tier("Quillon Trustmark Properties LLC") == "BUSINESS" def test_first_match_wins_in_tier_order(): # a church-owned holding company is RELIGIOUS, because RELIGIOUS is checked first assert tier("Grace Church Holdings LLC") == "RELIGIOUS" assert TIER_ORDER.index("RELIGIOUS") < TIER_ORDER.index("BUSINESS") def test_spelling_variants_share_one_group_key(): a = group_key(norm_display("Halvard Harbor Holdings, L.L.C.").upper()) b = group_key(norm_display("HALVARD HARBOR HOLDINGS LLC.").upper()) assert a == b == "HALVARD HARBOR HOLDINGS LLC"