Debian Codegraph @

tests/test_plugin_smseagle.py

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