Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/geocodio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,20 @@ def _parse_fields(self, fields_data: dict | None) -> GeocodioFields | None:

school_districts = None
if "school" in fields_data:
school_districts = [
SchoolDistrict.from_api(district)
for district in fields_data["school"]
]
school_data = fields_data["school"]
if isinstance(school_data, dict):
school_districts = [
SchoolDistrict.from_api(district)
for district in school_data.values()
]
elif "school_districts" in fields_data:
school_data = fields_data["school_districts"]
if isinstance(school_data, dict):
school_districts = [
SchoolDistrict.from_api(district)
for district in school_data.values()
]


# Dynamically parse all census fields (e.g., census2010, census2020, census2024, etc.)
# This supports any census year returned by the API
Expand Down
3 changes: 3 additions & 0 deletions src/geocodio/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ class SchoolDistrict(ApiModelMixin):
name: str
district_number: Optional[str] = None
lea_id: Optional[str] = None # Local Education Agency ID
lea_code: Optional[str] = None # Local Education Agency Code
nces_id: Optional[str] = None # National Center for Education Statistics ID
grade_low: Optional[str] = None # Lowest grade served
grade_high: Optional[str] = None # Highest grade served
extras: Dict[str, Any] = field(default_factory=dict, repr=False)


Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,14 @@ def test_integration_with_school_districts(client):
assert isinstance(district.district_number, str)
if district.lea_id:
assert isinstance(district.lea_id, str)
if district.lea_code: #added to match actual api response
assert isinstance(district.lea_code, str)
if district.nces_id:
assert isinstance(district.nces_id, str)
if district.grade_low: #added to match actual api response
assert isinstance(district.grade_low, str)
if district.grade_high: #added to match actual api response
assert isinstance(district.grade_high, str)


def test_integration_with_census2023(client):
Expand Down