2
0
Эх сурвалжийг харах

raise ValueError on priprity 2 with retry or expire

Antonio Fernandez 7 сар өмнө
parent
commit
a939a66fb4

+ 4 - 2
borgmatic/hooks/pushover.py

@@ -45,8 +45,10 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
             logger.info(f'{config_filename}: Setting retry to default (30sec).')
             state_config['retry'] = 30
     else:
-        state_config.pop('expire', None)
-        state_config.pop('retry', None)
+        if 'expire' in state_config or 'retry' in state_config:
+            raise ValueError(
+                'The configuration parameters retry and expire should not be set when priority is not equal to 2. Please remove them from the configuration.'
+            )
 
     state_config = {
         key: (1 if value is True and key in 'html' else value)

+ 4 - 12
tests/unit/hooks/test_pushover.py

@@ -225,8 +225,8 @@ def test_ping_monitor_start_state_backup_default_message_with_priority_high_decl
     '''
     This simulates priority level 1, retry and expiry being set. Since expire
     and retry are only used for priority level 2, they should not be included
-    in the request sent to Pushover. This test verifies that those are
-    stripped from the request.
+    in the request sent to Pushover. This test verifies that a ValueError is
+    raised.
     '''
     hook_config = {
         'token': 'ksdjfwoweijfvwoeifvjmwghagy92',
@@ -234,17 +234,9 @@ def test_ping_monitor_start_state_backup_default_message_with_priority_high_decl
         'states': {'start', 'fail', 'finish'},
         'start': {'priority': 1, 'expire': 30, 'retry': 30},
     }
+
     flexmock(module.logger).should_receive('warning').never()
-    flexmock(module.requests).should_receive('post').with_args(
-        'https://api.pushover.net/1/messages.json',
-        headers={'Content-type': 'application/x-www-form-urlencoded'},
-        data={
-            'token': 'ksdjfwoweijfvwoeifvjmwghagy92',
-            'user': '983hfe0of902lkjfa2amanfgui',
-            'message': 'start',
-            'priority': 1,
-        },
-    ).and_return(flexmock(ok=True)).once()
+    flexmock(module.requests).should_receive('post').never()
 
     module.ping_monitor(
         hook_config,