diff --git a/src/meshapi/tests/test_map_endpoints.py b/src/meshapi/tests/test_map_endpoints.py index 99ea3f32..9628ca67 100644 --- a/src/meshapi/tests/test_map_endpoints.py +++ b/src/meshapi/tests/test_map_endpoints.py @@ -1,6 +1,7 @@ import datetime import json import uuid +from unittest.mock import patch import requests_mock from django.test import Client, TestCase @@ -1726,6 +1727,23 @@ def test_kiosk_list_good_state(self, city_api_call_request_mocker): ) self.assertEqual(len(json.loads(response.content.decode("UTF8"))), 7) + @patch("logging.warning") + @requests_mock.Mocker() + def test_kiosk_list_empty_row(self, mock_warning, city_api_call_request_mocker): + # On 02-07-2025, City of New York LinkNYC API changed its data, and Row 19 + # was blank. This tests a guard I added to ensure that doesn't cause us to + # raise Exceptions + city_api_call_request_mocker.get(LINKNYC_KIOSK_DATA_URL, json=[{}]) + + response = self.c.get("/api/v1/mapdata/kiosks/") + self.assertEqual( + 200, + response.status_code, + f"status code incorrect, should be 200, but got {response.status_code}", + ) + mock_warning.assert_called() + self.assertEqual(len(json.loads(response.content.decode("UTF8"))), 0) + @requests_mock.Mocker() def test_kiosk_list_bad_fetch(self, city_api_call_request_mocker): city_api_call_request_mocker.get(LINKNYC_KIOSK_DATA_URL, status_code=500) diff --git a/src/meshapi/views/map.py b/src/meshapi/views/map.py index d6aba6be..13bc8ea8 100644 --- a/src/meshapi/views/map.py +++ b/src/meshapi/views/map.py @@ -452,6 +452,11 @@ def get(self, request: Request) -> Response: kiosks = [] for row in data: + if not row: + logging.warning( + "Got empty row from City of New York LinkNYC kiosk dataset. Skipping row and moving on." + ) + continue coordinates = [float(row["longitude"]), float(row["latitude"])] kiosk_status = LINKNYC_KIOSK_STATUS_TRANSLATION.get(row["link_installation_status"]) kiosks.append(