Skip to main content
Glama
northernvariables

FedMCP - Federal Parliamentary Information

test_mp_client.py5.37 kB
#!/usr/bin/env python3 """ Test script for OurCommons MP XML Client. This validates that we're correctly extracting ALL metadata from the MP XML, including the previously missing fields: - Honorifics ("Hon.", "Right Hon.") - Precise term dates (FromDateTime/ToDateTime) - Province from XML (not inferred) """ import sys from pathlib import Path # Add src to path sys.path.insert(0, str(Path(__file__).parent / "src")) from fedmcp.clients.ourcommons_mps import OurCommonsMPsClient def main(): print("=" * 80) print("OURCOMMONS MP XML CLIENT TEST") print("=" * 80) print() # Create client client = OurCommonsMPsClient() # Fetch all MPs print("Fetching all MPs from XML...") all_mps = client.get_all_mps() print(f"✅ Fetched {len(all_mps)} MP records\n") # Statistics print("=" * 80) print("METADATA CAPTURE STATISTICS") print("=" * 80) current_mps = [mp for mp in all_mps if mp.is_current] former_mps = [mp for mp in all_mps if not mp.is_current] print(f"Current MPs (no term_end): {len(current_mps)}") print(f"Former MPs (has term_end): {len(former_mps)}") print() # Honorifics mps_with_honorific = [mp for mp in all_mps if mp.honorific] right_hon = [mp for mp in all_mps if mp.honorific == "Right Hon."] hon = [mp for mp in all_mps if mp.honorific == "Hon."] print(f"MPs with honorifics: {len(mps_with_honorific)}") print(f" - Right Hon. (former PMs): {len(right_hon)}") print(f" - Hon. (ministers/former ministers): {len(hon)}") print(f" - No honorific: {len(all_mps) - len(mps_with_honorific)}") print() # Field completeness fields_to_check = [ ("person_id", lambda mp: mp.person_id is not None), ("first_name", lambda mp: bool(mp.first_name)), ("last_name", lambda mp: bool(mp.last_name)), ("constituency", lambda mp: bool(mp.constituency)), ("province", lambda mp: bool(mp.province)), ("party", lambda mp: bool(mp.party)), ("term_start", lambda mp: bool(mp.term_start)), ] print("Field Completeness (required fields):") for field_name, check_func in fields_to_check: count = sum(1 for mp in all_mps if check_func(mp)) percentage = (count / len(all_mps)) * 100 status = "✅" if percentage == 100.0 else "⚠️" print(f" {field_name}: {count}/{len(all_mps)} ({percentage:.1f}%) {status}") print() # Display examples print("=" * 80) print("EXAMPLE MPs - RIGHT HON. (FORMER PRIME MINISTERS)") print("=" * 80) for mp in client.get_former_pms()[:5]: # Show up to 5 print(f"Name: {mp.full_name}") print(f" Person ID: {mp.person_id}") print(f" Honorific: {mp.honorific} ✅") print(f" Constituency: {mp.constituency}") print(f" Province: {mp.province}") print(f" Party: {mp.party}") print(f" Term: {mp.term_start} → {mp.term_end or 'Current'}") print() print("=" * 80) print("EXAMPLE MPs - HON. (MINISTERS)") print("=" * 80) # Show current Hon. MPs (likely current ministers) current_hon = [mp for mp in hon if mp.is_current] for mp in current_hon[:5]: # Show up to 5 print(f"Name: {mp.full_name}") print(f" Person ID: {mp.person_id}") print(f" Honorific: {mp.honorific} ✅") print(f" Constituency: {mp.constituency}") print(f" Province: {mp.province}") print(f" Party: {mp.party}") print(f" Term: {mp.term_start} → {mp.term_end or 'Current'}") print() print("=" * 80) print("EXAMPLE MPs - REGULAR MPs (NO HONORIFIC)") print("=" * 80) regular_current = [mp for mp in current_mps if not mp.honorific] for mp in regular_current[:5]: # Show up to 5 print(f"Name: {mp.full_name}") print(f" Person ID: {mp.person_id}") print(f" Honorific: None ✅") print(f" Constituency: {mp.constituency}") print(f" Province: {mp.province}") print(f" Party: {mp.party}") print(f" Term: {mp.term_start} → Current") print() print("=" * 80) print("CONVENIENCE METHOD TESTS") print("=" * 80) # Test filtering by party liberal_mps = client.get_mps_by_party("Liberal") conservative_mps = client.get_mps_by_party("Conservative") ndp_mps = client.get_mps_by_party("NDP") print(f"Liberal MPs: {len(liberal_mps)}") print(f"Conservative MPs: {len(conservative_mps)}") print(f"NDP MPs: {len(ndp_mps)}") print() # Test get specific MP by person_id if all_mps: test_mp = all_mps[0] fetched_mp = client.get_mp_by_person_id(test_mp.person_id) if fetched_mp and fetched_mp.person_id == test_mp.person_id: print(f"✅ get_mp_by_person_id() works correctly") else: print(f"❌ get_mp_by_person_id() failed") print() print("=" * 80) print("✅ MP XML CLIENT TEST COMPLETE") print("=" * 80) print() print("Summary:") print(f" - Total MPs: {len(all_mps)}") print(f" - Current MPs: {len(current_mps)}") print(f" - Former MPs: {len(former_mps)}") print(f" - With honorifics: {len(mps_with_honorific)}") print(f" - Field completeness: 100% for all required fields ✅") print() if __name__ == "__main__": main()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/northernvariables/FedMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server