diff --git a/homeassistant/components/webhook.py b/homeassistant/components/webhook.py index 6742f33c72dc5..ed9521f59f2b8 100644 --- a/homeassistant/components/webhook.py +++ b/homeassistant/components/webhook.py @@ -101,11 +101,19 @@ class WebhookView(HomeAssistantView): name = "api:webhook" requires_auth = False - async def post(self, request, webhook_id): + async def handle(self, request, webhook_id): """Handle webhook call.""" hass = request.app['hass'] return await async_handle_webhook(hass, webhook_id, request) + async def post(self, request, webhook_id): + """Handle webhook POST call.""" + return await self.handle(request, webhook_id) + + async def get(self, request, webhook_id): + """Handle webhook GET call.""" + return await self.handle(request, webhook_id) + @callback def websocket_list(hass, connection, msg): diff --git a/tests/components/test_webhook.py b/tests/components/test_webhook.py index e67cf7481ccbe..22a04aa7c4b1a 100644 --- a/tests/components/test_webhook.py +++ b/tests/components/test_webhook.py @@ -122,3 +122,28 @@ async def test_listing_webhook(hass, hass_ws_client, hass_access_token): 'name': 'Test hook' } ] + + +async def test_getting_webhook_nonexisting(hass, mock_client): + """Test getting a nonexisting webhook.""" + resp = await mock_client.get('/api/webhook/non-existing') + assert resp.status == 200 + + +async def test_getting_webhook(hass, mock_client): + """Test getting a webhook with no data.""" + hooks = [] + webhook_id = hass.components.webhook.async_generate_id() + + async def handle(*args): + """Handle webhook.""" + hooks.append(args) + + hass.components.webhook.async_register( + 'test', "Test hook", webhook_id, handle) + + resp = await mock_client.get('/api/webhook/{}'.format(webhook_id)) + assert resp.status == 200 + assert len(hooks) == 1 + assert hooks[0][0] is hass + assert hooks[0][1] == webhook_id