Skip to content

Commit

Permalink
Fix crash on Node without installs
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Dickinson committed Dec 17, 2024
1 parent 03f75b1 commit 6a322b0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
47 changes: 47 additions & 0 deletions src/meshapi/tests/test_map_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,53 @@ def test_kiosk_list_bad_response(self, city_api_call_request_mocker):
)


class TestNodeWithoutInstallDoesntCrash(TestCase):
def test_node_without_install(self):
node = Node(
network_number=123,
latitude=40.724868,
longitude=-73.987881,
altitude=37.0,
status=Node.NodeStatus.ACTIVE,
install_date=datetime.date(2024, 12, 1),
)
node.save()

node2 = Node(
network_number=124,
latitude=40.724868,
longitude=-73.987881,
altitude=37.0,
status=Node.NodeStatus.PLANNED,
install_date=None,
)
node2.save()

self.maxDiff = None
response = self.client.get("/api/v1/mapdata/nodes/")

self.assertEqual(
json.loads(response.content.decode("UTF8")),
[
{
"id": 123,
"status": "NN assigned",
"coordinates": [-73.987881, 40.724868, 37.0],
"requestDate": 1733029200000,
"roofAccess": True,
"panoramas": [],
},
{
"id": 124,
"coordinates": [-73.987881, 40.724868, 37.0],
"requestDate": 0,
"roofAccess": True,
"panoramas": [],
},
],
)


class TestJavascriptDateSerializerField(TestCase):
def test_to_interal_value(self):
dt_serializer_field = JavascriptDatetimeField()
Expand Down
13 changes: 10 additions & 3 deletions src/meshapi/views/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ def get_queryset(self) -> List[Install]: # type: ignore[override]
altitude=node.altitude,
)

request_date = datetime.fromtimestamp(0)
if representative_install:
request_date = representative_install.request_date
elif node.install_date:
request_date = datetime.combine(
node.install_date,
datetime.min.time(),
)

all_installs.append(
Install(
install_number=node.network_number,
Expand All @@ -120,9 +129,7 @@ def get_queryset(self) -> List[Install]: # type: ignore[override]
if node.status == node.NodeStatus.ACTIVE
else Install.InstallStatus.REQUEST_RECEIVED,
building=building,
request_date=representative_install.request_date
if representative_install
else node.install_date,
request_date=request_date,
roof_access=representative_install.roof_access if representative_install else True,
),
)
Expand Down

0 comments on commit 6a322b0

Please sign in to comment.