Skip to content

Commit 8ee3612

Browse files
Add guard for empty row in LinkNYC API (#829)
* Add guard for empty row in LinkNYC API * lint * lint * ahhhhhhh --------- Co-authored-by: James Otten <jamesotten1@gmail.com>
1 parent 813083f commit 8ee3612

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/meshapi/tests/test_map_endpoints.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
import json
33
import uuid
4+
from unittest.mock import patch
45

56
import requests_mock
67
from django.test import Client, TestCase
@@ -1726,6 +1727,23 @@ def test_kiosk_list_good_state(self, city_api_call_request_mocker):
17261727
)
17271728
self.assertEqual(len(json.loads(response.content.decode("UTF8"))), 7)
17281729

1730+
@patch("logging.warning")
1731+
@requests_mock.Mocker()
1732+
def test_kiosk_list_empty_row(self, mock_warning, city_api_call_request_mocker):
1733+
# On 02-07-2025, City of New York LinkNYC API changed its data, and Row 19
1734+
# was blank. This tests a guard I added to ensure that doesn't cause us to
1735+
# raise Exceptions
1736+
city_api_call_request_mocker.get(LINKNYC_KIOSK_DATA_URL, json=[{}])
1737+
1738+
response = self.c.get("/api/v1/mapdata/kiosks/")
1739+
self.assertEqual(
1740+
200,
1741+
response.status_code,
1742+
f"status code incorrect, should be 200, but got {response.status_code}",
1743+
)
1744+
mock_warning.assert_called()
1745+
self.assertEqual(len(json.loads(response.content.decode("UTF8"))), 0)
1746+
17291747
@requests_mock.Mocker()
17301748
def test_kiosk_list_bad_fetch(self, city_api_call_request_mocker):
17311749
city_api_call_request_mocker.get(LINKNYC_KIOSK_DATA_URL, status_code=500)

src/meshapi/views/map.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ def get(self, request: Request) -> Response:
452452

453453
kiosks = []
454454
for row in data:
455+
if not row:
456+
logging.warning(
457+
"Got empty row from City of New York LinkNYC kiosk dataset. Skipping row and moving on."
458+
)
459+
continue
455460
coordinates = [float(row["longitude"]), float(row["latitude"])]
456461
kiosk_status = LINKNYC_KIOSK_STATUS_TRANSLATION.get(row["link_installation_status"])
457462
kiosks.append(

0 commit comments

Comments
 (0)