Skip to content

Commit bb0d76a

Browse files
committed
tests
1 parent fe94fc3 commit bb0d76a

File tree

1 file changed

+63
-2
lines changed

1 file changed

+63
-2
lines changed

tests/components/ntfy/test_services.py

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import Any
44

5-
from aiontfy import Message
5+
from aiontfy import BroadcastAction, HttpAction, Message, ViewAction
66
from aiontfy.exceptions import (
77
NtfyException,
88
NtfyHTTPError,
@@ -15,14 +15,17 @@
1515
from homeassistant.components.ntfy.const import DOMAIN
1616
from homeassistant.components.ntfy.notify import (
1717
ATTR_ATTACH,
18+
ATTR_BROADCAST,
1819
ATTR_CALL,
1920
ATTR_CLICK,
2021
ATTR_DELAY,
2122
ATTR_EMAIL,
23+
ATTR_HTTP,
2224
ATTR_ICON,
2325
ATTR_MARKDOWN,
2426
ATTR_PRIORITY,
2527
ATTR_TAGS,
28+
ATTR_VIEW,
2629
SERVICE_PUBLISH,
2730
)
2831
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
@@ -60,6 +63,32 @@ async def test_ntfy_publish(
6063
ATTR_MARKDOWN: True,
6164
ATTR_PRIORITY: "5",
6265
ATTR_TAGS: ["partying_face", "grin"],
66+
ATTR_HTTP: [
67+
{
68+
"label": "Close door",
69+
"url": "https://api.example.local/",
70+
"method": "PUT",
71+
"headers": {"Authorization": "Bearer ..."},
72+
"clear": False,
73+
}
74+
],
75+
ATTR_VIEW: [
76+
{
77+
"label": "Open website",
78+
"url": "https://example.com",
79+
"position": 3,
80+
"clear": False,
81+
}
82+
],
83+
ATTR_BROADCAST: [
84+
{
85+
"label": "Take picture",
86+
"intent": "com.example.AN_INTENT",
87+
"extras": {"cmd": "pic"},
88+
"position": 1,
89+
"clear": True,
90+
}
91+
],
6392
},
6493
blocking=True,
6594
)
@@ -76,6 +105,27 @@ async def test_ntfy_publish(
76105
markdown=True,
77106
icon=URL("https://example.org/logo.png"),
78107
delay="86430.0s",
108+
actions=[
109+
BroadcastAction(
110+
label="Take picture",
111+
intent="com.example.AN_INTENT",
112+
extras={"cmd": "pic"},
113+
clear=True,
114+
),
115+
ViewAction(
116+
label="Open website",
117+
url="https://example.com",
118+
clear=False,
119+
),
120+
HttpAction(
121+
label="Close door",
122+
url="https://api.example.local/",
123+
method="PUT",
124+
headers={"Authorization": "Bearer ..."},
125+
body=None,
126+
clear=False,
127+
),
128+
],
79129
)
80130
)
81131

@@ -142,12 +192,23 @@ async def test_send_message_exception(
142192
{ATTR_DELAY: {"days": 1, "seconds": 30}, ATTR_EMAIL: "[email protected]"},
143193
"Delayed email notifications are not supported",
144194
),
195+
(
196+
{
197+
ATTR_BROADCAST: [
198+
{"label": "1"},
199+
{"label": "2"},
200+
{"label": "3"},
201+
{"label": "4"},
202+
],
203+
},
204+
"Too many actions defined. Only 3 allowed",
205+
),
145206
],
146207
)
208+
@pytest.mark.usefixtures("mock_aiontfy")
147209
async def test_send_message_validation_errors(
148210
hass: HomeAssistant,
149211
config_entry: MockConfigEntry,
150-
mock_aiontfy: AsyncMock,
151212
payload: dict[str, Any],
152213
error_msg: str,
153214
) -> None:

0 commit comments

Comments
 (0)