Skip to content

Commit 0a06fca

Browse files
test: add test for census field appends
Add test case to verify that all census year fields (census2010, census2020, census2023, census2024) are properly parsed and included in the response. This test currently demonstrates the bug where census2024 and other years beyond 2023 are not being parsed even though the API returns them. Relates to #12
1 parent e33e911 commit 0a06fca

File tree

1 file changed

+99
-1
lines changed

1 file changed

+99
-1
lines changed

tests/unit/test_geocode.py

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,102 @@ def batch_response_callback(request):
498498
assert resp.results[1].formatted_address == "638 E 13th Ave, Denver, CO 80203"
499499
assert resp.results[1].fields.timezone.name == "America/Denver"
500500
assert resp.results[1].fields.timezone.utc_offset == -7
501-
assert resp.results[1].fields.congressional_districts[0].district_number == 1
501+
assert resp.results[1].fields.congressional_districts[0].district_number == 1
502+
503+
504+
def test_geocode_with_census_fields(client, httpx_mock):
505+
"""Test geocoding with census field appends including all census years."""
506+
# Arrange: stub the API call with multiple census years
507+
def response_callback(request):
508+
assert request.method == "GET"
509+
assert request.url.params["fields"] == "census2010,census2020,census2023,census2024"
510+
return httpx.Response(200, json={
511+
"results": [{
512+
"address_components": {
513+
"number": "1640",
514+
"street": "Main",
515+
"suffix": "St",
516+
"city": "Sheldon",
517+
"state": "VT",
518+
"zip": "05483",
519+
"country": "US"
520+
},
521+
"formatted_address": "1640 Main St, Sheldon, VT 05483",
522+
"location": {"lat": 44.895469, "lng": -72.953264},
523+
"accuracy": 1,
524+
"accuracy_type": "rooftop",
525+
"source": "Vermont",
526+
"fields": {
527+
"census2010": {
528+
"tract": "960100",
529+
"block": "2001",
530+
"blockgroup": "2",
531+
"county_fips": "50011",
532+
"state_fips": "50"
533+
},
534+
"census2020": {
535+
"tract": "960100",
536+
"block": "2002",
537+
"blockgroup": "2",
538+
"county_fips": "50011",
539+
"state_fips": "50"
540+
},
541+
"census2023": {
542+
"tract": "960100",
543+
"block": "2003",
544+
"blockgroup": "2",
545+
"county_fips": "50011",
546+
"state_fips": "50"
547+
},
548+
"census2024": {
549+
"tract": "960100",
550+
"block": "2004",
551+
"blockgroup": "2",
552+
"county_fips": "50011",
553+
"state_fips": "50"
554+
}
555+
}
556+
}]
557+
})
558+
559+
httpx_mock.add_callback(
560+
callback=response_callback,
561+
url=httpx.URL("https://api.test/v1.9/geocode", params={
562+
"street": "1640 Main St",
563+
"city": "Sheldon",
564+
"state": "VT",
565+
"postal_code": "05483",
566+
"fields": "census2010,census2020,census2023,census2024"
567+
}),
568+
match_headers={"Authorization": "Bearer TEST_KEY"},
569+
)
570+
571+
# Act
572+
resp = client.geocode(
573+
{"city": "Sheldon", "state": "VT", "street": "1640 Main St", "postal_code": "05483"},
574+
fields=["census2010", "census2020", "census2023", "census2024"],
575+
)
576+
577+
# Assert
578+
assert len(resp.results) == 1
579+
result = resp.results[0]
580+
assert result.formatted_address == "1640 Main St, Sheldon, VT 05483"
581+
582+
# Check that all census fields are present and parsed correctly
583+
assert result.fields.census2010 is not None
584+
assert result.fields.census2010.tract == "960100"
585+
assert result.fields.census2010.block == "2001"
586+
assert result.fields.census2010.county_fips == "50011"
587+
588+
assert result.fields.census2020 is not None
589+
assert result.fields.census2020.tract == "960100"
590+
assert result.fields.census2020.block == "2002"
591+
592+
assert result.fields.census2023 is not None
593+
assert result.fields.census2023.tract == "960100"
594+
assert result.fields.census2023.block == "2003"
595+
596+
# This will fail until we fix the parsing logic
597+
assert result.fields.census2024 is not None
598+
assert result.fields.census2024.tract == "960100"
599+
assert result.fields.census2024.block == "2004"

0 commit comments

Comments
 (0)