from leads.portfolio import build_portfolios def parcel(city, pid, owner, value, mail="100 Quarry Rd"): return {"city": city, "parcel_id": pid, "owner_name": owner, "total_value": value, "mailing_address": mail, "mailing_city": "Ashgrove", "mailing_state": "ZZ", "mailing_zip": "00000"} PARCELS = [ parcel("ASH", "A-1", "Halvard Harbor Holdings LLC", "400000"), parcel("ASH", "A-2", "HALVARD HARBOR HOLDINGS, L.L.C.", "250000"), parcel("KES", "K-9", "Halvard Harbor Holdings LLC", "1000000"), parcel("KES", "K-9", "Halvard Harbor Holdings LLC", "1000000"), # repeated parcel id parcel("ASH", "A-3", "Pellworth Anna M", "180000"), parcel("KES", "K-4", "Quillon Family Trust", "90000"), parcel("KES", "K-5", "", "50000"), # blank owner ] def test_one_portfolio_per_owner_with_totals(): rows, _ = build_portfolios(PARCELS, city_order=["ASH", "KES"]) top = rows[0] assert top["name"] == "HALVARD HARBOR HOLDINGS LLC" assert top["tier"] == "BUSINESS" assert top["total_parcels"] == 3 assert top["n_cities"] == 2 assert top["cities"] == "ASH:2 KES:1" assert top["total_assessed_value"] == "1650000" assert top["name_variants"] == 2 def test_largest_portfolio_sorts_first(): rows, _ = build_portfolios(PARCELS) counts = [r["total_parcels"] for r in rows] assert counts == sorted(counts, reverse=True) def test_trusts_are_quarantined_not_dropped(): rows, trusts = build_portfolios(PARCELS) assert [r["name"] for r in trusts] == ["QUILLON FAMILY TRUST"] assert all("TRUST" not in r["name"] for r in rows) def test_blank_owner_rows_are_skipped(): rows, trusts = build_portfolios(PARCELS) assert sum(r["total_parcels"] for r in rows + trusts) == 5