Skip to content

Commit

Permalink
Fix Mealie test coverage (home-assistant#133659)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Dec 20, 2024
1 parent 1e420f1 commit 9a0035e
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 67 deletions.
4 changes: 1 addition & 3 deletions homeassistant/components/mealie/quality_scale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ rules:
log-when-unavailable: done
parallel-updates: done
reauthentication-flow: done
test-coverage:
status: todo
comment: Platform missing tests
test-coverage: done
# Gold
devices: done
diagnostics: done
Expand Down
32 changes: 11 additions & 21 deletions homeassistant/components/mealie/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,29 +148,19 @@ async def async_update_todo_item(self, item: TodoItem) -> None:
"""Update an item on the list."""
list_items = self.shopping_items

for items in list_items:
if items.item_id == item.uid:
position = items.position
break

list_item: ShoppingItem | None = next(
(x for x in list_items if x.item_id == item.uid), None
)
assert list_item is not None
position = list_item.position

if not list_item:
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="item_not_found_error",
translation_placeholders={"shopping_list_item": item.uid or ""},
)

udpdate_shopping_item = MutateShoppingItem(
update_shopping_item = MutateShoppingItem(
item_id=list_item.item_id,
list_id=list_item.list_id,
note=list_item.note,
display=list_item.display,
checked=item.status == TodoItemStatus.COMPLETED,
position=list_item.position,
position=position,
is_food=list_item.is_food,
disable_amount=list_item.disable_amount,
quantity=list_item.quantity,
Expand All @@ -182,16 +172,16 @@ async def async_update_todo_item(self, item: TodoItem) -> None:
stripped_item_summary = item.summary.strip() if item.summary else item.summary

if list_item.display.strip() != stripped_item_summary:
udpdate_shopping_item.note = stripped_item_summary
udpdate_shopping_item.position = position
udpdate_shopping_item.is_food = False
udpdate_shopping_item.food_id = None
udpdate_shopping_item.quantity = 0.0
udpdate_shopping_item.checked = item.status == TodoItemStatus.COMPLETED
update_shopping_item.note = stripped_item_summary
update_shopping_item.position = position
update_shopping_item.is_food = False
update_shopping_item.food_id = None
update_shopping_item.quantity = 0.0
update_shopping_item.checked = item.status == TodoItemStatus.COMPLETED

try:
await self.coordinator.client.update_shopping_item(
list_item.item_id, udpdate_shopping_item
list_item.item_id, update_shopping_item
)
except MealieError as exception:
raise HomeAssistantError(
Expand Down
20 changes: 18 additions & 2 deletions tests/components/mealie/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from http import HTTPStatus
from unittest.mock import AsyncMock, patch

from aiomealie import MealplanResponse
from syrupy.assertion import SnapshotAssertion

from homeassistant.const import Platform
from homeassistant.const import STATE_OFF, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er

Expand Down Expand Up @@ -40,13 +41,28 @@ async def test_entities(
mock_mealie_client: AsyncMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test the API returns the calendar."""
"""Test the calendar entities."""
with patch("homeassistant.components.mealie.PLATFORMS", [Platform.CALENDAR]):
await setup_integration(hass, mock_config_entry)

await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)


async def test_no_meal_planned(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
mock_mealie_client: AsyncMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test the calendar handles no meal planned."""
mock_mealie_client.get_mealplans.return_value = MealplanResponse([])

await setup_integration(hass, mock_config_entry)

assert hass.states.get("calendar.mealie_dinner").state == STATE_OFF


async def test_api_events(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
Expand Down
Loading

0 comments on commit 9a0035e

Please sign in to comment.