Add HEAD and PUT support to webhooks (#26299)
parent
f01e106e6d
commit
37a3d5fd85
|
@ -99,11 +99,15 @@ 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)
|
||||
|
||||
head = _handle
|
||||
post = _handle
|
||||
put = _handle
|
||||
|
||||
|
||||
@callback
|
||||
def websocket_list(hass, connection, msg):
|
||||
|
|
|
@ -99,9 +99,48 @@ async def test_posting_webhook_no_data(hass, mock_client):
|
|||
assert len(hooks) == 1
|
||||
assert hooks[0][0] is hass
|
||||
assert hooks[0][1] == webhook_id
|
||||
assert hooks[0][2].method == "POST"
|
||||
assert await hooks[0][2].text() == ""
|
||||
|
||||
|
||||
async def test_webhook_put(hass, mock_client):
|
||||
"""Test sending a put request to a webhook."""
|
||||
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.put("/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
|
||||
assert hooks[0][2].method == "PUT"
|
||||
|
||||
|
||||
async def test_webhook_head(hass, mock_client):
|
||||
"""Test sending a head request to a webhook."""
|
||||
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.head("/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
|
||||
assert hooks[0][2].method == "HEAD"
|
||||
|
||||
|
||||
async def test_listing_webhook(hass, hass_ws_client, hass_access_token):
|
||||
"""Test unregistering a webhook."""
|
||||
assert await async_setup_component(hass, "webhook", {})
|
||||
|
|
Loading…
Reference in New Issue