Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
10 changes: 9 additions & 1 deletion homeassistant/components/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
25 changes: 25 additions & 0 deletions tests/components/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 posting to a nonexisting webhook."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale docstring.

resp = await mock_client.get('/api/webhook/non-existing')
assert resp.status == 200


async def test_getting_webhook(hass, mock_client):
"""Test posting a webhook with no data."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale docstring.

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