Debian Codegraph @

tests/test_plugin_smseagle.py

raw
1 # BSD 2-Clause License
2 #
3 # Apprise - Push Notification Library.
4 # Copyright (c) 2026, Chris Caron <[email protected]>
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # 1. Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 #
12 # 2. Redistributions in binary form must reproduce the above copyright notice,
13 # this list of conditions and the following disclaimer in the documentation
14 # and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 # POSSIBILITY OF SUCH DAMAGE.
27
28 from json import dumps, loads
29
30 # Disable logging for a cleaner testing output
31 import logging
32 import os
33 from unittest import mock
34
35 from helpers import AppriseURLTester
36 import requests
37
38 from apprise import Apprise, AppriseAttachment, NotifyType
39 from apprise.exception import AppriseImproperlyConfigured
40 from apprise.plugins.base import _delivery_tracker
41 from apprise.plugins.smseagle import NotifySMSEagle
42
43 logging.disable(logging.CRITICAL)
44
45 SMSEAGLE_GOOD_RESPONSE = dumps(
46 {"result": {"message_id": "748", "status": "ok"}}
47 )
48
49 SMSEAGLE_BAD_RESPONSE = dumps(
50 {
51 "result": {
52 "error_text": "Wrong parameters",
53 "status": "error",
54 }
55 }
56 )
57
58
59 @mock.patch("requests.post")
60 def test_plugin_smseagle_tracking_separates_categories(mock_post):
61 """Equal batch positions in different categories remain independent."""
62
63 response = requests.Request()
64 response.status_code = requests.codes.ok
65 response.content = SMSEAGLE_GOOD_RESPONSE
66 mock_post.return_value = response
67
68 obj = Apprise.instantiate(
69 "smseagle://token@localhost/12512222222/@contact/%23group"
70 )
71 assert isinstance(obj, NotifySMSEagle)
72
73 tracker_token = _delivery_tracker.set(set())
74 try:
75 assert obj.send(body="test") is True
76 finally:
77 _delivery_tracker.reset(tracker_token)
78
79 assert mock_post.call_count == 3
80
81
82 # Attachment Directory
83 TEST_VAR_DIR = os.path.join(os.path.dirname(__file__), "var")
84
85 # Our Testing URLs
86 apprise_url_tests = (
87 (
88 "smseagle://",
89 {
90 # No host specified
91 "instance": AppriseImproperlyConfigured,
92 },
93 ),
94 (
95 "smseagle://:@/",
96 {
97 # invalid host
98 "instance": AppriseImproperlyConfigured,
99 },
100 ),
101 (
102 "smseagle://localhost",
103 {
104 # Just a host provided (no access token)
105 "instance": AppriseImproperlyConfigured,
106 },
107 ),
108 (
109 "smseagle://%20@localhost",
110 {
111 # invalid token
112 "instance": AppriseImproperlyConfigured,
113 },
114 ),
115 (
116 "smseagle://token@localhost/123/",
117 {
118 # invalid 'to' phone number
119 "instance": NotifySMSEagle,
120 # Notify will fail because it couldn't send to anyone
121 "response": False,
122 # Our expected url(privacy=True) startswith() response:
123 "privacy_url": "smseagle://****@localhost/@123",
124 # Our response expected server response
125 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
126 },
127 ),
128 (
129 "smseagle://tokenb@localhost/%20/%20/",
130 {
131 # invalid 'to' phone number
132 "instance": NotifySMSEagle,
133 # Notify will fail because it couldn't send to anyone
134 "notify_response": False,
135 # Our expected url(privacy=True) startswith() response:
136 "privacy_url": "smseagle://****@localhost/",
137 # Our response expected server response
138 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
139 },
140 ),
141 (
142 "smseagle://token@localhost:8080/{}/".format("1" * 11),
143 {
144 # one phone number will notify ourselves
145 "instance": NotifySMSEagle,
146 # Our response expected server response
147 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
148 },
149 ),
150 (
151 "smseagle://localhost:8080/{}/?token=abc1234".format("1" * 11),
152 {
153 # pass our token in as an argument
154 "instance": NotifySMSEagle,
155 # Our response expected server response
156 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
157 "force_debug": True,
158 },
159 ),
160 # Set priority
161 (
162 "smseagle://token@localhost/@user/?priority=high",
163 {
164 "instance": NotifySMSEagle,
165 # Our response expected server response
166 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
167 },
168 ),
169 # Support integer value too
170 (
171 "smseagle://token@localhost/@user/?priority=1",
172 {
173 "instance": NotifySMSEagle,
174 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
175 },
176 ),
177 # Invalid priority
178 (
179 "smseagle://token@localhost/@user/?priority=invalid",
180 {
181 # Invalid Priority
182 "instance": AppriseImproperlyConfigured,
183 },
184 ),
185 # Invalid priority
186 (
187 "smseagle://token@localhost/@user/?priority=25",
188 {
189 # Invalid Priority
190 "instance": AppriseImproperlyConfigured,
191 },
192 ),
193 (
194 "smseagle://token@localhost:8082/#abcd/",
195 {
196 # a valid group
197 "instance": NotifySMSEagle,
198 # Our expected url(privacy=True) startswith() response:
199 "privacy_url": "smseagle://****@localhost:8082/#abcd",
200 # Our response expected server response
201 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
202 },
203 ),
204 (
205 "smseagle://token@localhost:8082/@abcd/",
206 {
207 # a valid contact
208 "instance": NotifySMSEagle,
209 # Our expected url(privacy=True) startswith() response:
210 "privacy_url": "smseagle://****@localhost:8082/@abcd",
211 # Our response expected server response
212 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
213 },
214 ),
215 (
216 "smseagles://token@localhost:8081/contact/",
217 {
218 # another valid group (without @ symbol)
219 "instance": NotifySMSEagle,
220 # Our expected url(privacy=True) startswith() response:
221 "privacy_url": "smseagles://****@localhost:8081/@contact",
222 # Our response expected server response
223 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
224 },
225 ),
226 (
227 "smseagle://token@localhost:8082/@/#/,/",
228 {
229 # Test case where we provide bad data
230 "instance": NotifySMSEagle,
231 # Our failed response
232 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
233 # as a result, we expect a failed notification
234 "response": False,
235 },
236 ),
237 (
238 "smseagle://token@localhost:8083/@user/",
239 {
240 # Test case where we get a bad response
241 "instance": NotifySMSEagle,
242 # Our expected url(privacy=True) startswith() response:
243 "privacy_url": "smseagle://****@localhost:8083/@user",
244 # Our failed response
245 "requests_response_text": SMSEAGLE_BAD_RESPONSE,
246 # as a result, we expect a failed notification
247 "response": False,
248 },
249 ),
250 (
251 "smseagle://token@localhost:8084/@user/",
252 {
253 # Test case where we get a bad response
254 "instance": NotifySMSEagle,
255 # Our expected url(privacy=True) startswith() response:
256 "privacy_url": "smseagle://****@localhost:8084/@user",
257 # Our failed response
258 "requests_response_text": None,
259 # as a result, we expect a failed notification
260 "response": False,
261 },
262 ),
263 (
264 "smseagle://token@localhost:8085/@user/",
265 {
266 # Test case where we get a bad response
267 "instance": NotifySMSEagle,
268 # Our expected url(privacy=True) startswith() response:
269 "privacy_url": "smseagle://****@localhost:8085/@user",
270 # Our failed response (bad json)
271 "requests_response_text": "{",
272 # as a result, we expect a failed notification
273 "response": False,
274 },
275 ),
276 (
277 "smseagle://token@localhost:8086/?to={},{}".format("2" * 11, "3" * 11),
278 {
279 # use get args to acomplish the same thing
280 "instance": NotifySMSEagle,
281 # Our response expected server response
282 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
283 },
284 ),
285 (
286 "smseagle://token@localhost:8087/?to={},{},{}".format(
287 "2" * 11, "3" * 11, "5" * 3
288 ),
289 {
290 # 2 good targets and one invalid one
291 "instance": NotifySMSEagle,
292 # Our response expected server response
293 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
294 },
295 ),
296 (
297 "smseagle://token@localhost:8088/{}/{}/".format("2" * 11, "3" * 11),
298 {
299 # If we have from= specified, then all elements take on the
300 # to= value
301 "instance": NotifySMSEagle,
302 # Our response expected server response
303 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
304 },
305 ),
306 (
307 "smseagles://token@localhost/{}".format("3" * 11),
308 {
309 # use get args to acomplish the same thing (use source instead of
310 # from)
311 "instance": NotifySMSEagle,
312 # Our response expected server response
313 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
314 },
315 ),
316 (
317 "smseagles://token@localhost/{}/{}?batch=True".format(
318 "3" * 11, "4" * 11
319 ),
320 {
321 # test batch mode
322 "instance": NotifySMSEagle,
323 # Our response expected server response
324 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
325 },
326 ),
327 (
328 "smseagles://token@localhost/{}/?flash=yes".format("3" * 11),
329 {
330 # test flash mode
331 "instance": NotifySMSEagle,
332 # Our response expected server response
333 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
334 },
335 ),
336 (
337 "smseagles://token@localhost/{}/?test=yes".format("3" * 11),
338 {
339 # test mode
340 "instance": NotifySMSEagle,
341 # Our response expected server response
342 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
343 },
344 ),
345 (
346 "smseagles://token@localhost/{}/{}?status=True".format(
347 "3" * 11, "4" * 11
348 ),
349 {
350 # test status switch
351 "instance": NotifySMSEagle,
352 # Our response expected server response
353 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
354 },
355 ),
356 (
357 "smseagle://token@localhost/{}".format("4" * 11),
358 {
359 "instance": NotifySMSEagle,
360 # throw a bizarre code forcing us to fail to look it up
361 "response": False,
362 "requests_response_code": 999,
363 # Our response expected server response
364 "requests_response_text": SMSEAGLE_GOOD_RESPONSE,
365 },
366 ),
367 (
368 "smseagle://token@localhost/{}".format("4" * 11),
369 {
370 "instance": NotifySMSEagle,
371 # Throws a series of i/o exceptions with this flag
372 # is set and tests that we gracefully handle them
373 "test_requests_exceptions": True,
374 },
375 ),
376 )
377
378
379 def test_plugin_smseagle_urls():
380 """NotifySMSEagle() Apprise URLs."""
381
382 # Run our general tests
383 AppriseURLTester(tests=apprise_url_tests).run_all()
384
385
386 @mock.patch("requests.post")
387 def test_plugin_smseagle_edge_cases(mock_post):
388 """NotifySMSEagle() Edge Cases."""
389
390 # Prepare our response
391 response = requests.Request()
392 response.status_code = requests.codes.ok
393 response.content = SMSEAGLE_GOOD_RESPONSE
394
395 # Prepare Mock
396 mock_post.return_value = response
397
398 # Initialize some generic (but valid) tokens
399 target = "+1 (555) 987-5432"
400 body = "test body"
401 title = "My Title"
402
403 aobj = Apprise()
404 assert aobj.add(f"smseagles://token@localhost:231/{target}")
405 assert len(aobj) == 1
406 assert aobj.notify(title=title, body=body)
407 assert mock_post.call_count == 1
408
409 details = mock_post.call_args_list[0]
410 assert details[0][0] == "https://localhost:231/jsonrpc/sms"
411 payload = loads(details[1]["data"])
412 assert payload["params"]["message"] == "My Title\r\ntest body"
413
414 # Reset our mock object
415 mock_post.reset_mock()
416
417 aobj = Apprise()
418 assert aobj.add(f"smseagles://token@localhost:231/{target}?status=Yes")
419 assert len(aobj) == 1
420 assert aobj.notify(title=title, body=body)
421 assert mock_post.call_count == 1
422
423 details = mock_post.call_args_list[0]
424 assert details[0][0] == "https://localhost:231/jsonrpc/sms"
425 payload = loads(details[1]["data"])
426 # Status flag is set
427 assert payload["params"]["message"] == "[i] My Title\r\ntest body"
428
429
430 @mock.patch("requests.post")
431 def test_plugin_smseagle_result_set(mock_post):
432 """NotifySMSEagle() Result Sets."""
433
434 # Prepare our response
435 response = requests.Request()
436 response.status_code = requests.codes.ok
437 response.content = SMSEAGLE_GOOD_RESPONSE
438
439 # Prepare Mock
440 mock_post.return_value = response
441
442 body = "test body"
443 title = "My Title"
444
445 aobj = Apprise()
446 aobj.add(
447 "smseagle://[email protected]:8080/+12512222222/+12513333333/"
448 "12514444444?batch=yes"
449 )
450 # In a batch mode we can shove them all into 1 call
451 assert len(aobj[0]) == 1
452
453 assert aobj.notify(title=title, body=body)
454
455 # If a batch, there is only 1 post
456 assert mock_post.call_count == 1
457
458 details = mock_post.call_args_list[0]
459 assert details[0][0] == "http://10.0.0.112:8080/jsonrpc/sms"
460 payload = loads(details[1]["data"])
461 assert "method" in payload
462 assert payload["method"] == "sms.send_sms"
463
464 assert "params" in payload
465 assert isinstance(payload["params"], dict)
466 params = payload["params"]
467 assert "to" in params
468 assert len(params["to"].split(",")) == 3
469
470 assert "+12512222222" in params["to"].split(",")
471 assert "+12513333333" in params["to"].split(",")
472 # The + is not appended
473 assert "12514444444" in params["to"].split(",")
474 assert params.get("message_type") == "sms"
475 assert params.get("responsetype") == "extended"
476 assert params.get("access_token") == "token"
477 assert params.get("highpriority") == 0
478 assert params.get("flash") == 0
479 assert params.get("test") == 0
480 assert params.get("unicode") == 1
481 assert params.get("message") == "My Title\r\ntest body"
482
483 # Reset our test and turn batch mode off
484 mock_post.reset_mock()
485
486 aobj = Apprise()
487 aobj.add(
488 "smseagle://[email protected]:8080/#group/Contact/123456789?batch=no"
489 )
490 assert len(aobj[0]) == 3
491
492 assert aobj.notify(title=title, body=body)
493
494 # If batch is off then there is a post per entry
495 assert mock_post.call_count == 3
496
497 details = mock_post.call_args_list[0]
498 assert details[0][0] == "http://10.0.0.112:8080/jsonrpc/sms"
499 payload = loads(details[1]["data"])
500 assert payload["method"] == "sms.send_sms"
501
502 assert "params" in payload
503 assert isinstance(payload["params"], dict)
504 params = payload["params"]
505 assert "to" in params
506 assert len(params["to"].split(",")) == 1
507 assert "123456789" in params["to"].split(",")
508
509 assert params.get("message_type") == "sms"
510 assert params.get("responsetype") == "extended"
511 assert params.get("access_token") == "token"
512 assert params.get("highpriority") == 0
513 assert params.get("flash") == 0
514 assert params.get("test") == 0
515 assert params.get("unicode") == 1
516 assert params.get("message") == "My Title\r\ntest body"
517
518 details = mock_post.call_args_list[1]
519 assert details[0][0] == "http://10.0.0.112:8080/jsonrpc/sms"
520 payload = loads(details[1]["data"])
521 assert payload["method"] == "sms.send_togroup"
522
523 assert "params" in payload
524 assert isinstance(payload["params"], dict)
525 params = payload["params"]
526 assert "groupname" in params
527 assert len(params["groupname"].split(",")) == 1
528 assert "group" in params["groupname"].split(",")
529
530 assert params.get("message_type") == "sms"
531 assert params.get("responsetype") == "extended"
532 assert params.get("access_token") == "token"
533 assert params.get("highpriority") == 0
534 assert params.get("flash") == 0
535 assert params.get("test") == 0
536 assert params.get("unicode") == 1
537 assert params.get("message") == "My Title\r\ntest body"
538
539 details = mock_post.call_args_list[2]
540 assert details[0][0] == "http://10.0.0.112:8080/jsonrpc/sms"
541 payload = loads(details[1]["data"])
542 assert payload["method"] == "sms.send_tocontact"
543
544 assert "params" in payload
545 assert isinstance(payload["params"], dict)
546 params = payload["params"]
547 assert "contactname" in params
548 assert len(params["contactname"].split(",")) == 1
549 assert "Contact" in params["contactname"].split(",")
550
551 assert params.get("message_type") == "sms"
552 assert params.get("responsetype") == "extended"
553 assert params.get("access_token") == "token"
554 assert params.get("highpriority") == 0
555 assert params.get("flash") == 0
556 assert params.get("test") == 0
557 assert params.get("unicode") == 1
558 assert params.get("message") == "My Title\r\ntest body"
559
560 mock_post.reset_mock()
561
562 # Test groups and contact names
563 aobj = Apprise()
564 aobj.add(
565 "smseagle://[email protected]:8080/513333333/#group1/@contact1/"
566 "contact2/12514444444?batch=yes"
567 )
568
569 # contacts and numbers can be combined and is calculated in batch response
570 assert len(aobj[0]) == 3
571 assert aobj.notify(title=title, body=body)
572
573 # There is a unique post to each (group, contact x2, and phone x2)
574 # The key is the contacts were grouped here in 1 post each
575 assert mock_post.call_count == 3
576
577 details = mock_post.call_args_list[0]
578 assert details[0][0] == "http://10.0.0.112:8080/jsonrpc/sms"
579 payload = loads(details[1]["data"])
580 assert payload["method"] == "sms.send_sms"
581
582 assert "params" in payload
583 assert isinstance(payload["params"], dict)
584 params = payload["params"]
585 assert "to" in params
586 assert len(params["to"].split(",")) == 2
587 assert "513333333" in params["to"].split(",")
588 assert "12514444444" in params["to"].split(",")
589
590 assert params.get("message_type") == "sms"
591 assert params.get("responsetype") == "extended"
592 assert params.get("access_token") == "token"
593 assert params.get("highpriority") == 0
594 assert params.get("flash") == 0
595 assert params.get("test") == 0
596 assert params.get("unicode") == 1
597 assert params.get("message") == "My Title\r\ntest body"
598
599 details = mock_post.call_args_list[1]
600 assert details[0][0] == "http://10.0.0.112:8080/jsonrpc/sms"
601 payload = loads(details[1]["data"])
602 assert payload["method"] == "sms.send_togroup"
603
604 assert "params" in payload
605 assert isinstance(payload["params"], dict)
606 params = payload["params"]
607 assert "groupname" in params
608 assert len(params["groupname"].split(",")) == 1
609 assert "group1" in params["groupname"].split(",")
610
611 assert params.get("message_type") == "sms"
612 assert params.get("responsetype") == "extended"
613 assert params.get("access_token") == "token"
614 assert params.get("highpriority") == 0
615 assert params.get("flash") == 0
616 assert params.get("test") == 0
617 assert params.get("unicode") == 1
618 assert params.get("message") == "My Title\r\ntest body"
619
620 details = mock_post.call_args_list[2]
621 assert details[0][0] == "http://10.0.0.112:8080/jsonrpc/sms"
622 payload = loads(details[1]["data"])
623 assert payload["method"] == "sms.send_tocontact"
624
625 assert "params" in payload
626 assert isinstance(payload["params"], dict)
627 params = payload["params"]
628 assert "contactname" in params
629 assert len(params["contactname"].split(",")) == 2
630 assert "contact1" in params["contactname"].split(",")
631 assert "contact2" in params["contactname"].split(",")
632
633 assert params.get("message_type") == "sms"
634 assert params.get("responsetype") == "extended"
635 assert params.get("access_token") == "token"
636 assert params.get("highpriority") == 0
637 assert params.get("flash") == 0
638 assert params.get("test") == 0
639 assert params.get("unicode") == 1
640 assert params.get("message") == "My Title\r\ntest body"
641
642 # Validate our information is also placed back into the assembled URL
643 assert "/@contact1" in aobj[0].url()
644 assert "/@contact2" in aobj[0].url()
645 assert "/#group1" in aobj[0].url()
646 assert "/513333333" in aobj[0].url()
647 assert "/12514444444" in aobj[0].url()
648
649
650 @mock.patch("requests.post")
651 def test_notify_smseagle_plugin_result_list(mock_post):
652 """NotifySMSEagle() Result List Response."""
653
654 okay_response = requests.Request()
655 okay_response.status_code = requests.codes.ok
656 # We want to test the case where the `result` set returned is a list
657 okay_response.content = dumps(
658 {"result": [{"message_id": "748", "status": "ok"}]}
659 )
660
661 # Assign our mock object our return value
662 mock_post.return_value = okay_response
663
664 obj = Apprise.instantiate("smseagle://[email protected]/12222222/")
665 assert isinstance(obj, NotifySMSEagle)
666
667 # We should successfully handle the list
668 assert bool(obj.notify("test")) is True
669
670 # However if one of the elements in the list is bad
671 okay_response.content = dumps(
672 {
673 "result": [
674 {"message_id": "748", "status": "ok"},
675 {"message_id": "749", "status": "error"},
676 ]
677 }
678 )
679
680 # Assign our mock object our return value
681 mock_post.return_value = okay_response
682
683 # We should now fail
684 assert bool(obj.notify("test")) is False
685
686
687 @mock.patch("requests.post")
688 def test_notify_smseagle_plugin_attachments(mock_post):
689 """NotifySMSEagle() Attachments."""
690
691 okay_response = requests.Request()
692 okay_response.status_code = requests.codes.ok
693 okay_response.content = SMSEAGLE_GOOD_RESPONSE
694
695 # Assign our mock object our return value
696 mock_post.return_value = okay_response
697
698 obj = Apprise.instantiate(
699 "smseagle://[email protected]:8080/+12512222222/+12513333333/"
700 "12514444444?batch=no"
701 )
702 assert isinstance(obj, NotifySMSEagle)
703
704 # Test Valid Attachment
705 path = os.path.join(TEST_VAR_DIR, "apprise-test.gif")
706 attach = AppriseAttachment(path)
707 assert (
708 bool(
709 obj.notify(
710 body="body",
711 title="title",
712 notify_type=NotifyType.INFO,
713 attach=attach,
714 )
715 )
716 is True
717 )
718
719 # Test invalid attachment
720 path = os.path.join(TEST_VAR_DIR, "/invalid/path/to/an/invalid/file.jpg")
721 assert (
722 bool(
723 obj.notify(
724 body="body",
725 title="title",
726 notify_type=NotifyType.INFO,
727 attach=path,
728 )
729 )
730 is False
731 )
732
733 path = (
734 os.path.join(TEST_VAR_DIR, "apprise-test.gif"),
735 os.path.join(TEST_VAR_DIR, "apprise-test.gif"),
736 os.path.join(TEST_VAR_DIR, "apprise-test.gif"),
737 )
738 attach = AppriseAttachment(path)
739
740 # Return our good configuration
741 mock_post.side_effect = None
742 mock_post.return_value = okay_response
743 with mock.patch("builtins.open", side_effect=OSError()):
744 # We can't send the message we can't open the attachment for reading
745 assert (
746 bool(
747 obj.notify(
748 body="body",
749 title="title",
750 notify_type=NotifyType.INFO,
751 attach=attach,
752 )
753 )
754 is False
755 )
756
757 # test the handling of our batch modes
758 obj = Apprise.instantiate(
759 "smseagle://[email protected]:8080/+12512222222/+12513333333/"
760 "12514444444?batch=yes"
761 )
762 assert isinstance(obj, NotifySMSEagle)
763
764 # Now send an attachment normally without issues
765 mock_post.reset_mock()
766 assert (
767 bool(
768 obj.notify(
769 body="body",
770 title="title",
771 notify_type=NotifyType.INFO,
772 attach=attach,
773 )
774 )
775 is True
776 )
777
778 # Verify we posted upstream
779 assert mock_post.call_count == 1
780
781 details = mock_post.call_args_list[0]
782 assert details[0][0] == "http://10.0.0.112:8080/jsonrpc/sms"
783 payload = loads(details[1]["data"])
784 assert payload["method"] == "sms.send_sms"
785
786 assert "params" in payload
787 assert isinstance(payload["params"], dict)
788 params = payload["params"]
789 assert "to" in params
790 assert len(params["to"].split(",")) == 3
791 assert "+12512222222" in params["to"].split(",")
792 assert "+12513333333" in params["to"].split(",")
793 assert "12514444444" in params["to"].split(",")
794
795 assert params.get("message_type") == "mms"
796 assert params.get("responsetype") == "extended"
797 assert params.get("access_token") == "token"
798 assert params.get("highpriority") == 0
799 assert params.get("flash") == 0
800 assert params.get("test") == 0
801 assert params.get("unicode") == 1
802 assert params.get("message") == "title\r\nbody"
803
804 # Verify our attachments are in place
805 assert "attachments" in params
806 assert isinstance(params["attachments"], list)
807 assert len(params["attachments"]) == 3
808 for entry in params["attachments"]:
809 assert "content" in entry
810 assert "content_type" in entry
811 assert entry.get("content_type").startswith("image/")
812
813 # Reset our mock object
814 mock_post.reset_mock()
815
816 # test the handling of our batch modes
817 obj = Apprise.instantiate("smseagle://[email protected]:8080/513333333/")
818 assert isinstance(obj, NotifySMSEagle)
819
820 # Unsupported (non image types are not sent)
821 attach = os.path.join(TEST_VAR_DIR, "apprise-test.mp4")
822 assert (
823 bool(
824 obj.notify(
825 body="body",
826 title="title",
827 notify_type=NotifyType.INFO,
828 attach=attach,
829 )
830 )
831 is True
832 )
833
834 # Verify we still posted upstream
835 assert mock_post.call_count == 1
836
837 details = mock_post.call_args_list[0]
838 assert details[0][0] == "http://10.0.0.112:8080/jsonrpc/sms"
839 payload = loads(details[1]["data"])
840 assert payload["method"] == "sms.send_sms"
841
842 assert "params" in payload
843 assert isinstance(payload["params"], dict)
844 params = payload["params"]
845 assert "to" in params
846 assert len(params["to"].split(",")) == 1
847 assert "513333333" in params["to"].split(",")
848
849 assert params.get("message_type") == "sms"
850 assert params.get("responsetype") == "extended"
851 assert params.get("access_token") == "token"
852 assert params.get("highpriority") == 0
853 assert params.get("flash") == 0
854 assert params.get("test") == 0
855 assert params.get("unicode") == 1
856 assert params.get("message") == "title\r\nbody"
857
858 # No attachments were added
859 assert "attachments" not in params