Add Local calendar edit support (#84141)
* Add update support for calendars and implement in local calendar * Fix supported feature for update calendar * Increase test coverage for websocket error cases * Improve test coverage for update failure cases * Improve test coverage by sharing code between update and create * Update homeassistant/components/calendar/__init__.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
b01efc55a2
commit
624c93bb38
5 changed files with 455 additions and 24 deletions
|
@ -3,6 +3,8 @@ from datetime import timedelta
|
|||
from http import HTTPStatus
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
@ -67,3 +69,91 @@ async def test_calendars_http_api(hass, hass_client):
|
|||
{"entity_id": "calendar.calendar_1", "name": "Calendar 1"},
|
||||
{"entity_id": "calendar.calendar_2", "name": "Calendar 2"},
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"payload,code",
|
||||
[
|
||||
(
|
||||
{
|
||||
"type": "calendar/event/create",
|
||||
"entity_id": "calendar.calendar_1",
|
||||
"event": {
|
||||
"summary": "Bastille Day Party",
|
||||
"dtstart": "1997-07-14T17:00:00+00:00",
|
||||
"dtend": "1997-07-15T04:00:00+00:00",
|
||||
},
|
||||
},
|
||||
"not_supported",
|
||||
),
|
||||
(
|
||||
{
|
||||
"type": "calendar/event/create",
|
||||
"entity_id": "calendar.calendar_99",
|
||||
"event": {
|
||||
"summary": "Bastille Day Party",
|
||||
"dtstart": "1997-07-14T17:00:00+00:00",
|
||||
"dtend": "1997-07-15T04:00:00+00:00",
|
||||
},
|
||||
},
|
||||
"not_found",
|
||||
),
|
||||
(
|
||||
{
|
||||
"type": "calendar/event/delete",
|
||||
"entity_id": "calendar.calendar_1",
|
||||
"uid": "some-uid",
|
||||
},
|
||||
"not_supported",
|
||||
),
|
||||
(
|
||||
{
|
||||
"type": "calendar/event/delete",
|
||||
"entity_id": "calendar.calendar_99",
|
||||
"uid": "some-uid",
|
||||
},
|
||||
"not_found",
|
||||
),
|
||||
(
|
||||
{
|
||||
"type": "calendar/event/update",
|
||||
"entity_id": "calendar.calendar_1",
|
||||
"uid": "some-uid",
|
||||
"event": {
|
||||
"summary": "Bastille Day Party",
|
||||
"dtstart": "1997-07-14T17:00:00+00:00",
|
||||
"dtend": "1997-07-15T04:00:00+00:00",
|
||||
},
|
||||
},
|
||||
"not_supported",
|
||||
),
|
||||
(
|
||||
{
|
||||
"type": "calendar/event/update",
|
||||
"entity_id": "calendar.calendar_99",
|
||||
"uid": "some-uid",
|
||||
"event": {
|
||||
"summary": "Bastille Day Party",
|
||||
"dtstart": "1997-07-14T17:00:00+00:00",
|
||||
"dtend": "1997-07-15T04:00:00+00:00",
|
||||
},
|
||||
},
|
||||
"not_found",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_unsupported_websocket(hass, hass_ws_client, payload, code):
|
||||
"""Test unsupported websocket command."""
|
||||
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
|
||||
await hass.async_block_till_done()
|
||||
client = await hass_ws_client(hass)
|
||||
await client.send_json(
|
||||
{
|
||||
"id": 1,
|
||||
**payload,
|
||||
}
|
||||
)
|
||||
resp = await client.receive_json()
|
||||
assert resp.get("id") == 1
|
||||
assert resp.get("error")
|
||||
assert resp["error"].get("code") == code
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue