From 415896e8380e485afcc45a20e9e7f1e50311c54a Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Fri, 14 Jun 2024 15:31:57 +0200 Subject: [PATCH] Filter failure - reset counter --- changedetectionio/flask_app.py | 4 +++- changedetectionio/model/App.py | 1 + .../tests/test_filter_failure_notification.py | 18 ++++++++---------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/changedetectionio/flask_app.py b/changedetectionio/flask_app.py index 02e041b1..690a1511 100644 --- a/changedetectionio/flask_app.py +++ b/changedetectionio/flask_app.py @@ -679,7 +679,9 @@ def changedetection_app(config=None, datastore_o=None): if request.method == 'POST' and form.validate(): - extra_update_obj = {} + extra_update_obj = { + 'filter_failure_notification_threshold_attempts': 0 + } if request.args.get('unpause_on_save'): extra_update_obj['paused'] = False diff --git a/changedetectionio/model/App.py b/changedetectionio/model/App.py index e412542b..fdd627ed 100644 --- a/changedetectionio/model/App.py +++ b/changedetectionio/model/App.py @@ -5,6 +5,7 @@ from changedetectionio.notification import ( default_notification_title, ) +# Equal to or greater than this number of FilterNotFoundInResponse exceptions will trigger a filter-not-found notification _FILTER_FAILURE_THRESHOLD_ATTEMPTS_DEFAULT = 6 DEFAULT_SETTINGS_HEADERS_USERAGENT='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36' diff --git a/changedetectionio/tests/test_filter_failure_notification.py b/changedetectionio/tests/test_filter_failure_notification.py index b25931ea..5f533ba8 100644 --- a/changedetectionio/tests/test_filter_failure_notification.py +++ b/changedetectionio/tests/test_filter_failure_notification.py @@ -23,8 +23,6 @@ def set_response_with_filter(): def run_filter_test(client, content_filter): - # Give the endpoint time to spin up - time.sleep(1) # cleanup for the next client.get( url_for("form_delete", uuid="all"), @@ -79,6 +77,7 @@ def run_filter_test(client, content_filter): "include_filters": content_filter, "fetch_backend": "html_requests"}) + # A POST here will also reset the filter failure counter (filter_failure_notification_threshold_attempts) res = client.post( url_for("edit_page", uuid="first"), data=notification_form_data, @@ -91,20 +90,21 @@ def run_filter_test(client, content_filter): # Now the notification should not exist, because we didnt reach the threshold assert not os.path.isfile("test-datastore/notification.txt") - # -2 because we would have checked twice above (on adding and on edit) - for i in range(0, App._FILTER_FAILURE_THRESHOLD_ATTEMPTS_DEFAULT-2): - res = client.get(url_for("form_watch_checknow"), follow_redirects=True) + # recheck it up to just before the threshold + for i in range(0, App._FILTER_FAILURE_THRESHOLD_ATTEMPTS_DEFAULT-1): + client.get(url_for("form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) + time.sleep(2) # delay for apprise to fire assert not os.path.isfile("test-datastore/notification.txt"), f"test-datastore/notification.txt should not exist - Attempt {i}" # We should see something in the frontend + res = client.get(url_for("index")) assert b'Warning, no filters were found' in res.data - # One more check should trigger it (see -2 above) - client.get(url_for("form_watch_checknow"), follow_redirects=True) - wait_for_all_checks(client) + # One more check should trigger the _FILTER_FAILURE_THRESHOLD_ATTEMPTS_DEFAULT threshold client.get(url_for("form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) + time.sleep(2) # delay for apprise to fire # Now it should exist and contain our "filter not found" alert assert os.path.isfile("test-datastore/notification.txt") @@ -150,12 +150,10 @@ def test_setup(live_server): def test_check_include_filters_failure_notification(client, live_server): set_original_response() - wait_for_all_checks(client) run_filter_test(client, '#nope-doesnt-exist') def test_check_xpath_filter_failure_notification(client, live_server): set_original_response() - time.sleep(1) run_filter_test(client, '//*[@id="nope-doesnt-exist"]') # Test that notification is never sent