Add Calendar API endpoint to get events (#14702)

* Add Calendar API endpoint to get events

* Set default event color

* Fix PR comments

* Fix PR comments

* Fix PR comments

* Remote local.py file

* Use iso 8601

* Fix lint

* Fix PR comments

* Fix PR comments

* Add Support for todoist and demo calendar

* Todoist events are allday events

* Add calendar demo api endpoint test

* Register only one api endpoint for calendar

* Rename demo calendar
This commit is contained in:
Thibault Cohen authored and Paulus Schoutsen committed 2018-06-15 11:16:31 -04:00
1 parent 1128104281
commit 3cd4cb741c
8 files changed
+202 -34

No files matched your search

+9 -8
View File
@@ -19,7 +19,7 @@ _LOGGER = logging.getLogger(__name__)
DEVICE_DATA = {
"name": "Private Calendar",
"device_id": "Private Calendar"
"device_id": "Private Calendar",
}
EVENTS = [
@@ -163,6 +163,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.http = Mock()
self.calendar = _mock_calendar("Private")
# pylint: disable=invalid-name
@@ -255,7 +256,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
"start_time": "2017-11-27 17:00:00",
"end_time": "2017-11-27 18:00:00",
"location": "Hamburg",
"description": "Surprisingly rainy"
"description": "Surprisingly rainy",
})
@patch('homeassistant.util.dt.now', return_value=_local_datetime(17, 30))
@@ -274,7 +275,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
"start_time": "2017-11-27 17:00:00",
"end_time": "2017-11-27 18:00:00",
"location": "Hamburg",
"description": "Surprisingly rainy"
"description": "Surprisingly rainy",
})
@patch('homeassistant.util.dt.now', return_value=_local_datetime(17, 00))
@@ -293,7 +294,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
"start_time": "2017-11-27 16:30:00",
"description": "Sunny day",
"end_time": "2017-11-27 17:30:00",
"location": "San Francisco"
"location": "San Francisco",
})
@patch('homeassistant.util.dt.now', return_value=_local_datetime(8, 30))
@@ -311,7 +312,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
"start_time": "2017-11-27 10:00:00",
"end_time": "2017-11-27 11:00:00",
"location": "Hamburg",
"description": "Surprisingly shiny"
"description": "Surprisingly shiny",
})
@patch('homeassistant.util.dt.now', return_value=_local_datetime(12, 00))
@@ -332,7 +333,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
"start_time": "2017-11-27 17:00:00",
"end_time": "2017-11-27 18:00:00",
"location": "Hamburg",
"description": "Surprisingly rainy"
"description": "Surprisingly rainy",
})
@patch('homeassistant.util.dt.now', return_value=_local_datetime(12, 00))
@@ -353,7 +354,7 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
"start_time": "2017-11-27 17:00:00",
"end_time": "2017-11-27 18:00:00",
"location": "Hamburg",
"description": "Surprisingly rainy"
"description": "Surprisingly rainy",
})
@patch('homeassistant.util.dt.now', return_value=_local_datetime(20, 00))
@@ -395,5 +396,5 @@ class TestComponentsWebDavCalendar(unittest.TestCase):
"start_time": "2017-11-27 00:00:00",
"end_time": "2017-11-28 00:00:00",
"location": "Hamburg",
"description": "What a beautiful day"
"description": "What a beautiful day",
})
+24
View File
@@ -0,0 +1,24 @@
"""The tests for the demo calendar component."""
from datetime import timedelta
from homeassistant.bootstrap import async_setup_component
import homeassistant.util.dt as dt_util
async def test_api_calendar_demo_view(hass, aiohttp_client):
"""Test the calendar demo view."""
await async_setup_component(hass, 'calendar',
{'calendar': {'platform': 'demo'}})
client = await aiohttp_client(hass.http.app)
response = await client.get(
'/api/calendar/calendar_2')
assert response.status == 400
start = dt_util.now()
end = start + timedelta(days=1)
response = await client.get(
'/api/calendar/calendar_1?start={}&end={}'.format(start.isoformat(),
end.isoformat()))
assert response.status == 200
events = await response.json()
assert events[0]['summary'] == 'Future Event'
assert events[0]['title'] == 'Future Event'
+7 -6
View File
@@ -27,6 +27,7 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
def setUp(self):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.http = Mock()
# Set our timezone to CST/Regina so we can check calculations
# This keeps UTC-6 all year round
@@ -99,7 +100,7 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
'start_time': '{} 00:00:00'.format(event['start']['date']),
'end_time': '{} 00:00:00'.format(event['end']['date']),
'location': event['location'],
'description': event['description']
'description': event['description'],
})
@patch('homeassistant.components.calendar.google.GoogleCalendarData')
@@ -160,7 +161,7 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
(one_hour_from_now + dt_util.dt.timedelta(minutes=60))
.strftime(DATE_STR_FORMAT),
'location': '',
'description': ''
'description': '',
})
@patch('homeassistant.components.calendar.google.GoogleCalendarData')
@@ -222,7 +223,7 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
(middle_of_event + dt_util.dt.timedelta(minutes=60))
.strftime(DATE_STR_FORMAT),
'location': '',
'description': ''
'description': '',
})
@patch('homeassistant.components.calendar.google.GoogleCalendarData')
@@ -285,7 +286,7 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
(middle_of_event + dt_util.dt.timedelta(minutes=60))
.strftime(DATE_STR_FORMAT),
'location': '',
'description': ''
'description': '',
})
@pytest.mark.skip
@@ -352,7 +353,7 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
'start_time': '{} 06:00:00'.format(event['start']['date']),
'end_time': '{} 06:00:00'.format(event['end']['date']),
'location': event['location'],
'description': event['description']
'description': event['description'],
})
@patch('homeassistant.components.calendar.google.GoogleCalendarData')
@@ -419,7 +420,7 @@ class TestComponentsGoogleCalendar(unittest.TestCase):
'start_time': '{} 00:00:00'.format(event['start']['date']),
'end_time': '{} 00:00:00'.format(event['end']['date']),
'location': event['location'],
'description': event['description']
'description': event['description'],
})
@MockDependency("httplib2")