From 265f622e759a63076d99f064f77cc3fb14ff80ea Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Mon, 5 Dec 2022 20:49:08 +0100 Subject: [PATCH] Notification - Support for standard API calls post:// posts:// get:// gets:// delete:// deletes:// put:// puts:// (#1194) --- .../tests/test_element_removal.py | 2 +- changedetectionio/tests/test_errorhandling.py | 3 +- changedetectionio/tests/test_ignore_text.py | 6 --- changedetectionio/tests/test_notification.py | 40 ++++--------------- 4 files changed, 11 insertions(+), 40 deletions(-) diff --git a/changedetectionio/tests/test_element_removal.py b/changedetectionio/tests/test_element_removal.py index 3e384b77..6b3842f4 100644 --- a/changedetectionio/tests/test_element_removal.py +++ b/changedetectionio/tests/test_element_removal.py @@ -121,7 +121,7 @@ def test_element_removal_full(client, live_server): url_for("import_page"), data={"urls": test_url}, follow_redirects=True ) assert b"1 Imported" in res.data - + time.sleep(1) # Goto the edit page, add the filter data # Not sure why \r needs to be added - absent of the #changetext this is not necessary subtractive_selectors_data = "header\r\nfooter\r\nnav\r\n#changetext" diff --git a/changedetectionio/tests/test_errorhandling.py b/changedetectionio/tests/test_errorhandling.py index a8b29863..3f8e9c9c 100644 --- a/changedetectionio/tests/test_errorhandling.py +++ b/changedetectionio/tests/test_errorhandling.py @@ -77,7 +77,8 @@ def test_DNS_errors(client, live_server): time.sleep(3) res = client.get(url_for("index")) - assert b'Name or service not known' in res.data + found_name_resolution_error = b"Temporary failure in name resolution" in res.data or b"Name or service not known" in res.data + assert found_name_resolution_error # Should always record that we tried assert bytes("just now".encode('utf-8')) in res.data diff --git a/changedetectionio/tests/test_ignore_text.py b/changedetectionio/tests/test_ignore_text.py index 89f89eb5..1a393717 100644 --- a/changedetectionio/tests/test_ignore_text.py +++ b/changedetectionio/tests/test_ignore_text.py @@ -101,9 +101,6 @@ def test_check_ignore_text_functionality(client, live_server): ) assert b"1 Imported" in res.data - # Trigger a check - client.get(url_for("form_watch_checknow"), follow_redirects=True) - # Give the thread time to pick it up time.sleep(sleep_time_for_fetch_thread) @@ -199,9 +196,6 @@ def test_check_global_ignore_text_functionality(client, live_server): ) assert b"1 Imported" in res.data - # Trigger a check - client.get(url_for("form_watch_checknow"), follow_redirects=True) - # Give the thread time to pick it up time.sleep(sleep_time_for_fetch_thread) diff --git a/changedetectionio/tests/test_notification.py b/changedetectionio/tests/test_notification.py index f1ab4b0d..596add56 100644 --- a/changedetectionio/tests/test_notification.py +++ b/changedetectionio/tests/test_notification.py @@ -237,6 +237,7 @@ def test_check_notification(client, live_server): ) def test_notification_validation(client, live_server): + time.sleep(1) # re #242 - when you edited an existing new entry, it would not correctly show the notification settings @@ -266,43 +267,15 @@ def test_notification_validation(client, live_server): # ) # assert b"Notification Body and Title is required when a Notification URL is used" in res.data - # Now adding a wrong token should give us an error -# Disabled for now -# res = client.post( -# url_for("settings_page"), -# data={"application-notification_title": "New ChangeDetection.io Notification - {{watch_url}}", -# "application-notification_body": "Rubbish: {{rubbish}}\n", -# "application-notification_format": "Text", -# "application-notification_urls": "json://localhost/foobar", -# "requests-time_between_check-minutes": 180, -# "fetch_backend": "html_requests" -# }, -# follow_redirects=True -# ) -# assert bytes("Token 'rubbish' is not a valid token or is unknown".encode('utf-8')) in res.data - - # And trying to define an invalid Jinja2 template should also throw an error - res = client.post( - url_for("settings_page"), - data={"application-notification_title": "New ChangeDetection.io Notification - {{ watch_url }}", - "application-notification_body": "Rubbish: {{ rubbish }\n", - "application-notification_urls": "json://foobar.com", - "application-minutes_between_check": 180, - "application-fetch_backend": "html_requests" - }, - follow_redirects=True - ) - assert bytes("This is not a valid Jinja2 template".encode('utf-8')) in res.data - - # cleanup for the next client.get( url_for("form_delete", uuid="all"), follow_redirects=True ) -def test_notification_jinja2(client, live_server): - #live_server_setup(live_server) + + +def test_notification_custom_endpoint_and_jinja2(client, live_server): time.sleep(1) # test_endpoint - that sends the contents of a file @@ -341,6 +314,7 @@ def test_notification_jinja2(client, live_server): client.get(url_for("form_watch_checknow"), follow_redirects=True) time.sleep(2) + with open("test-datastore/notification.txt", 'r') as f: x=f.read() j = json.loads(x) @@ -352,4 +326,6 @@ def test_notification_jinja2(client, live_server): with open("test-datastore/notification-url.txt", 'r') as f: notification_url = f.read() assert 'xxx=http' in notification_url - os.unlink("test-datastore/notification-url.txt") \ No newline at end of file + + os.unlink("test-datastore/notification-url.txt") +