2022-11-02 15:11:44 +00:00
|
|
|
"""Test pushbullet notification platform."""
|
2021-10-23 18:56:30 +00:00
|
|
|
from http import HTTPStatus
|
2018-01-24 20:06:35 +00:00
|
|
|
|
2023-02-15 10:14:04 +00:00
|
|
|
import requests_mock
|
2018-01-12 19:06:42 +00:00
|
|
|
|
2022-11-02 15:11:44 +00:00
|
|
|
from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN
|
|
|
|
from homeassistant.components.pushbullet.const import DOMAIN
|
2023-02-15 10:14:04 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2019-12-09 12:06:25 +00:00
|
|
|
|
2022-11-02 15:11:44 +00:00
|
|
|
from . import MOCK_CONFIG
|
2018-01-12 19:06:42 +00:00
|
|
|
|
2022-11-02 15:11:44 +00:00
|
|
|
from tests.common import MockConfigEntry
|
2018-01-12 19:06:42 +00:00
|
|
|
|
|
|
|
|
2023-02-15 10:14:04 +00:00
|
|
|
async def test_pushbullet_push_default(
|
|
|
|
hass: HomeAssistant, requests_mock: requests_mock.Mocker
|
|
|
|
) -> None:
|
2020-10-06 12:34:39 +00:00
|
|
|
"""Test pushbullet push to default target."""
|
|
|
|
requests_mock.register_uri(
|
|
|
|
"POST",
|
|
|
|
"https://api.pushbullet.com/v2/pushes",
|
2021-10-23 18:56:30 +00:00
|
|
|
status_code=HTTPStatus.OK,
|
2020-10-06 12:34:39 +00:00
|
|
|
json={"mock_response": "Ok"},
|
|
|
|
)
|
2022-11-02 15:11:44 +00:00
|
|
|
entry = MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
data=MOCK_CONFIG,
|
|
|
|
)
|
|
|
|
entry.add_to_hass(hass)
|
|
|
|
|
|
|
|
assert await hass.config_entries.async_setup(entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-10-06 12:34:39 +00:00
|
|
|
data = {"title": "Test Title", "message": "Test Message"}
|
2022-11-02 15:11:44 +00:00
|
|
|
await hass.services.async_call(NOTIFY_DOMAIN, "pushbullet", data)
|
2020-10-06 12:34:39 +00:00
|
|
|
await hass.async_block_till_done()
|
2018-01-24 20:06:35 +00:00
|
|
|
|
2020-10-06 12:34:39 +00:00
|
|
|
expected_body = {"body": "Test Message", "title": "Test Title", "type": "note"}
|
2022-11-02 15:11:44 +00:00
|
|
|
assert requests_mock.last_request
|
2020-10-06 12:34:39 +00:00
|
|
|
assert requests_mock.last_request.json() == expected_body
|
2018-01-24 20:06:35 +00:00
|
|
|
|
|
|
|
|
2023-02-15 10:14:04 +00:00
|
|
|
async def test_pushbullet_push_device(
|
|
|
|
hass: HomeAssistant, requests_mock: requests_mock.Mocker
|
|
|
|
) -> None:
|
2020-10-06 12:34:39 +00:00
|
|
|
"""Test pushbullet push to default target."""
|
|
|
|
requests_mock.register_uri(
|
|
|
|
"POST",
|
|
|
|
"https://api.pushbullet.com/v2/pushes",
|
2021-10-23 18:56:30 +00:00
|
|
|
status_code=HTTPStatus.OK,
|
2020-10-06 12:34:39 +00:00
|
|
|
json={"mock_response": "Ok"},
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2022-11-02 15:11:44 +00:00
|
|
|
entry = MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
data=MOCK_CONFIG,
|
|
|
|
)
|
|
|
|
entry.add_to_hass(hass)
|
|
|
|
assert await hass.config_entries.async_setup(entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-10-06 12:34:39 +00:00
|
|
|
data = {
|
|
|
|
"title": "Test Title",
|
|
|
|
"message": "Test Message",
|
|
|
|
"target": ["device/DESKTOP"],
|
|
|
|
}
|
2022-11-02 15:11:44 +00:00
|
|
|
await hass.services.async_call(NOTIFY_DOMAIN, "pushbullet", data)
|
2020-10-06 12:34:39 +00:00
|
|
|
await hass.async_block_till_done()
|
2018-01-24 20:06:35 +00:00
|
|
|
|
2020-10-06 12:34:39 +00:00
|
|
|
expected_body = {
|
|
|
|
"body": "Test Message",
|
|
|
|
"device_iden": "identity1",
|
|
|
|
"title": "Test Title",
|
|
|
|
"type": "note",
|
|
|
|
}
|
|
|
|
assert requests_mock.last_request.json() == expected_body
|
|
|
|
|
|
|
|
|
2023-02-15 10:14:04 +00:00
|
|
|
async def test_pushbullet_push_devices(
|
|
|
|
hass: HomeAssistant, requests_mock: requests_mock.Mocker
|
|
|
|
) -> None:
|
2020-10-06 12:34:39 +00:00
|
|
|
"""Test pushbullet push to default target."""
|
|
|
|
requests_mock.register_uri(
|
|
|
|
"POST",
|
|
|
|
"https://api.pushbullet.com/v2/pushes",
|
2021-10-23 18:56:30 +00:00
|
|
|
status_code=HTTPStatus.OK,
|
2020-10-06 12:34:39 +00:00
|
|
|
json={"mock_response": "Ok"},
|
|
|
|
)
|
2022-11-02 15:11:44 +00:00
|
|
|
entry = MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
data=MOCK_CONFIG,
|
|
|
|
)
|
|
|
|
entry.add_to_hass(hass)
|
|
|
|
assert await hass.config_entries.async_setup(entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-10-06 12:34:39 +00:00
|
|
|
data = {
|
|
|
|
"title": "Test Title",
|
|
|
|
"message": "Test Message",
|
|
|
|
"target": ["device/DESKTOP", "device/My iPhone"],
|
|
|
|
}
|
2022-11-02 15:11:44 +00:00
|
|
|
await hass.services.async_call(NOTIFY_DOMAIN, "pushbullet", data)
|
2020-10-06 12:34:39 +00:00
|
|
|
await hass.async_block_till_done()
|
2018-01-24 20:06:35 +00:00
|
|
|
|
2020-10-06 12:34:39 +00:00
|
|
|
expected_body = {
|
|
|
|
"body": "Test Message",
|
|
|
|
"device_iden": "identity1",
|
|
|
|
"title": "Test Title",
|
|
|
|
"type": "note",
|
|
|
|
}
|
2022-11-02 15:11:44 +00:00
|
|
|
assert requests_mock.request_history[-2].json() == expected_body
|
2020-10-06 12:34:39 +00:00
|
|
|
expected_body = {
|
|
|
|
"body": "Test Message",
|
|
|
|
"device_iden": "identity2",
|
|
|
|
"title": "Test Title",
|
|
|
|
"type": "note",
|
|
|
|
}
|
2022-11-02 15:11:44 +00:00
|
|
|
assert requests_mock.request_history[-1].json() == expected_body
|
2020-10-06 12:34:39 +00:00
|
|
|
|
|
|
|
|
2023-02-15 10:14:04 +00:00
|
|
|
async def test_pushbullet_push_email(
|
|
|
|
hass: HomeAssistant, requests_mock: requests_mock.Mocker
|
|
|
|
) -> None:
|
2020-10-06 12:34:39 +00:00
|
|
|
"""Test pushbullet push to default target."""
|
|
|
|
requests_mock.register_uri(
|
|
|
|
"POST",
|
|
|
|
"https://api.pushbullet.com/v2/pushes",
|
2021-10-23 18:56:30 +00:00
|
|
|
status_code=HTTPStatus.OK,
|
2020-10-06 12:34:39 +00:00
|
|
|
json={"mock_response": "Ok"},
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2022-11-02 15:11:44 +00:00
|
|
|
entry = MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
data=MOCK_CONFIG,
|
|
|
|
)
|
|
|
|
entry.add_to_hass(hass)
|
|
|
|
assert await hass.config_entries.async_setup(entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-10-06 12:34:39 +00:00
|
|
|
data = {
|
|
|
|
"title": "Test Title",
|
|
|
|
"message": "Test Message",
|
|
|
|
"target": ["email/user@host.net"],
|
|
|
|
}
|
2022-11-02 15:11:44 +00:00
|
|
|
await hass.services.async_call(NOTIFY_DOMAIN, "pushbullet", data)
|
2020-10-06 12:34:39 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
expected_body = {
|
|
|
|
"body": "Test Message",
|
|
|
|
"email": "user@host.net",
|
|
|
|
"title": "Test Title",
|
|
|
|
"type": "note",
|
|
|
|
}
|
2022-11-02 15:11:44 +00:00
|
|
|
assert requests_mock.last_request.json() == expected_body
|
2020-10-06 12:34:39 +00:00
|
|
|
|
|
|
|
|
2023-02-15 10:14:04 +00:00
|
|
|
async def test_pushbullet_push_mixed(
|
|
|
|
hass: HomeAssistant, requests_mock: requests_mock.Mocker
|
|
|
|
) -> None:
|
2020-10-06 12:34:39 +00:00
|
|
|
"""Test pushbullet push to default target."""
|
|
|
|
requests_mock.register_uri(
|
|
|
|
"POST",
|
|
|
|
"https://api.pushbullet.com/v2/pushes",
|
2021-10-23 18:56:30 +00:00
|
|
|
status_code=HTTPStatus.OK,
|
2020-10-06 12:34:39 +00:00
|
|
|
json={"mock_response": "Ok"},
|
|
|
|
)
|
2022-11-02 15:11:44 +00:00
|
|
|
entry = MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
data=MOCK_CONFIG,
|
|
|
|
)
|
|
|
|
entry.add_to_hass(hass)
|
|
|
|
assert await hass.config_entries.async_setup(entry.entry_id)
|
2022-11-26 18:01:22 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-10-06 12:34:39 +00:00
|
|
|
data = {
|
|
|
|
"title": "Test Title",
|
|
|
|
"message": "Test Message",
|
|
|
|
"target": ["device/DESKTOP", "email/user@host.net"],
|
|
|
|
}
|
2022-11-26 18:01:22 +00:00
|
|
|
|
2022-11-02 15:11:44 +00:00
|
|
|
await hass.services.async_call(NOTIFY_DOMAIN, "pushbullet", data)
|
2020-10-06 12:34:39 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
expected_body = {
|
|
|
|
"body": "Test Message",
|
|
|
|
"device_iden": "identity1",
|
|
|
|
"title": "Test Title",
|
|
|
|
"type": "note",
|
|
|
|
}
|
2022-11-02 15:11:44 +00:00
|
|
|
assert requests_mock.request_history[-2].json() == expected_body
|
2020-10-06 12:34:39 +00:00
|
|
|
expected_body = {
|
|
|
|
"body": "Test Message",
|
|
|
|
"email": "user@host.net",
|
|
|
|
"title": "Test Title",
|
|
|
|
"type": "note",
|
|
|
|
}
|
2022-11-02 15:11:44 +00:00
|
|
|
assert requests_mock.request_history[-1].json() == expected_body
|