| from app.services.geo import GeoService | |
| def _geo(): | |
| import os | |
| return GeoService(os.environ["ZIP_CENTROID_FILE"]) | |
| def test_distance_close_zips_small(): | |
| g = _geo() | |
| # Two Manhattan ZIPs should be only a few miles apart. | |
| d = g.distance_miles("10001", "10002") | |
| assert d is not None and d < 5 | |
| def test_distance_coast_to_coast_large(): | |
| g = _geo() | |
| d = g.distance_miles("20001", "94103") # DC -> SF | |
| assert d is not None and d > 2000 | |
| def test_within_radius_levels(): | |
| g = _geo() | |
| assert g.within_radius("20001", "20002", 10) is True | |
| assert g.within_radius("20001", "98101", 25) is False | |
| assert g.within_radius("20001", "98101", -1) is True # nationwide | |
| def test_unknown_zip_fails_open(): | |
| g = _geo() | |
| assert g.within_radius("20001", "00000", 10) is True | |