From ab84c6590a70d470e25e892b3d8e0e2caa45be88 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Thu, 9 Oct 2025 18:33:15 +0200 Subject: [PATCH] Test speedup - remove common calls for function calls --- .../test_custom_browser_url.py | 9 +- .../tests/proxy_socks5/test_socks5_proxy.py | 5 +- .../tests/smtp/test_notification_smtp.py | 8 +- .../tests/test_add_replace_remove_filter.py | 27 ++-- changedetectionio/tests/test_api.py | 8 +- changedetectionio/tests/test_auth.py | 8 +- .../test_automatic_follow_ldjson_price.py | 24 +--- changedetectionio/tests/test_backend.py | 38 ++--- .../tests/test_block_while_text_present.py | 13 +- changedetectionio/tests/test_clone.py | 8 +- changedetectionio/tests/test_conditions.py | 29 ++-- changedetectionio/tests/test_css_selector.py | 24 +--- .../tests/test_element_removal.py | 6 +- changedetectionio/tests/test_encoding.py | 14 +- changedetectionio/tests/test_errorhandling.py | 22 +-- changedetectionio/tests/test_extract_regex.py | 29 ++-- .../tests/test_filter_failure_notification.py | 9 +- changedetectionio/tests/test_group.py | 34 ++--- .../tests/test_history_consistency.py | 13 +- changedetectionio/tests/test_ignore.py | 16 +-- changedetectionio/tests/test_ignore_text.py | 24 +--- .../tests/test_ignorehyperlinks.py | 8 +- .../tests/test_ignorestatuscode.py | 16 +-- .../tests/test_ignorewhitespace.py | 8 +- changedetectionio/tests/test_import.py | 14 +- .../tests/test_jsonpath_jq_selector.py | 67 +++------ changedetectionio/tests/test_live_preview.py | 5 +- .../tests/test_nonrenderable_pages.py | 5 +- changedetectionio/tests/test_obfuscations.py | 8 +- changedetectionio/tests/test_pdf.py | 9 +- .../tests/test_preview_endpoints.py | 9 +- changedetectionio/tests/test_request.py | 89 ++++-------- .../tests/test_restock_itemprop.py | 32 ++--- changedetectionio/tests/test_rss.py | 15 +- changedetectionio/tests/test_scheduler.py | 34 ++--- changedetectionio/tests/test_security.py | 5 +- changedetectionio/tests/test_share_watch.py | 14 +- changedetectionio/tests/test_source.py | 18 +-- changedetectionio/tests/test_trigger.py | 8 +- changedetectionio/tests/test_trigger_regex.py | 13 +- .../tests/test_trigger_regex_with_filter.py | 13 +- changedetectionio/tests/test_ui.py | 14 +- changedetectionio/tests/test_unique_lines.py | 35 ++--- .../tests/test_watch_fields_storage.py | 8 +- .../tests/test_xpath_selector.py | 134 +++++------------- changedetectionio/tests/util.py | 5 + 46 files changed, 276 insertions(+), 678 deletions(-) diff --git a/changedetectionio/tests/custom_browser_url/test_custom_browser_url.py b/changedetectionio/tests/custom_browser_url/test_custom_browser_url.py index 5590ba989..96be7d590 100644 --- a/changedetectionio/tests/custom_browser_url/test_custom_browser_url.py +++ b/changedetectionio/tests/custom_browser_url/test_custom_browser_url.py @@ -29,13 +29,8 @@ def do_test(client, live_server, make_test_use_extra_browser=False): assert b"Settings updated." in res.data # Add our URL to the import page - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) if make_test_use_extra_browser: diff --git a/changedetectionio/tests/proxy_socks5/test_socks5_proxy.py b/changedetectionio/tests/proxy_socks5/test_socks5_proxy.py index 96c302c4e..547f60996 100644 --- a/changedetectionio/tests/proxy_socks5/test_socks5_proxy.py +++ b/changedetectionio/tests/proxy_socks5/test_socks5_proxy.py @@ -2,7 +2,7 @@ import json import os from flask import url_for -from changedetectionio.tests.util import live_server_setup, wait_for_all_checks, extract_UUID_from_client +from changedetectionio.tests.util import live_server_setup, wait_for_all_checks, extract_UUID_from_client, delete_all_watches def set_response(): @@ -98,6 +98,5 @@ def test_socks5(client, live_server, measure_memory_usage): ) assert b"OK" in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) diff --git a/changedetectionio/tests/smtp/test_notification_smtp.py b/changedetectionio/tests/smtp/test_notification_smtp.py index d89ea7950..388b481a0 100644 --- a/changedetectionio/tests/smtp/test_notification_smtp.py +++ b/changedetectionio/tests/smtp/test_notification_smtp.py @@ -5,7 +5,7 @@ import re from flask import url_for from changedetectionio.tests.util import set_original_response, set_modified_response, set_more_modified_response, live_server_setup, \ wait_for_all_checks, \ - set_longer_modified_response + set_longer_modified_response, delete_all_watches from changedetectionio.tests.util import extract_UUID_from_client import logging import base64 @@ -85,8 +85,7 @@ def test_check_notification_email_formats_default_HTML(client, live_server, meas assert '(added) So let\'s see what happens.\r\n' in msg # The plaintext part with \r\n assert 'Content-Type: text/html' in msg assert '(added) So let\'s see what happens.
' in msg # the html part - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_check_notification_email_formats_default_Text_override_HTML(client, live_server, measure_memory_usage): @@ -179,5 +178,4 @@ def test_check_notification_email_formats_default_Text_override_HTML(client, liv assert '<' not in msg assert 'Content-Type: text/html' in msg - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) diff --git a/changedetectionio/tests/test_add_replace_remove_filter.py b/changedetectionio/tests/test_add_replace_remove_filter.py index c1a71c799..ab27968fa 100644 --- a/changedetectionio/tests/test_add_replace_remove_filter.py +++ b/changedetectionio/tests/test_add_replace_remove_filter.py @@ -3,7 +3,7 @@ import os.path from flask import url_for -from .util import live_server_setup, wait_for_all_checks, wait_for_notification_endpoint_output +from .util import live_server_setup, wait_for_all_checks, wait_for_notification_endpoint_output, delete_all_watches import time def set_original(excluding=None, add_line=None): @@ -44,12 +44,8 @@ def test_check_removed_line_contains_trigger(client, live_server, measure_memory set_original() # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) @@ -107,14 +103,12 @@ def test_check_removed_line_contains_trigger(client, live_server, measure_memory res = client.get(url_for("watchlist.index")) assert b'has-unread-changes' in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_check_add_line_contains_trigger(client, live_server, measure_memory_usage): - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) time.sleep(1) # Give the endpoint time to spin up @@ -137,12 +131,8 @@ def test_check_add_line_contains_trigger(client, live_server, measure_memory_usa set_original() # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) @@ -187,5 +177,4 @@ def test_check_add_line_contains_trigger(client, live_server, measure_memory_usa assert b'-Oh yes please' in response assert '网站监测 内容更新了'.encode('utf-8') in response - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) diff --git a/changedetectionio/tests/test_api.py b/changedetectionio/tests/test_api.py index fa433980c..99c070862 100644 --- a/changedetectionio/tests/test_api.py +++ b/changedetectionio/tests/test_api.py @@ -2,7 +2,7 @@ import time from flask import url_for -from .util import live_server_setup, wait_for_all_checks +from .util import live_server_setup, wait_for_all_checks, delete_all_watches import json import uuid @@ -276,8 +276,7 @@ def test_access_denied(client, live_server, measure_memory_usage): assert res.status_code == 200 # Cleanup everything - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) res = client.post( url_for("settings.settings_page"), @@ -385,8 +384,7 @@ def test_api_watch_PUT_update(client, live_server, measure_memory_usage): assert b'Additional properties are not allowed' in res.data # Cleanup everything - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_api_import(client, live_server, measure_memory_usage): diff --git a/changedetectionio/tests/test_auth.py b/changedetectionio/tests/test_auth.py index 2c74b423f..33266a5b3 100644 --- a/changedetectionio/tests/test_auth.py +++ b/changedetectionio/tests/test_auth.py @@ -12,12 +12,8 @@ def test_basic_auth(client, live_server, measure_memory_usage): # This page will echo back any auth info test_url = url_for('test_basicauth_method', _external=True).replace("//","//myuser:mypass@") time.sleep(1) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) time.sleep(1) # Check form validation diff --git a/changedetectionio/tests/test_automatic_follow_ldjson_price.py b/changedetectionio/tests/test_automatic_follow_ldjson_price.py index c730286c9..b4b674ccd 100644 --- a/changedetectionio/tests/test_automatic_follow_ldjson_price.py +++ b/changedetectionio/tests/test_automatic_follow_ldjson_price.py @@ -86,12 +86,8 @@ def test_check_ldjson_price_autodetect(client, live_server, measure_memory_usage # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) # Should get a notice that it's available @@ -129,12 +125,8 @@ def test_check_ldjson_price_autodetect(client, live_server, measure_memory_usage # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) res = client.get(url_for("watchlist.index")) assert b'ldjson-price-track-offer' not in res.data @@ -146,12 +138,8 @@ def test_check_ldjson_price_autodetect(client, live_server, measure_memory_usage def _test_runner_check_bad_format_ignored(live_server, client, has_ldjson_price_data): test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) for k,v in client.application.config.get('DATASTORE').data['watching'].items(): diff --git a/changedetectionio/tests/test_backend.py b/changedetectionio/tests/test_backend.py index c694942ea..a15a97a98 100644 --- a/changedetectionio/tests/test_backend.py +++ b/changedetectionio/tests/test_backend.py @@ -3,7 +3,7 @@ import time from flask import url_for from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks, extract_rss_token_from_UI, \ - extract_UUID_from_client + extract_UUID_from_client, delete_all_watches sleep_time_for_fetch_thread = 3 @@ -163,8 +163,7 @@ def test_check_basic_change_detection_functionality(client, live_server, measure # # Cleanup everything - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_non_text_mime_or_downloads(client, live_server, measure_memory_usage): """ @@ -193,13 +192,8 @@ got it\r\n test_url = url_for('test_endpoint', content_type="application/octet-stream", _external=True) # Add our URL to the import page - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) @@ -227,7 +221,7 @@ got it\r\n assert b"some random text that should be split by line\n" in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) + delete_all_watches(client) def test_standard_text_plain(client, live_server, measure_memory_usage): @@ -258,13 +252,8 @@ got it\r\n test_url = url_for('test_endpoint', content_type="text/plain", _external=True) # Add our URL to the import page - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) @@ -293,7 +282,7 @@ got it\r\n assert b"some random text that should be split by line\n" in res.data assert b"Even this title should stay because we are just plain text" in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) + delete_all_watches(client) # Server says its plaintext, we should always treat it as plaintext def test_plaintext_even_if_xml_content(client, live_server, measure_memory_usage): @@ -309,13 +298,8 @@ def test_plaintext_even_if_xml_content(client, live_server, measure_memory_usage test_url = url_for('test_endpoint', content_type="text/plain", _external=True) # Add our URL to the import page - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) @@ -326,5 +310,5 @@ def test_plaintext_even_if_xml_content(client, live_server, measure_memory_usage assert b'<string name="feed_update_receiver_name"' in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) + delete_all_watches(client) diff --git a/changedetectionio/tests/test_block_while_text_present.py b/changedetectionio/tests/test_block_while_text_present.py index bf26a3de9..9580d727f 100644 --- a/changedetectionio/tests/test_block_while_text_present.py +++ b/changedetectionio/tests/test_block_while_text_present.py @@ -2,7 +2,7 @@ import time from flask import url_for -from .util import live_server_setup, wait_for_all_checks +from .util import live_server_setup, wait_for_all_checks, delete_all_watches from changedetectionio import html_tools def set_original_ignore_response(): @@ -70,12 +70,8 @@ def test_check_block_changedetection_text_NOT_present(client, live_server, measu # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) @@ -144,5 +140,4 @@ def test_check_block_changedetection_text_NOT_present(client, live_server, measu - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) diff --git a/changedetectionio/tests/test_clone.py b/changedetectionio/tests/test_clone.py index aeb3b4f2a..970b43c72 100644 --- a/changedetectionio/tests/test_clone.py +++ b/changedetectionio/tests/test_clone.py @@ -14,12 +14,8 @@ def test_clone_functionality(client, live_server, measure_memory_usage): test_url = url_for('test_endpoint', _external=True) # Add our URL to the import page - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) # So that we can be sure the same history doesnt carry over diff --git a/changedetectionio/tests/test_conditions.py b/changedetectionio/tests/test_conditions.py index 2685ae75f..2ca2f72bd 100644 --- a/changedetectionio/tests/test_conditions.py +++ b/changedetectionio/tests/test_conditions.py @@ -3,7 +3,7 @@ import json import time from flask import url_for -from .util import live_server_setup, wait_for_all_checks +from .util import live_server_setup, wait_for_all_checks, delete_all_watches from ..model import CONDITIONS_MATCH_LOGIC_DEFAULT @@ -60,12 +60,8 @@ def test_conditions_with_text_and_number(client, live_server): test_url = url_for('test_endpoint', _external=True) # Add our URL to the import page - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) # Configure the watch with two conditions connected with AND: @@ -143,8 +139,7 @@ def test_conditions_with_text_and_number(client, live_server): res = client.get(url_for("watchlist.index")) assert b'has-unread-changes' not in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) # The 'validate' button next to each rule row def test_condition_validate_rule_row(client, live_server): @@ -154,12 +149,8 @@ def test_condition_validate_rule_row(client, live_server): test_url = url_for('test_endpoint', _external=True) # Add our URL to the import page - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) uuid = next(iter(live_server.app.config['DATASTORE'].data['watching'])) @@ -230,12 +221,8 @@ def test_wordcount_conditions_plugin(client, live_server, measure_memory_usage): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) diff --git a/changedetectionio/tests/test_css_selector.py b/changedetectionio/tests/test_css_selector.py index b9c6a839e..094424905 100644 --- a/changedetectionio/tests/test_css_selector.py +++ b/changedetectionio/tests/test_css_selector.py @@ -81,12 +81,8 @@ def test_check_markup_include_filters_restriction(client, live_server, measure_m # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up time.sleep(sleep_time_for_fetch_thread) @@ -138,12 +134,8 @@ def test_check_multiple_filters(client, live_server, measure_memory_usage): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) # Goto the edit page, add our ignore text @@ -193,12 +185,8 @@ def test_filter_is_empty_help_suggestion(client, live_server, measure_memory_usa # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) # Goto the edit page, add our ignore text diff --git a/changedetectionio/tests/test_element_removal.py b/changedetectionio/tests/test_element_removal.py index 3b6ad3d13..69f1230fb 100644 --- a/changedetectionio/tests/test_element_removal.py +++ b/changedetectionio/tests/test_element_removal.py @@ -5,7 +5,7 @@ import time from flask import url_for from ..html_tools import * -from .util import live_server_setup, wait_for_all_checks +from .util import live_server_setup, wait_for_all_checks, delete_all_watches @@ -209,7 +209,6 @@ def test_element_removal_full(client, live_server, measure_memory_usage): # Re #2752 def test_element_removal_nth_offset_no_shift(client, live_server, measure_memory_usage): - set_response_with_multiple_index() subtractive_selectors_data = [""" @@ -228,8 +227,7 @@ body > table > tr:nth-child(3) > td:nth-child(3)""", for selector_list in subtractive_selectors_data: - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) # Add our URL to the import page test_url = url_for("test_endpoint", _external=True) diff --git a/changedetectionio/tests/test_encoding.py b/changedetectionio/tests/test_encoding.py index 722d1e6b8..35704797d 100644 --- a/changedetectionio/tests/test_encoding.py +++ b/changedetectionio/tests/test_encoding.py @@ -28,11 +28,8 @@ def test_check_encoding_detection(client, live_server, measure_memory_usage): # Add our URL to the import page test_url = url_for('test_endpoint', content_type="text/html", _external=True) - client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) @@ -59,11 +56,8 @@ def test_check_encoding_detection_missing_content_type_header(client, live_serve # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) diff --git a/changedetectionio/tests/test_errorhandling.py b/changedetectionio/tests/test_errorhandling.py index 83b192b45..52cc50556 100644 --- a/changedetectionio/tests/test_errorhandling.py +++ b/changedetectionio/tests/test_errorhandling.py @@ -3,7 +3,7 @@ import time from flask import url_for -from .util import live_server_setup, wait_for_all_checks +from .util import live_server_setup, wait_for_all_checks, delete_all_watches @@ -19,12 +19,8 @@ def _runner_test_http_errors(client, live_server, http_code, expected_text): status_code=http_code, _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) @@ -47,8 +43,7 @@ def _runner_test_http_errors(client, live_server, http_code, expected_text): #assert b'Error Screenshot' in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_http_error_handler(client, live_server, measure_memory_usage): @@ -56,8 +51,7 @@ def test_http_error_handler(client, live_server, measure_memory_usage): _runner_test_http_errors(client, live_server, 404, 'Page not found') _runner_test_http_errors(client, live_server, 500, '(Internal server error) received') _runner_test_http_errors(client, live_server, 400, 'Error - Request returned a HTTP error code 400') - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) # Just to be sure error text is properly handled def test_DNS_errors(client, live_server, measure_memory_usage): @@ -87,8 +81,7 @@ def test_DNS_errors(client, live_server, measure_memory_usage): assert found_name_resolution_error # Should always record that we tried assert bytes("just now".encode('utf-8')) in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) # Re 1513 def test_low_level_errors_clear_correctly(client, live_server, measure_memory_usage): @@ -145,5 +138,4 @@ def test_low_level_errors_clear_correctly(client, live_server, measure_memory_us ) assert not found_name_resolution_error - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) diff --git a/changedetectionio/tests/test_extract_regex.py b/changedetectionio/tests/test_extract_regex.py index 8276296e8..b398de9c0 100644 --- a/changedetectionio/tests/test_extract_regex.py +++ b/changedetectionio/tests/test_extract_regex.py @@ -2,7 +2,7 @@ import time from flask import url_for -from .util import live_server_setup, wait_for_all_checks +from .util import live_server_setup, wait_for_all_checks, delete_all_watches from ..html_tools import * @@ -76,12 +76,8 @@ def test_check_filter_multiline(client, live_server, measure_memory_usage): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) @@ -131,12 +127,8 @@ def test_check_filter_and_regex_extract(client, live_server, measure_memory_usag # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) @@ -212,12 +204,8 @@ def test_regex_error_handling(client, live_server, measure_memory_usage): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) ### test regex error handling res = client.post( @@ -231,5 +219,4 @@ def test_regex_error_handling(client, live_server, measure_memory_usage): assert b'is not a valid regular expression.' in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) diff --git a/changedetectionio/tests/test_filter_failure_notification.py b/changedetectionio/tests/test_filter_failure_notification.py index 2d48d056e..7294f6991 100644 --- a/changedetectionio/tests/test_filter_failure_notification.py +++ b/changedetectionio/tests/test_filter_failure_notification.py @@ -42,13 +42,8 @@ def run_filter_test(client, live_server, content_filter): if os.path.isfile("test-datastore/notification.txt"): os.unlink("test-datastore/notification.txt") - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) uuid = next(iter(live_server.app.config['DATASTORE'].data['watching'])) diff --git a/changedetectionio/tests/test_group.py b/changedetectionio/tests/test_group.py index e63639a9d..dec2ef7ff 100644 --- a/changedetectionio/tests/test_group.py +++ b/changedetectionio/tests/test_group.py @@ -2,7 +2,7 @@ import time from flask import url_for -from .util import live_server_setup, wait_for_all_checks, extract_rss_token_from_UI, get_UUID_for_tag_name, extract_UUID_from_client +from .util import live_server_setup, wait_for_all_checks, extract_rss_token_from_UI, get_UUID_for_tag_name, extract_UUID_from_client, delete_all_watches import os @@ -127,8 +127,7 @@ def test_setup_group_tag(client, live_server, measure_memory_usage): assert b"should-be-excluded" not in res.data assert res.status_code == 200 assert b"first-imported=1" in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_tag_import_singular(client, live_server, measure_memory_usage): @@ -147,8 +146,7 @@ def test_tag_import_singular(client, live_server, measure_memory_usage): ) # Should be only 1 tag because they both had the same assert res.data.count(b'test-tag') == 1 - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_tag_add_in_ui(client, live_server, measure_memory_usage): @@ -164,8 +162,7 @@ def test_tag_add_in_ui(client, live_server, measure_memory_usage): res = client.get(url_for("tags.delete_all"), follow_redirects=True) assert b'All tags deleted' in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_group_tag_notification(client, live_server, measure_memory_usage): @@ -232,8 +229,7 @@ def test_group_tag_notification(client, live_server, measure_memory_usage): #@todo Test that multiple notifications fired #@todo Test that each of multiple notifications with different settings - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_limit_tag_ui(client, live_server, measure_memory_usage): @@ -269,8 +265,7 @@ def test_limit_tag_ui(client, live_server, measure_memory_usage): assert res.data.count(b' unviewed ') == 1 - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) res = client.get(url_for("tags.delete_all"), follow_redirects=True) assert b'All tags deleted' in res.data @@ -297,8 +292,7 @@ def test_clone_tag_on_import(client, live_server, measure_memory_usage): # 2 times plus the top link to tag assert res.data.count(b'test-tag') == 3 assert res.data.count(b'another-tag') == 3 - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_clone_tag_on_quickwatchform_add(client, live_server, measure_memory_usage): @@ -325,8 +319,7 @@ def test_clone_tag_on_quickwatchform_add(client, live_server, measure_memory_usa # 2 times plus the top link to tag assert res.data.count(b'test-tag') == 3 assert res.data.count(b'another-tag') == 3 - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) res = client.get(url_for("tags.delete_all"), follow_redirects=True) assert b'All tags deleted' in res.data @@ -389,12 +382,8 @@ def test_order_of_filters_tag_filter_and_watch_filter(client, live_server, measu f.write(d) test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) filters = [ @@ -480,5 +469,4 @@ the {test} appeared before. {test in res.data[:n]=} """ n += t_index + len(test) - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) diff --git a/changedetectionio/tests/test_history_consistency.py b/changedetectionio/tests/test_history_consistency.py index b8a21cf2c..69c553054 100644 --- a/changedetectionio/tests/test_history_consistency.py +++ b/changedetectionio/tests/test_history_consistency.py @@ -4,7 +4,7 @@ import time import os import json from flask import url_for -from .util import wait_for_all_checks +from .util import wait_for_all_checks, delete_all_watches from urllib.parse import urlparse, parse_qs def test_consistent_history(client, live_server, measure_memory_usage): @@ -87,12 +87,8 @@ def test_check_text_history_view(client, live_server): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) @@ -121,5 +117,4 @@ def test_check_text_history_view(client, live_server): assert b'test-two' in res.data assert b'test-one' not in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) diff --git a/changedetectionio/tests/test_ignore.py b/changedetectionio/tests/test_ignore.py index 7f6aa62a3..ac456ec71 100644 --- a/changedetectionio/tests/test_ignore.py +++ b/changedetectionio/tests/test_ignore.py @@ -27,12 +27,8 @@ def test_ignore(client, live_server, measure_memory_usage): # live_server_setup(live_server) # Setup on conftest per function set_original_ignore_response() test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) @@ -79,12 +75,8 @@ def test_strip_ignore_lines(client, live_server, measure_memory_usage): assert b"Settings updated." in res.data test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) diff --git a/changedetectionio/tests/test_ignore_text.py b/changedetectionio/tests/test_ignore_text.py index 0b76bf87a..d42a934a1 100644 --- a/changedetectionio/tests/test_ignore_text.py +++ b/changedetectionio/tests/test_ignore_text.py @@ -2,7 +2,7 @@ import time from flask import url_for -from .util import live_server_setup, wait_for_all_checks +from .util import live_server_setup, wait_for_all_checks, delete_all_watches from changedetectionio import html_tools @@ -97,12 +97,8 @@ def test_check_ignore_text_functionality(client, live_server, measure_memory_usa # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) @@ -163,8 +159,7 @@ def test_check_ignore_text_functionality(client, live_server, measure_memory_usa # it is only ignored, it is not removed (it will be highlighted too) assert b'new ignore stuff' in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) # When adding some ignore text, it should not trigger a change, even if something else on that line changes def _run_test_global_ignore(client, as_source=False, extra_ignore=""): @@ -192,12 +187,8 @@ def _run_test_global_ignore(client, as_source=False, extra_ignore=""): # Switch to source mode so we can test that too! test_url = "source:"+test_url - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) @@ -251,8 +242,7 @@ def _run_test_global_ignore(client, as_source=False, extra_ignore=""): res = client.get(url_for("watchlist.index")) assert b'has-unread-changes' in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_check_global_ignore_text_functionality(client, live_server): diff --git a/changedetectionio/tests/test_ignorehyperlinks.py b/changedetectionio/tests/test_ignorehyperlinks.py index 01ce2a3be..a3412af51 100644 --- a/changedetectionio/tests/test_ignorehyperlinks.py +++ b/changedetectionio/tests/test_ignorehyperlinks.py @@ -3,9 +3,7 @@ import time from flask import url_for -from .util import live_server_setup, wait_for_all_checks - - +from .util import live_server_setup, wait_for_all_checks, delete_all_watches def set_original_ignore_response(): @@ -117,7 +115,5 @@ def test_render_anchor_tag_content_true(client, live_server, measure_memory_usag assert b"/test-endpoint" in res.data # Cleanup everything - res = client.get(url_for("ui.form_delete", uuid="all"), - follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) diff --git a/changedetectionio/tests/test_ignorestatuscode.py b/changedetectionio/tests/test_ignorestatuscode.py index 1f4f26493..37e7fb383 100644 --- a/changedetectionio/tests/test_ignorestatuscode.py +++ b/changedetectionio/tests/test_ignorestatuscode.py @@ -60,12 +60,8 @@ def test_normal_page_check_works_with_ignore_status_code(client, live_server, me # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) @@ -94,12 +90,8 @@ def test_403_page_check_works_with_ignore_status_code(client, live_server, measu # Add our URL to the import page test_url = url_for('test_endpoint', status_code=403, _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.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_ignorewhitespace.py b/changedetectionio/tests/test_ignorewhitespace.py index 5a3f434c0..c507885c2 100644 --- a/changedetectionio/tests/test_ignorewhitespace.py +++ b/changedetectionio/tests/test_ignorewhitespace.py @@ -70,12 +70,8 @@ def test_check_ignore_whitespace(client, live_server, measure_memory_usage): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) time.sleep(sleep_time_for_fetch_thread) # Trigger a check diff --git a/changedetectionio/tests/test_import.py b/changedetectionio/tests/test_import.py index 899ff1bac..0d9de7c80 100644 --- a/changedetectionio/tests/test_import.py +++ b/changedetectionio/tests/test_import.py @@ -5,7 +5,7 @@ import time from flask import url_for -from .util import live_server_setup, wait_for_all_checks +from .util import live_server_setup, wait_for_all_checks, delete_all_watches # def test_setup(client, live_server, measure_memory_usage): @@ -28,7 +28,7 @@ https://example.com tag1, other tag""" assert b"3 Imported" in res.data assert b"tag1" in res.data assert b"other tag" in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) + delete_all_watches(client) # Clear flask alerts res = client.get( url_for("watchlist.index")) @@ -53,7 +53,7 @@ def xtest_import_skip_url(client, live_server, measure_memory_usage): assert b"1 Imported" in res.data assert b"ht000000broken" in res.data assert b"1 Skipped" in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) + delete_all_watches(client) # Clear flask alerts res = client.get( url_for("watchlist.index")) @@ -119,7 +119,7 @@ def test_import_distillio(client, live_server, measure_memory_usage): assert b"nice stuff" in res.data assert b"nerd-news" in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) + delete_all_watches(client) # Clear flask alerts res = client.get(url_for("watchlist.index")) @@ -169,8 +169,7 @@ def test_import_custom_xlsx(client, live_server, measure_memory_usage): assert filters[0] == '/html[1]/body[1]/div[4]/div[1]/div[1]/div[1]||//*[@id=\'content\']/div[3]/div[1]/div[1]||//*[@id=\'content\']/div[1]' assert watch.get('time_between_check') == {'weeks': 0, 'days': 1, 'hours': 6, 'minutes': 24, 'seconds': 0} - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_import_watchete_xlsx(client, live_server, measure_memory_usage): """Test can upload a excel spreadsheet and the watches are created correctly""" @@ -214,5 +213,4 @@ def test_import_watchete_xlsx(client, live_server, measure_memory_usage): if watch.get('title') == 'system default website': assert watch.get('fetch_backend') == 'system' # uses default if blank - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) diff --git a/changedetectionio/tests/test_jsonpath_jq_selector.py b/changedetectionio/tests/test_jsonpath_jq_selector.py index 217e623db..fbe1efb5a 100644 --- a/changedetectionio/tests/test_jsonpath_jq_selector.py +++ b/changedetectionio/tests/test_jsonpath_jq_selector.py @@ -3,7 +3,7 @@ import time from flask import url_for, escape -from . util import live_server_setup, wait_for_all_checks +from . util import live_server_setup, wait_for_all_checks, delete_all_watches import pytest jq_support = True @@ -210,11 +210,8 @@ def test_check_json_without_filter(client, live_server, measure_memory_usage): # Add our URL to the import page test_url = url_for('test_endpoint', content_type="application/json", _external=True) - client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) @@ -228,8 +225,7 @@ def test_check_json_without_filter(client, live_server, measure_memory_usage): assert b'"html": "<b>"' in res.data assert res.data.count(b'{') >= 2 - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def check_json_filter(json_filter, client, live_server): set_original_response() @@ -239,12 +235,8 @@ def check_json_filter(json_filter, client, live_server): # Add our URL to the import page test_url = url_for('test_endpoint', content_type="application/json", _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) @@ -291,8 +283,7 @@ def check_json_filter(json_filter, client, live_server): # And #462 - check we see the proper utf-8 string there assert "Örnsköldsvik".encode('utf-8') in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_check_jsonpath_filter(client, live_server, measure_memory_usage): check_json_filter('json:boss.name', client, live_server) @@ -313,12 +304,8 @@ def check_json_filter_bool_val(json_filter, client, live_server): test_url = url_for('test_endpoint', content_type="application/json", _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) # Goto the edit page, add our ignore text @@ -350,8 +337,7 @@ def check_json_filter_bool_val(json_filter, client, live_server): # But the change should be there, tho its hard to test the change was detected because it will show old and new versions assert b'false' in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_check_jsonpath_filter_bool_val(client, live_server, measure_memory_usage): check_json_filter_bool_val("json:$['available']", client, live_server) @@ -377,12 +363,8 @@ def check_json_ext_filter(json_filter, client, live_server): # Add our URL to the import page test_url = url_for('test_endpoint', content_type="application/json", _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) @@ -436,8 +418,7 @@ def check_json_ext_filter(json_filter, client, live_server): assert b'ForSale' in res.data assert b'Sold' in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_ignore_json_order(client, live_server, measure_memory_usage): # A change in order shouldn't trigger a notification @@ -448,12 +429,8 @@ def test_ignore_json_order(client, live_server, measure_memory_usage): # Add our URL to the import page test_url = url_for('test_endpoint', content_type="application/json", _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) @@ -478,8 +455,7 @@ def test_ignore_json_order(client, live_server, measure_memory_usage): res = client.get(url_for("watchlist.index")) assert b'has-unread-changes' in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_correct_header_detect(client, live_server, measure_memory_usage): # Like in https://github.com/dgtlmoon/changedetection.io/pull/1593 @@ -490,12 +466,8 @@ def test_correct_header_detect(client, live_server, measure_memory_usage): # Add our URL to the import page # Check weird casing is cleaned up and detected also test_url = url_for('test_endpoint', content_type="aPPlication/JSon", uppercase_headers=True, _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) res = client.get(url_for("watchlist.index")) @@ -510,8 +482,7 @@ def test_correct_header_detect(client, live_server, measure_memory_usage): assert b'"hello": 123,' in res.data assert b'"world": 123' in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_check_jsonpath_ext_filter(client, live_server, measure_memory_usage): check_json_ext_filter('json:$[?(@.status==Sold)]', client, live_server) diff --git a/changedetectionio/tests/test_live_preview.py b/changedetectionio/tests/test_live_preview.py index c811f71ff..2927098f2 100644 --- a/changedetectionio/tests/test_live_preview.py +++ b/changedetectionio/tests/test_live_preview.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 from flask import url_for -from changedetectionio.tests.util import live_server_setup, wait_for_all_checks, extract_UUID_from_client +from changedetectionio.tests.util import live_server_setup, wait_for_all_checks, extract_UUID_from_client, delete_all_watches def set_response(): @@ -75,5 +75,4 @@ def test_content_filter_live_preview(client, live_server, measure_memory_usage): assert reply.get('ignore_line_numbers') == [2] # Ignored - "socks" on line 2 assert reply.get('trigger_line_numbers') == [1] # Triggers "Awesome" in line 1 - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) diff --git a/changedetectionio/tests/test_nonrenderable_pages.py b/changedetectionio/tests/test_nonrenderable_pages.py index 70d0c2e93..85fad316a 100644 --- a/changedetectionio/tests/test_nonrenderable_pages.py +++ b/changedetectionio/tests/test_nonrenderable_pages.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 from flask import url_for -from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks +from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks, delete_all_watches import time @@ -113,6 +113,5 @@ def test_check_basic_change_detection_functionality(client, live_server, measure # # Cleanup everything - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) diff --git a/changedetectionio/tests/test_obfuscations.py b/changedetectionio/tests/test_obfuscations.py index 9004f0fd3..53034669e 100644 --- a/changedetectionio/tests/test_obfuscations.py +++ b/changedetectionio/tests/test_obfuscations.py @@ -24,12 +24,8 @@ def test_obfuscations(client, live_server, measure_memory_usage): time.sleep(1) # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up time.sleep(3) diff --git a/changedetectionio/tests/test_pdf.py b/changedetectionio/tests/test_pdf.py index 90da876aa..74858cfae 100644 --- a/changedetectionio/tests/test_pdf.py +++ b/changedetectionio/tests/test_pdf.py @@ -13,13 +13,8 @@ def test_fetch_pdf(client, live_server, measure_memory_usage): # live_server_setup(live_server) # Setup on conftest per function test_url = url_for('test_pdf_endpoint', _external=True) # Add our URL to the import page - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) diff --git a/changedetectionio/tests/test_preview_endpoints.py b/changedetectionio/tests/test_preview_endpoints.py index bc4d5412d..6044bf9f9 100644 --- a/changedetectionio/tests/test_preview_endpoints.py +++ b/changedetectionio/tests/test_preview_endpoints.py @@ -13,13 +13,8 @@ def test_fetch_pdf(client, live_server, measure_memory_usage): # live_server_setup(live_server) # Setup on conftest per function test_url = url_for('test_pdf_endpoint', _external=True) # Add our URL to the import page - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) diff --git a/changedetectionio/tests/test_request.py b/changedetectionio/tests/test_request.py index f4f56fabf..3110eef6a 100644 --- a/changedetectionio/tests/test_request.py +++ b/changedetectionio/tests/test_request.py @@ -2,7 +2,7 @@ import json import os import time from flask import url_for -from . util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks, extract_UUID_from_client +from . util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks, extract_UUID_from_client, delete_all_watches @@ -17,21 +17,13 @@ def test_headers_in_request(client, live_server, measure_memory_usage): test_url = test_url.replace('localhost', 'changedet') # Add the test URL twice, we will check - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) cookie_header = '_ga=GA1.2.1022228332; cookie-preferences=analytics:accepted;' @@ -82,8 +74,7 @@ def test_headers_in_request(client, live_server, measure_memory_usage): for k, watch in client.application.config.get('DATASTORE').data.get('watching').items(): assert 'custom' in watch.get('remote_server_reply') # added in util.py - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_body_in_request(client, live_server, measure_memory_usage): @@ -93,12 +84,8 @@ def test_body_in_request(client, live_server, measure_memory_usage): # Because its no longer calling back to localhost but from the browser container, set in test-only.yml test_url = test_url.replace('localhost', 'cdio') - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) @@ -150,12 +137,8 @@ def test_body_in_request(client, live_server, measure_memory_usage): ####### data sanity checks # Add the test URL twice, we will check - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) watches_with_body = 0 with open('test-datastore/url-watches.json') as f: @@ -180,8 +163,7 @@ def test_body_in_request(client, live_server, measure_memory_usage): follow_redirects=True ) assert b"Body must be empty when Request Method is set to GET" in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_method_in_request(client, live_server, measure_memory_usage): # Add our URL to the import page @@ -191,20 +173,12 @@ def test_method_in_request(client, live_server, measure_memory_usage): test_url = test_url.replace('localhost', 'cdio') # Add the test URL twice, we will check - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) @@ -258,8 +232,7 @@ def test_method_in_request(client, live_server, measure_memory_usage): # Should be only one with method set to PATCH assert watches_with_method == 1 - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) # Re #2408 - user-agent override test, also should handle case-insensitive header deduplication def test_ua_global_override(client, live_server, measure_memory_usage): @@ -277,12 +250,8 @@ def test_ua_global_override(client, live_server, measure_memory_usage): ) assert b'Settings updated' in res.data - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) res = client.get( @@ -315,8 +284,7 @@ def test_ua_global_override(client, live_server, measure_memory_usage): ) assert b"agent-from-watch" in res.data assert b"html-requests-user-agent" not in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_headers_textfile_in_request(client, live_server, measure_memory_usage): @@ -356,12 +324,8 @@ def test_headers_textfile_in_request(client, live_server, measure_memory_usage): assert b"requests-default_ua-html_requests" in res.data # Add the test URL twice, we will check - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) @@ -429,19 +393,14 @@ def test_headers_textfile_in_request(client, live_server, measure_memory_usage): assert "User-Agent:".encode('utf-8') + requests_ua.encode('utf-8') in res.data # unlink headers.txt on start/stop - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_headers_validation(client, live_server): test_url = url_for('test_headers', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) res = client.post( url_for("ui.ui_edit.edit_page", uuid="first"), diff --git a/changedetectionio/tests/test_restock_itemprop.py b/changedetectionio/tests/test_restock_itemprop.py index 6cc3a2b26..590572205 100644 --- a/changedetectionio/tests/test_restock_itemprop.py +++ b/changedetectionio/tests/test_restock_itemprop.py @@ -3,7 +3,7 @@ import os import time from flask import url_for -from .util import live_server_setup, wait_for_all_checks, wait_for_notification_endpoint_output, extract_UUID_from_client +from .util import live_server_setup, wait_for_all_checks, wait_for_notification_endpoint_output, extract_UUID_from_client, delete_all_watches from ..notification import default_notification_format instock_props = [ @@ -69,8 +69,7 @@ def test_restock_itemprop_basic(client, live_server): assert b'has-restock-info' in res.data assert b' in-stock' in res.data assert b' not-in-stock' not in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) for p in out_of_stock_props: @@ -85,8 +84,7 @@ def test_restock_itemprop_basic(client, live_server): assert b'has-restock-info not-in-stock' in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_itemprop_price_change(client, live_server): @@ -132,13 +130,11 @@ def test_itemprop_price_change(client, live_server): assert b'has-unread-changes' not in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def _run_test_minmax_limit(client, extra_watch_edit_form): - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) test_url = url_for('test_endpoint', _external=True) @@ -212,8 +208,7 @@ def _run_test_minmax_limit(client, extra_watch_edit_form): assert b'1,890.45' in res.data or b'1890.45' in res.data assert b'has-unread-changes' in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_restock_itemprop_minmax(client, live_server): @@ -257,8 +252,7 @@ def test_restock_itemprop_with_tag(client, live_server): def test_itemprop_percent_threshold(client, live_server): - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) test_url = url_for('test_endpoint', _external=True) @@ -317,8 +311,7 @@ def test_itemprop_percent_threshold(client, live_server): - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) @@ -393,8 +386,7 @@ def test_change_with_notification_values(client, live_server): def test_data_sanity(client, live_server): - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) test_url = url_for('test_endpoint', _external=True) test_url2 = url_for('test_endpoint2', _external=True) @@ -421,8 +413,7 @@ def test_data_sanity(client, live_server): assert str(res.data.decode()).count("950.95") == 1, "Price should only show once (for the watch added, no other watches yet)" ## different test, check the edit page works on an empty request result - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) client.post( url_for("ui.ui_views.form_quick_watch_add"), @@ -435,8 +426,7 @@ def test_data_sanity(client, live_server): url_for("ui.ui_edit.edit_page", uuid="first")) assert test_url2.encode('utf-8') in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) # All examples should give a prive of 666.66 def test_special_prop_examples(client, live_server): diff --git a/changedetectionio/tests/test_rss.py b/changedetectionio/tests/test_rss.py index 56d1c7d34..38d558635 100644 --- a/changedetectionio/tests/test_rss.py +++ b/changedetectionio/tests/test_rss.py @@ -3,7 +3,7 @@ import time from flask import url_for from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks, extract_rss_token_from_UI, \ - extract_UUID_from_client + extract_UUID_from_client, delete_all_watches def set_original_cdata_xml(): @@ -114,13 +114,8 @@ def test_basic_cdata_rss_markup(client, live_server, measure_memory_usage): test_url = url_for('test_endpoint', content_type="application/atom+xml; charset=UTF-8", _external=True) # Add our URL to the import page - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) @@ -132,7 +127,7 @@ def test_basic_cdata_rss_markup(client, live_server, measure_memory_usage): assert b' res.data.find(b'Which is across multiple lines') - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data \ No newline at end of file + delete_all_watches(client) \ No newline at end of file diff --git a/changedetectionio/tests/test_watch_fields_storage.py b/changedetectionio/tests/test_watch_fields_storage.py index c0c264262..1cfd60301 100644 --- a/changedetectionio/tests/test_watch_fields_storage.py +++ b/changedetectionio/tests/test_watch_fields_storage.py @@ -10,12 +10,8 @@ def test_check_watch_field_storage(client, live_server, measure_memory_usage): test_url = "http://somerandomsitewewatch.com" - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) res = client.post( diff --git a/changedetectionio/tests/test_xpath_selector.py b/changedetectionio/tests/test_xpath_selector.py index abcc766a2..356b91b98 100644 --- a/changedetectionio/tests/test_xpath_selector.py +++ b/changedetectionio/tests/test_xpath_selector.py @@ -2,7 +2,7 @@ from flask import url_for -from .util import wait_for_all_checks +from .util import wait_for_all_checks, delete_all_watches from ..processors.magic import RSS_XML_CONTENT_TYPES @@ -113,12 +113,8 @@ def test_check_xpath_filter_utf8(client, live_server, measure_memory_usage): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True, content_type="application/rss+xml;charset=UTF-8") - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) res = client.post( url_for("ui.ui_edit.edit_page", uuid="first"), @@ -129,8 +125,7 @@ def test_check_xpath_filter_utf8(client, live_server, measure_memory_usage): wait_for_all_checks(client) res = client.get(url_for("watchlist.index")) assert b'Unicode strings with encoding declaration are not supported.' not in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) # Handle utf-8 charset replies https://github.com/dgtlmoon/changedetection.io/pull/613 @@ -167,12 +162,8 @@ def test_check_xpath_text_function_utf8(client, live_server, measure_memory_usag # Add our URL to the import page test_url = url_for('test_endpoint', _external=True, content_type="application/rss+xml;charset=UTF-8") - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) res = client.post( url_for("ui.ui_edit.edit_page", uuid="first"), @@ -193,8 +184,7 @@ def test_check_xpath_text_function_utf8(client, live_server, measure_memory_usag assert b'Stock Alert (UK): RPi CM4' in res.data assert b'Stock Alert (UK): Big monitor' in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_check_markup_xpath_filter_restriction(client, live_server, measure_memory_usage): @@ -204,12 +194,8 @@ def test_check_markup_xpath_filter_restriction(client, live_server, measure_memo # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up wait_for_all_checks(client) @@ -239,19 +225,14 @@ def test_check_markup_xpath_filter_restriction(client, live_server, measure_memo res = client.get(url_for("watchlist.index")) assert b'has-unread-changes' not in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_xpath_validation(client, live_server, measure_memory_usage): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) res = client.post( @@ -260,19 +241,14 @@ def test_xpath_validation(client, live_server, measure_memory_usage): follow_redirects=True ) assert b"is not a valid XPath expression" in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_xpath23_prefix_validation(client, live_server, measure_memory_usage): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) res = client.post( @@ -281,8 +257,7 @@ def test_xpath23_prefix_validation(client, live_server, measure_memory_usage): follow_redirects=True ) assert b"is not a valid XPath expression" in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_xpath1_lxml(client, live_server, measure_memory_usage): @@ -317,12 +292,8 @@ def test_xpath1_lxml(client, live_server, measure_memory_usage): test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) res = client.post( @@ -351,12 +322,8 @@ def test_xpath1_lxml(client, live_server, measure_memory_usage): def test_xpath1_validation(client, live_server, measure_memory_usage): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) res = client.post( @@ -365,25 +332,19 @@ def test_xpath1_validation(client, live_server, measure_memory_usage): follow_redirects=True ) assert b"is not a valid XPath expression" in res.data - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) # actually only really used by the distll.io importer, but could be handy too def test_check_with_prefix_include_filters(client, live_server, measure_memory_usage): - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) set_original_response() wait_for_all_checks(client) # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) res = client.post( @@ -428,12 +389,8 @@ def test_various_rules(client, live_server, measure_memory_usage): """) test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) for r in ['//div', '//a', 'xpath://div', 'xpath://a']: @@ -452,18 +409,13 @@ def test_various_rules(client, live_server, measure_memory_usage): res = client.get(url_for("watchlist.index")) assert b'fetch-error' not in res.data, f"Should not see errors after '{r} filter" - res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) - assert b'Deleted' in res.data + delete_all_watches(client) def test_xpath_20(client, live_server, measure_memory_usage): test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) set_original_response() @@ -499,12 +451,8 @@ def test_xpath_20_function_count(client, live_server, measure_memory_usage): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) res = client.post( @@ -536,12 +484,8 @@ def test_xpath_20_function_count2(client, live_server, measure_memory_usage): # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) res = client.post( @@ -573,16 +517,12 @@ def test_xpath_20_function_string_join_matches(client, live_server, measure_memo # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - res = client.post( - url_for("imports.import_page"), - data={"urls": test_url}, - follow_redirects=True - ) - assert b"1 Imported" in res.data + uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) res = client.post( - url_for("ui.ui_edit.edit_page", uuid="first"), + url_for("ui.ui_edit.edit_page", uuid=uuid), data={ "include_filters": "xpath:string-join(//*[contains(@class, 'sametext')]|//*[matches(@class, 'changetext')], 'specialconjunction')", "url": test_url, @@ -597,7 +537,7 @@ def test_xpath_20_function_string_join_matches(client, live_server, measure_memo wait_for_all_checks(client) res = client.get( - url_for("ui.ui_views.preview_page", uuid="first"), + url_for("ui.ui_views.preview_page", uuid=uuid), follow_redirects=True ) diff --git a/changedetectionio/tests/util.py b/changedetectionio/tests/util.py index 468a631fa..d7bf705ff 100644 --- a/changedetectionio/tests/util.py +++ b/changedetectionio/tests/util.py @@ -127,6 +127,11 @@ def extract_UUID_from_client(client): uuid = m.group(1) return uuid.strip() +def delete_all_watches(client=None): + uuids = list(client.application.config.get('DATASTORE').data['watching']) + for uuid in uuids: + client.application.config.get('DATASTORE').delete(uuid) + def wait_for_all_checks(client=None): """