Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions homeassistant/components/calendar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ async def get(self, request: web.Request, entity_id: str) -> web.Response:
return web.Response(status=HTTPStatus.BAD_REQUEST)
if start_date is None or end_date is None:
return web.Response(status=HTTPStatus.BAD_REQUEST)
if start_date > end_date:
return web.Response(status=HTTPStatus.BAD_REQUEST)
Comment thread
albinmedoc marked this conversation as resolved.

try:
calendar_event_list = await entity.async_get_events(
Expand Down
17 changes: 17 additions & 0 deletions tests/components/calendar/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ async def test_events_http_api_error(
assert await response.json() == {"message": "Error reading events: Failure"}


async def test_events_http_api_dates_wrong_order(
hass: HomeAssistant, hass_client: ClientSessionGenerator
) -> None:
"""Test the calendar demo view."""
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
await hass.async_block_till_done()
client = await hass_client()
start = dt_util.now()
end = start + timedelta(days=-1)
response = await client.get(
"/api/calendars/calendar.calendar_1?start={}&end={}".format(
start.isoformat(), end.isoformat()
)
Comment thread
albinmedoc marked this conversation as resolved.
Outdated
)
assert response.status == HTTPStatus.BAD_REQUEST


async def test_calendars_http_api(
hass: HomeAssistant, hass_client: ClientSessionGenerator
) -> None:
Expand Down