Skip to content

Commit

Permalink
Use new constants in todo tests (home-assistant#121727)
Browse files Browse the repository at this point in the history
joostlek authored Jul 10, 2024
1 parent 2fce71e commit 0462582
Showing 9 changed files with 446 additions and 372 deletions.
107 changes: 58 additions & 49 deletions tests/components/caldav/test_todo.py
Original file line number Diff line number Diff line change
@@ -8,8 +8,17 @@
from caldav.objects import Todo
import pytest

from homeassistant.components.todo import DOMAIN as TODO_DOMAIN
from homeassistant.const import Platform
from homeassistant.components.todo import (
ATTR_DESCRIPTION,
ATTR_DUE_DATE,
ATTR_DUE_DATETIME,
ATTR_ITEM,
ATTR_RENAME,
ATTR_STATUS,
DOMAIN as TODO_DOMAIN,
TodoServices,
)
from homeassistant.const import ATTR_ENTITY_ID, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError

@@ -226,12 +235,12 @@ async def test_supported_components(
RESULT_ITEM,
),
(
{"due_date": "2023-11-18"},
{ATTR_DUE_DATE: "2023-11-18"},
{"status": "NEEDS-ACTION", "summary": "Cheese", "due": date(2023, 11, 18)},
{**RESULT_ITEM, "due": "2023-11-18"},
),
(
{"due_datetime": "2023-11-18T08:30:00-06:00"},
{ATTR_DUE_DATETIME: "2023-11-18T08:30:00-06:00"},
{
"status": "NEEDS-ACTION",
"summary": "Cheese",
@@ -240,7 +249,7 @@ async def test_supported_components(
{**RESULT_ITEM, "due": "2023-11-18T08:30:00-06:00"},
),
(
{"description": "Make sure to get Swiss"},
{ATTR_DESCRIPTION: "Make sure to get Swiss"},
{
"status": "NEEDS-ACTION",
"summary": "Cheese",
@@ -278,9 +287,9 @@ async def test_add_item(

await hass.services.async_call(
TODO_DOMAIN,
"add_item",
{"item": "Cheese", **item_data},
target={"entity_id": TEST_ENTITY},
TodoServices.ADD_ITEM,
{ATTR_ITEM: "Cheese", **item_data},
target={ATTR_ENTITY_ID: TEST_ENTITY},
blocking=True,
)

@@ -306,9 +315,9 @@ async def test_add_item_failure(
with pytest.raises(HomeAssistantError, match="CalDAV save error"):
await hass.services.async_call(
TODO_DOMAIN,
"add_item",
{"item": "Cheese"},
target={"entity_id": TEST_ENTITY},
TodoServices.ADD_ITEM,
{ATTR_ITEM: "Cheese"},
target={ATTR_ENTITY_ID: TEST_ENTITY},
blocking=True,
)

@@ -317,7 +326,7 @@ async def test_add_item_failure(
("update_data", "expected_ics", "expected_state", "expected_item"),
[
(
{"rename": "Swiss Cheese"},
{ATTR_RENAME: "Swiss Cheese"},
[
"DESCRIPTION:Any kind will do",
"DUE;VALUE=DATE:20171126",
@@ -334,7 +343,7 @@ async def test_add_item_failure(
},
),
(
{"status": "needs_action"},
{ATTR_STATUS: "needs_action"},
[
"DESCRIPTION:Any kind will do",
"DUE;VALUE=DATE:20171126",
@@ -351,7 +360,7 @@ async def test_add_item_failure(
},
),
(
{"status": "completed"},
{ATTR_STATUS: "completed"},
[
"DESCRIPTION:Any kind will do",
"DUE;VALUE=DATE:20171126",
@@ -368,7 +377,7 @@ async def test_add_item_failure(
},
),
(
{"rename": "Swiss Cheese", "status": "needs_action"},
{ATTR_RENAME: "Swiss Cheese", ATTR_STATUS: "needs_action"},
[
"DESCRIPTION:Any kind will do",
"DUE;VALUE=DATE:20171126",
@@ -385,7 +394,7 @@ async def test_add_item_failure(
},
),
(
{"due_date": "2023-11-18"},
{ATTR_DUE_DATE: "2023-11-18"},
[
"DESCRIPTION:Any kind will do",
"DUE;VALUE=DATE:20231118",
@@ -402,7 +411,7 @@ async def test_add_item_failure(
},
),
(
{"due_datetime": "2023-11-18T08:30:00-06:00"},
{ATTR_DUE_DATETIME: "2023-11-18T08:30:00-06:00"},
[
"DESCRIPTION:Any kind will do",
"DUE;TZID=America/Regina:20231118T083000",
@@ -419,7 +428,7 @@ async def test_add_item_failure(
},
),
(
{"due_datetime": None},
{ATTR_DUE_DATETIME: None},
[
"DESCRIPTION:Any kind will do",
"STATUS:NEEDS-ACTION",
@@ -434,7 +443,7 @@ async def test_add_item_failure(
},
),
(
{"description": "Make sure to get Swiss"},
{ATTR_DESCRIPTION: "Make sure to get Swiss"},
[
"DESCRIPTION:Make sure to get Swiss",
"DUE;VALUE=DATE:20171126",
@@ -451,7 +460,7 @@ async def test_add_item_failure(
},
),
(
{"description": None},
{ATTR_DESCRIPTION: None},
["DUE;VALUE=DATE:20171126", "STATUS:NEEDS-ACTION", "SUMMARY:Cheese"],
"1",
{
@@ -501,12 +510,12 @@ async def test_update_item(

await hass.services.async_call(
TODO_DOMAIN,
"update_item",
TodoServices.UPDATE_ITEM,
{
"item": "Cheese",
ATTR_ITEM: "Cheese",
**update_data,
},
target={"entity_id": TEST_ENTITY},
target={ATTR_ENTITY_ID: TEST_ENTITY},
blocking=True,
)

@@ -520,9 +529,9 @@ async def test_update_item(

result = await hass.services.async_call(
TODO_DOMAIN,
"get_items",
TodoServices.GET_ITEMS,
{},
target={"entity_id": TEST_ENTITY},
target={ATTR_ENTITY_ID: TEST_ENTITY},
blocking=True,
return_response=True,
)
@@ -548,12 +557,12 @@ async def test_update_item_failure(
with pytest.raises(HomeAssistantError, match="CalDAV save error"):
await hass.services.async_call(
TODO_DOMAIN,
"update_item",
TodoServices.UPDATE_ITEM,
{
"item": "Cheese",
"status": "completed",
ATTR_ITEM: "Cheese",
ATTR_STATUS: "completed",
},
target={"entity_id": TEST_ENTITY},
target={ATTR_ENTITY_ID: TEST_ENTITY},
blocking=True,
)

@@ -582,12 +591,12 @@ async def test_update_item_lookup_failure(
with pytest.raises(HomeAssistantError, match=match):
await hass.services.async_call(
TODO_DOMAIN,
"update_item",
TodoServices.UPDATE_ITEM,
{
"item": "Cheese",
"status": "completed",
ATTR_ITEM: "Cheese",
ATTR_STATUS: "completed",
},
target={"entity_id": TEST_ENTITY},
target={ATTR_ENTITY_ID: TEST_ENTITY},
blocking=True,
)

@@ -635,9 +644,9 @@ def lookup(uid: str) -> Mock:

await hass.services.async_call(
TODO_DOMAIN,
"remove_item",
{"item": uids_to_delete},
target={"entity_id": TEST_ENTITY},
TodoServices.REMOVE_ITEM,
{ATTR_ITEM: uids_to_delete},
target={ATTR_ENTITY_ID: TEST_ENTITY},
blocking=True,
)

@@ -668,9 +677,9 @@ async def test_remove_item_lookup_failure(
with pytest.raises(HomeAssistantError, match=match):
await hass.services.async_call(
TODO_DOMAIN,
"remove_item",
{"item": "Cheese"},
target={"entity_id": TEST_ENTITY},
TodoServices.REMOVE_ITEM,
{ATTR_ITEM: "Cheese"},
target={ATTR_ENTITY_ID: TEST_ENTITY},
blocking=True,
)

@@ -697,9 +706,9 @@ def lookup(uid: str) -> Mock:
with pytest.raises(HomeAssistantError, match="CalDAV delete error"):
await hass.services.async_call(
TODO_DOMAIN,
"remove_item",
{"item": "Cheese"},
target={"entity_id": TEST_ENTITY},
TodoServices.REMOVE_ITEM,
{ATTR_ITEM: "Cheese"},
target={ATTR_ENTITY_ID: TEST_ENTITY},
blocking=True,
)

@@ -725,9 +734,9 @@ def lookup(uid: str) -> Mock:
with pytest.raises(HomeAssistantError, match="Could not find"):
await hass.services.async_call(
TODO_DOMAIN,
"remove_item",
{"item": "Cheese"},
target={"entity_id": TEST_ENTITY},
TodoServices.REMOVE_ITEM,
{ATTR_ITEM: "Cheese"},
target={ATTR_ENTITY_ID: TEST_ENTITY},
blocking=True,
)

@@ -779,12 +788,12 @@ async def test_subscribe(
]
await hass.services.async_call(
TODO_DOMAIN,
"update_item",
TodoServices.UPDATE_ITEM,
{
"item": "Cheese",
"rename": "Milk",
ATTR_ITEM: "Cheese",
ATTR_RENAME: "Milk",
},
target={"entity_id": TEST_ENTITY},
target={ATTR_ENTITY_ID: TEST_ENTITY},
blocking=True,
)

Loading

0 comments on commit 0462582

Please sign in to comment.