Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya committed Nov 13, 2023
1 parent 62c899f commit 99c4fe8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pytile/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ async def async_get_tiles(self) -> dict[str, Tile]:

data = {}
for tile_uuid, result in zip(details_tasks, results):
if isinstance(result, RequestError):
if "412" in str(result):
# Tile Labels will return an HTTP 412 because they don't have
# additional details; we can safely ignore these errors and still
# track the Tile (without additional details):
continue
if isinstance(result, RequestError) and "412" in str(result):
# Tile Labels will return an HTTP 412 because they don't have
# additional details; we can safely ignore these errors and still
# track the Tile (without additional details):
continue
if isinstance(result, BaseException):
LOGGER.error("Error requesting details for %s: %s", tile_uuid, result)
continue
data[tile_uuid] = Tile(self._async_request, result)

return data
Expand Down
46 changes: 46 additions & 0 deletions tests/test_tile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Define tests for the client object."""
import logging
from datetime import datetime
from typing import Any
from unittest.mock import Mock

import aiohttp
import pytest
Expand Down Expand Up @@ -140,6 +142,50 @@ async def test_get_tiles(
aresponses.assert_plan_strictly_followed()


@pytest.mark.asyncio
async def test_get_tiles_http_error(
aresponses: ResponsesMockServer,
authenticated_tile_api_server: ResponsesMockServer,
caplog: Mock,
tile_states_response: dict[str, Any],
) -> None:
"""Test getting all Tiles associated with an account.
Args:
aresponses: An aresponses server.
authenticated_tile_api_server: A mock Tile API server connection.
caplog: A mocked logging utility.
tile_states_response: An API response payload.
"""
caplog.set_level(logging.INFO)

async with authenticated_tile_api_server:
authenticated_tile_api_server.add(
"production.tile-api.com",
"/api/v1/tiles/tile_states",
"get",
response=aiohttp.web_response.json_response(
tile_states_response, status=200
),
)
authenticated_tile_api_server.add(
"production.tile-api.com",
f"/api/v1/tiles/{TILE_TILE_UUID}",
"get",
response=aresponses.Response(text=None, status=500),
)

async with aiohttp.ClientSession() as session:
api = await async_login(
TILE_EMAIL, TILE_PASSWORD, session, client_uuid=TILE_CLIENT_UUID
)
tiles = await api.async_get_tiles()
assert len(tiles) == 0
assert any("Error requesting details" in e.message for e in caplog.records)

aresponses.assert_plan_strictly_followed()


@pytest.mark.asyncio
async def test_missing_last_tile_state(
aresponses: ResponsesMockServer,
Expand Down

0 comments on commit 99c4fe8

Please sign in to comment.