88from src .email_message import EmailMessage as Message
99from src .notify import (
1010 notify_discord ,
11+ notify_pushover ,
1112 notify_telegram ,
1213 post_message_to_discord ,
14+ post_message_to_pushover ,
1315 post_message_to_telegram ,
1416)
1517
@@ -29,6 +31,7 @@ def setUp(self) -> None:
2931 "password" : "password" ,
3032 },
3133 "telegram" : {"bot_token" : "bot_token" , "chat_id" : "chat_id" },
34+ "pushover" : {"user_key" : "pushover_user_key" , "api_token" : "pushover_api_token" },
3235 },
3336 }
3437 self .message_body = "message body"
@@ -332,3 +335,88 @@ def test_post_message_to_discord_fail(self):
332335 data = {"content" : message , "username" : "username" },
333336 timeout = 10 ,
334337 )
338+
339+ def test_notify_pushover_success (self ):
340+ """Test for successful Pushover notification."""
341+ with patch ("src.notify.post_message_to_pushover" ) as post_message_mock :
342+ notify_pushover (self .config , self .message_body , None , False )
343+
344+ # Verify that post_message_to_pushover is called with the correct arguments
345+ post_message_mock .assert_called_once_with (
346+ self .config ["app" ]["pushover" ]["api_token" ],
347+ self .config ["app" ]["pushover" ]["user_key" ],
348+ self .message_body ,
349+ )
350+
351+ def test_notify_pushover_fail (self ):
352+ """Test for failed Pushover notification."""
353+ with patch ("src.notify.post_message_to_pushover" ) as post_message_mock :
354+ post_message_mock .return_value = False
355+ notify_pushover (self .config , self .message_body , None , False )
356+
357+ # Verify that post_message_to_pushover is called with the correct arguments
358+ post_message_mock .assert_called_once_with (
359+ self .config ["app" ]["pushover" ]["api_token" ],
360+ self .config ["app" ]["pushover" ]["user_key" ],
361+ self .message_body ,
362+ )
363+
364+ def test_notify_pushover_throttling (self ):
365+ """Test for throttled Pushover notification."""
366+ last_send = datetime .datetime .now () - datetime .timedelta (hours = 2 )
367+ dry_run = False
368+
369+ with patch ("src.notify.post_message_to_pushover" ) as post_message_mock :
370+ notify_pushover (self .config , self .message_body , last_send , dry_run )
371+
372+ # Verify that post_message_to_pushover is not called when throttled
373+ post_message_mock .assert_not_called ()
374+
375+ def test_notify_pushover_dry_run (self ):
376+ """Test for dry run mode in Pushover notification."""
377+ last_send = datetime .datetime .now ()
378+ dry_run = True
379+
380+ with patch ("src.notify.post_message_to_pushover" ) as post_message_mock :
381+ notify_pushover (self .config , self .message_body , last_send , dry_run )
382+
383+ # Verify that post_message_to_pushover is not called in dry run mode
384+ post_message_mock .assert_not_called ()
385+
386+ def test_notify_pushover_no_config (self ):
387+ """Test for missing Pushover configuration."""
388+ config = {}
389+ last_send = None
390+ dry_run = False
391+
392+ with patch ("src.notify.post_message_to_pushover" ) as post_message_mock :
393+ notify_pushover (config , self .message_body , last_send , dry_run )
394+
395+ # Verify that post_message_to_pushover is not called when Pushover configuration is missing
396+ post_message_mock .assert_not_called ()
397+
398+ def test_post_message_to_pushover (self ):
399+ """Test for successful post to Pushover."""
400+ with patch ("requests.post" ) as post_mock :
401+ post_mock .return_value .status_code = 200
402+ post_message_to_pushover ("pushover_api_token" , "pushover_user_key" , "message" )
403+
404+ # Verify that post is called with the correct arguments
405+ post_mock .assert_called_once_with (
406+ "https://api.pushover.net/1/messages.json" ,
407+ data = {"token" : "pushover_api_token" , "user" : "pushover_user_key" , "message" : "message" },
408+ timeout = 10 ,
409+ )
410+
411+ def test_post_message_to_pushover_fail (self ):
412+ """Test for failed post to Pushover."""
413+ with patch ("requests.post" ) as post_mock :
414+ post_mock .return_value .status_code = 400
415+ post_message_to_pushover ("pushover_api_token" , "pushover_user_key" , "message" )
416+
417+ # Verify that post is called with the correct arguments
418+ post_mock .assert_called_once_with (
419+ "https://api.pushover.net/1/messages.json" ,
420+ data = {"token" : "pushover_api_token" , "user" : "pushover_user_key" , "message" : "message" },
421+ timeout = 10 ,
422+ )
0 commit comments