From 5b153ca25d2f7bb66383cb67650a8847adc3292b Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Mon, 2 Feb 2026 12:51:39 +0100 Subject: [PATCH] Revert test changes --- .../blueprint/rss/single_watch.py | 2 + changedetectionio/blueprint/tags/__init__.py | 4 + changedetectionio/blueprint/ui/__init__.py | 5 + changedetectionio/blueprint/ui/diff.py | 8 ++ changedetectionio/blueprint/ui/edit.py | 7 ++ changedetectionio/blueprint/ui/preview.py | 4 + changedetectionio/tests/conftest.py | 97 ++++++------------- .../test_custom_browser_url.py | 6 +- .../tests/fetchers/test_content.py | 11 ++- .../fetchers/test_custom_js_before_content.py | 9 +- .../tests/proxy_list/test_multiple_proxy.py | 9 +- .../tests/proxy_list/test_noproxy.py | 5 +- .../tests/proxy_list/test_proxy_noconnect.py | 8 +- .../proxy_list/test_select_custom_proxy.py | 12 ++- .../tests/proxy_socks5/test_socks5_proxy.py | 14 ++- .../proxy_socks5/test_socks5_proxy_sources.py | 13 ++- .../tests/smtp/test_notification_smtp.py | 10 +- .../tests/test_access_control.py | 12 ++- .../tests/test_add_replace_remove_filter.py | 4 +- changedetectionio/tests/test_api.py | 2 +- changedetectionio/tests/test_auth.py | 4 +- changedetectionio/tests/test_backend.py | 12 +-- changedetectionio/tests/test_clone.py | 2 +- changedetectionio/tests/test_conditions.py | 4 +- changedetectionio/tests/test_css_selector.py | 10 +- .../tests/test_element_removal.py | 14 +-- changedetectionio/tests/test_encoding.py | 4 +- changedetectionio/tests/test_errorhandling.py | 11 ++- changedetectionio/tests/test_extract_csv.py | 12 ++- changedetectionio/tests/test_extract_regex.py | 8 +- .../tests/test_filter_exist_changes.py | 11 ++- changedetectionio/tests/test_group.py | 34 ++++--- .../tests/test_history_consistency.py | 4 +- changedetectionio/tests/test_ignore_text.py | 10 +- .../tests/test_ignorehyperlinks.py | 10 +- .../tests/test_ignorestatuscode.py | 2 +- changedetectionio/tests/test_import.py | 4 +- changedetectionio/tests/test_jinja2.py | 20 ++-- .../tests/test_jsonpath_jq_selector.py | 13 ++- changedetectionio/tests/test_notification.py | 6 +- .../tests/test_notification_errors.py | 9 +- changedetectionio/tests/test_obfuscations.py | 2 +- changedetectionio/tests/test_pdf.py | 4 +- .../tests/test_preview_endpoints.py | 6 +- changedetectionio/tests/test_request.py | 33 +++---- .../tests/test_restock_itemprop.py | 67 ++++++++----- changedetectionio/tests/test_rss.py | 4 +- .../tests/test_rss_single_watch.py | 7 +- changedetectionio/tests/test_scheduler.py | 12 +-- changedetectionio/tests/test_search.py | 56 +++++++---- changedetectionio/tests/test_security.py | 46 ++++++--- changedetectionio/tests/test_share_watch.py | 17 +++- changedetectionio/tests/test_source.py | 8 +- changedetectionio/tests/test_trigger.py | 10 +- changedetectionio/tests/test_trigger_regex.py | 4 +- .../tests/test_trigger_regex_with_filter.py | 4 +- changedetectionio/tests/test_ui.py | 30 ++++-- changedetectionio/tests/test_unique_lines.py | 10 +- .../tests/test_watch_fields_storage.py | 4 +- .../tests/test_xpath_selector.py | 52 +++++----- changedetectionio/tests/util.py | 4 +- .../tests/visualselector/test_fetch_data.py | 14 ++- 62 files changed, 502 insertions(+), 338 deletions(-) diff --git a/changedetectionio/blueprint/rss/single_watch.py b/changedetectionio/blueprint/rss/single_watch.py index 1d011902..b45645ab 100644 --- a/changedetectionio/blueprint/rss/single_watch.py +++ b/changedetectionio/blueprint/rss/single_watch.py @@ -37,6 +37,8 @@ def construct_single_watch_routes(rss_blueprint, datastore): rss_content_format = datastore.data['settings']['application'].get('rss_content_format') + if uuid == 'first': + uuid = list(datastore.data['watching'].keys()).pop() # Get the watch by UUID watch = datastore.data['watching'].get(uuid) if not watch: diff --git a/changedetectionio/blueprint/tags/__init__.py b/changedetectionio/blueprint/tags/__init__.py index 1d388d11..761e93fe 100644 --- a/changedetectionio/blueprint/tags/__init__.py +++ b/changedetectionio/blueprint/tags/__init__.py @@ -137,6 +137,8 @@ def construct_blueprint(datastore: ChangeDetectionStore): @login_optionally_required def form_tag_edit(uuid): from changedetectionio.blueprint.tags.form import group_restock_settings_form + if uuid == 'first': + uuid = list(datastore.data['settings']['application']['tags'].keys()).pop() default = datastore.data['settings']['application']['tags'].get(uuid) if not default: @@ -197,6 +199,8 @@ def construct_blueprint(datastore: ChangeDetectionStore): @login_optionally_required def form_tag_edit_submit(uuid): from changedetectionio.blueprint.tags.form import group_restock_settings_form + if uuid == 'first': + uuid = list(datastore.data['settings']['application']['tags'].keys()).pop() default = datastore.data['settings']['application']['tags'].get(uuid) diff --git a/changedetectionio/blueprint/ui/__init__.py b/changedetectionio/blueprint/ui/__init__.py index 498d674e..0606de2a 100644 --- a/changedetectionio/blueprint/ui/__init__.py +++ b/changedetectionio/blueprint/ui/__init__.py @@ -222,6 +222,9 @@ def construct_blueprint(datastore: ChangeDetectionStore, update_q, worker_pool, @login_optionally_required def form_delete(): uuid = request.args.get('uuid') + # More for testing, possible to return the first/only + if uuid == 'first': + uuid = list(datastore.data['watching'].keys()).pop() if uuid != 'all' and not uuid in datastore.data['watching'].keys(): flash(gettext('The watch by UUID {} does not exist.').format(uuid), 'error') @@ -237,6 +240,8 @@ def construct_blueprint(datastore: ChangeDetectionStore, update_q, worker_pool, def form_clone(): uuid = request.args.get('uuid') + if uuid == 'first': + uuid = list(datastore.data['watching'].keys()).pop() new_uuid = datastore.clone(uuid) diff --git a/changedetectionio/blueprint/ui/diff.py b/changedetectionio/blueprint/ui/diff.py index 6e90d19e..2ec0af5a 100644 --- a/changedetectionio/blueprint/ui/diff.py +++ b/changedetectionio/blueprint/ui/diff.py @@ -83,6 +83,8 @@ def construct_blueprint(datastore: ChangeDetectionStore): If a processor doesn't have a difference module, falls back to text_json_diff. """ + if uuid == 'first': + uuid = list(datastore.data['watching'].keys()).pop() try: watch = datastore.data['watching'][uuid] @@ -143,6 +145,8 @@ def construct_blueprint(datastore: ChangeDetectionStore): """ + if uuid == 'first': + uuid = list(datastore.data['watching'].keys()).pop() try: watch = datastore.data['watching'][uuid] except KeyError: @@ -196,6 +200,8 @@ def construct_blueprint(datastore: ChangeDetectionStore): If a processor doesn't have an extract module, falls back to text_json_diff. """ + if uuid == 'first': + uuid = list(datastore.data['watching'].keys()).pop() try: watch = datastore.data['watching'][uuid] @@ -261,6 +267,8 @@ def construct_blueprint(datastore: ChangeDetectionStore): - /diff/{uuid}/processor-asset/rendered_diff """ + if uuid == 'first': + uuid = list(datastore.data['watching'].keys()).pop() try: watch = datastore.data['watching'][uuid] diff --git a/changedetectionio/blueprint/ui/edit.py b/changedetectionio/blueprint/ui/edit.py index 7baf389e..b6b5a7ef 100644 --- a/changedetectionio/blueprint/ui/edit.py +++ b/changedetectionio/blueprint/ui/edit.py @@ -30,6 +30,8 @@ def construct_blueprint(datastore: ChangeDetectionStore, update_q, queuedWatchMe from changedetectionio import processors import importlib + if uuid == 'first': + uuid = list(datastore.data['watching'].keys()).pop() # More for testing, possible to return the first/only if not datastore.data['watching'].keys(): flash(gettext("No watches to edit"), "error") @@ -368,6 +370,8 @@ def construct_blueprint(datastore: ChangeDetectionStore, update_q, queuedWatchMe from flask import send_file import brotli + if uuid == 'first': + uuid = list(datastore.data['watching'].keys()).pop() watch = datastore.data['watching'].get(uuid) if watch and watch.history.keys() and os.path.isdir(watch.watch_data_dir): latest_filename = list(watch.history.keys())[-1] @@ -392,6 +396,9 @@ def construct_blueprint(datastore: ChangeDetectionStore, update_q, queuedWatchMe def watch_get_preview_rendered(uuid): '''For when viewing the "preview" of the rendered text from inside of Edit''' from flask import jsonify + + if uuid == 'first': + uuid = list(datastore.data['watching'].keys()).pop() from changedetectionio.processors.text_json_diff import prepare_filter_prevew result = prepare_filter_prevew(watch_uuid=uuid, form_data=request.form, datastore=datastore) return jsonify(result) diff --git a/changedetectionio/blueprint/ui/preview.py b/changedetectionio/blueprint/ui/preview.py index 2b2d7a28..1e3df6a0 100644 --- a/changedetectionio/blueprint/ui/preview.py +++ b/changedetectionio/blueprint/ui/preview.py @@ -27,6 +27,8 @@ def construct_blueprint(datastore: ChangeDetectionStore): If a processor doesn't have a preview module, falls back to default text preview. """ + if uuid == 'first': + uuid = list(datastore.data['watching'].keys()).pop() try: watch = datastore.data['watching'][uuid] except KeyError: @@ -147,6 +149,8 @@ def construct_blueprint(datastore: ChangeDetectionStore): """ from flask import make_response + if uuid == 'first': + uuid = list(datastore.data['watching'].keys()).pop() try: watch = datastore.data['watching'][uuid] except KeyError: diff --git a/changedetectionio/tests/conftest.py b/changedetectionio/tests/conftest.py index 672860c6..3b6b4dd9 100644 --- a/changedetectionio/tests/conftest.py +++ b/changedetectionio/tests/conftest.py @@ -29,24 +29,6 @@ def reportlog(pytestconfig): logger.remove(handler_id) -@pytest.fixture(scope="session") -def live_server_options(): - """Configure live_server to run in threaded mode for concurrent requests. - - CRITICAL: Without threaded=True, the test server is single-threaded and will - serialize all requests. This breaks tests that verify concurrent worker behavior. - - With threaded=True: - - Multiple workers can fetch from test server concurrently - - Test endpoints with time.sleep(delay) don't block other requests - - Real concurrency testing is possible - """ - return { - 'threaded': True, # Enable multi-threading for concurrent requests - 'port': 0, # Use random available port - } - - @pytest.fixture def environment(mocker): """Mock arrow.now() to return a fixed datetime for testing jinja2 time extension.""" @@ -162,7 +144,7 @@ def prepare_test_function(live_server, datastore_path): CRITICAL for xdist per-test isolation: - Reuses the SAME datastore instance (so blueprint references stay valid) - Clears all watches and state for a clean slate - - First watch will get uuid=uuid + - First watch will get uuid="first" """ routes = [rule.rule for rule in live_server.app.url_map.iter_rules()] if '/test-random-content-endpoint' not in routes: @@ -175,60 +157,14 @@ def prepare_test_function(live_server, datastore_path): # CRITICAL: Get datastore and stop it from writing stale data datastore = live_server.app.config.get('DATASTORE') - # CRITICAL: Clear ALL global state that persists between tests - from changedetectionio.flask_app import update_q, notification_q, notification_debug_log - - # Clear update queue + # Clear the queue before starting the test to prevent state leakage + from changedetectionio.flask_app import update_q while not update_q.empty(): try: update_q.get_nowait() except: break - # Clear notification queue (was missing!) - while not notification_q.empty(): - try: - notification_q.get_nowait() - except: - break - - # Clear notification debug log (accumulates across tests!) - notification_debug_log.clear() - - # Clear SALTED_PASS env var if set by previous test - if 'SALTED_PASS' in os.environ: - del os.environ['SALTED_PASS'] - - # Stop background thread with longer timeout - datastore.stop_thread = True - if hasattr(datastore, 'save_data_thread') and datastore.save_data_thread: - datastore.save_data_thread.join(timeout=2.0) - - # Prevent background thread from writing during cleanup/reload - datastore.needs_write = False - datastore.needs_write_urgent = False - - # Reset dirty tracking - datastore._dirty_watches = set() - datastore._dirty_settings = False - datastore._watch_hashes = {} - - # CRITICAL: Clean up any files from previous tests - cleanup(datastore_path) - - # Reset stop_thread so reload_state can start new thread - datastore.stop_thread = False - - # Reload state with clean data (no default watches) - datastore.reload_state( - datastore_path=datastore_path, - include_default_watches=False, - version_tag='0.0.0' - ) - live_server.app.secret_key = init_app_secret(datastore_path) - logger.debug(f"prepare_test_function: Reloaded datastore at {hex(id(datastore))}") - logger.debug(f"prepare_test_function: Path {datastore.datastore_path}") - # Add test helper methods to the app for worker management def set_workers(count): """Set the number of workers for testing - brutal shutdown, no delays""" @@ -237,7 +173,7 @@ def prepare_test_function(live_server, datastore_path): current_count = worker_pool.get_worker_count() - # Special case: Setting to 0 means shutdown all workers brutally + # Special case: Setting to 0 means shutdown all workers brutally if count == 0: logger.debug(f"Brutally shutting down all {current_count} workers") worker_pool.shutdown_workers() @@ -277,6 +213,31 @@ def prepare_test_function(live_server, datastore_path): live_server.app.set_workers = set_workers live_server.app.check_all_workers_alive = check_all_workers_alive + + + + # Prevent background thread from writing during cleanup/reload + datastore.needs_write = False + datastore.needs_write_urgent = False + + # CRITICAL: Clean up any files from previous tests + # This ensures a completely clean directory + cleanup(datastore_path) + + # CRITICAL: Reload the EXISTING datastore instead of creating a new one + # This keeps blueprint references valid (they capture datastore at construction) + # reload_state() completely resets the datastore to a clean state + + # Reload state with clean data (no default watches) + datastore.reload_state( + datastore_path=datastore_path, + include_default_watches=False, + version_tag=datastore.data.get('version_tag', '0.0.0') + ) + live_server.app.secret_key = init_app_secret(datastore_path) + logger.debug(f"prepare_test_function: Reloaded datastore at {hex(id(datastore))}") + logger.debug(f"prepare_test_function: Path {datastore.datastore_path}") + yield # Cleanup: Clear watches and queue after test 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 cfb7d303..514a9965 100644 --- a/changedetectionio/tests/custom_browser_url/test_custom_browser_url.py +++ b/changedetectionio/tests/custom_browser_url/test_custom_browser_url.py @@ -37,13 +37,13 @@ def do_test(client, live_server, make_test_use_extra_browser=False): # So the name should appear in the edit page under "Request" > "Fetch Method" res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), follow_redirects=True ) assert b'custom browser URL' in res.data res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ # 'run_customer_browser_url_tests.sh' will search for this string to know if we hit the right browser container or not "url": "https://changedetection.io/ci-test.html?custom-browser-search-string=1", @@ -66,7 +66,7 @@ def do_test(client, live_server, make_test_use_extra_browser=False): wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) assert b'cool it works' in res.data diff --git a/changedetectionio/tests/fetchers/test_content.py b/changedetectionio/tests/fetchers/test_content.py index c3b70017..89623fdc 100644 --- a/changedetectionio/tests/fetchers/test_content.py +++ b/changedetectionio/tests/fetchers/test_content.py @@ -24,12 +24,19 @@ def test_fetch_webdriver_content(client, live_server, measure_memory_usage, data ) assert b"Settings updated." in res.data - uuid = client.application.config.get('DATASTORE').add_watch(url="https://changedetection.io/ci-test.html") + # Add our URL to the import page + res = client.post( + url_for("imports.import_page"), + data={"urls": "https://changedetection.io/ci-test.html"}, + follow_redirects=True + ) + + assert b"1 Imported" in res.data wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) logging.getLogger().info("Looking for correct fetched HTML (text) from server") diff --git a/changedetectionio/tests/fetchers/test_custom_js_before_content.py b/changedetectionio/tests/fetchers/test_custom_js_before_content.py index 9679b516..2ee8836d 100644 --- a/changedetectionio/tests/fetchers/test_custom_js_before_content.py +++ b/changedetectionio/tests/fetchers/test_custom_js_before_content.py @@ -12,11 +12,16 @@ def test_execute_custom_js(client, live_server, measure_memory_usage, datastore_ test_url = test_url.replace('localhost.localdomain', 'cdio') test_url = test_url.replace('localhost', 'cdio') + res = client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url, "tags": '', 'edit_and_watch_submit_button': 'Edit > Watch'}, + follow_redirects=True + ) - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url, extras={'paused': True}) + assert b"Watch added in Paused state, saving will unpause" in res.data res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid, unpause_on_save=1), + url_for("ui.ui_edit.edit_page", uuid="first", unpause_on_save=1), data={ "url": test_url, "tags": "", diff --git a/changedetectionio/tests/proxy_list/test_multiple_proxy.py b/changedetectionio/tests/proxy_list/test_multiple_proxy.py index 520ca735..b81cd816 100644 --- a/changedetectionio/tests/proxy_list/test_multiple_proxy.py +++ b/changedetectionio/tests/proxy_list/test_multiple_proxy.py @@ -10,11 +10,16 @@ def test_preferred_proxy(client, live_server, measure_memory_usage, datastore_pa url = "http://chosen.changedetection.io" - uuid = client.application.config.get('DATASTORE').add_watch(url=url, extras={'paused': True}) + res = client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": url, "tags": '', 'edit_and_watch_submit_button': 'Edit > Watch'}, + follow_redirects=True + ) + assert b"Watch added in Paused state, saving will unpause" in res.data wait_for_all_checks(client) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid, unpause_on_save=1), + url_for("ui.ui_edit.edit_page", uuid="first", unpause_on_save=1), data={ "include_filters": "", "fetch_backend": 'html_webdriver' if os.getenv('PLAYWRIGHT_DRIVER_URL') else 'html_requests', diff --git a/changedetectionio/tests/proxy_list/test_noproxy.py b/changedetectionio/tests/proxy_list/test_noproxy.py index bf379ad5..c3b4c3e4 100644 --- a/changedetectionio/tests/proxy_list/test_noproxy.py +++ b/changedetectionio/tests/proxy_list/test_noproxy.py @@ -11,12 +11,9 @@ def test_noproxy_option(client, live_server, measure_memory_usage, datastore_pat # Call this URL then scan the containers that it never went through them url = "http://noproxy.changedetection.io" - - uuid = client.application.config.get('DATASTORE').add_watch(url=url, extras={'paused': True}) - # Should only be available when a proxy is setup res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid, unpause_on_save=1)) + url_for("ui.ui_edit.edit_page", uuid="first", unpause_on_save=1)) assert b'No proxy' not in res.data # Setup a proxy diff --git a/changedetectionio/tests/proxy_list/test_proxy_noconnect.py b/changedetectionio/tests/proxy_list/test_proxy_noconnect.py index 6db0d8d0..93b7e8cb 100644 --- a/changedetectionio/tests/proxy_list/test_proxy_noconnect.py +++ b/changedetectionio/tests/proxy_list/test_proxy_noconnect.py @@ -32,7 +32,11 @@ def test_proxy_noconnect_custom(client, live_server, measure_memory_usage, datas assert b"Settings updated." in res.data test_url = "https://changedetection.io" - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url, extras={'paused': True}) + res = client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url, "tags": '', 'edit_and_watch_submit_button': 'Edit > Watch'}, + follow_redirects=True + ) assert b"Watch added in Paused state, saving will unpause" in res.data @@ -44,7 +48,7 @@ def test_proxy_noconnect_custom(client, live_server, measure_memory_usage, datas } res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid, unpause_on_save=1), + url_for("ui.ui_edit.edit_page", uuid="first", unpause_on_save=1), data=options, follow_redirects=True ) diff --git a/changedetectionio/tests/proxy_list/test_select_custom_proxy.py b/changedetectionio/tests/proxy_list/test_select_custom_proxy.py index 06d032f4..c0602247 100644 --- a/changedetectionio/tests/proxy_list/test_select_custom_proxy.py +++ b/changedetectionio/tests/proxy_list/test_select_custom_proxy.py @@ -25,16 +25,22 @@ def test_select_custom(client, live_server, measure_memory_usage, datastore_path assert b"Settings updated." in res.data + res = client.post( + url_for("imports.import_page"), + # Because a URL wont show in squid/proxy logs due it being SSLed + # Use plain HTTP or a specific domain-name here + data={"urls": "https://changedetection.io/CHANGELOG.txt"}, + follow_redirects=True + ) - uuid = client.application.config.get('DATASTORE').add_watch(url='https://changedetection.io/CHANGELOG.txt') - res = client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) + assert b"1 Imported" in res.data wait_for_all_checks(client) res = client.get(url_for("watchlist.index")) assert b'Proxy Authentication Required' not in res.data res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) # We should see something via proxy diff --git a/changedetectionio/tests/proxy_socks5/test_socks5_proxy.py b/changedetectionio/tests/proxy_socks5/test_socks5_proxy.py index 99c40b15..99b6d54d 100644 --- a/changedetectionio/tests/proxy_socks5/test_socks5_proxy.py +++ b/changedetectionio/tests/proxy_socks5/test_socks5_proxy.py @@ -44,17 +44,21 @@ def test_socks5(client, live_server, measure_memory_usage, datastore_path): test_url = test_url.replace('localhost.localdomain', 'cdio') test_url = test_url.replace('localhost', 'cdio') - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url, extras={'paused': True}) - + res = client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url, "tags": '', 'edit_and_watch_submit_button': 'Edit > Watch'}, + follow_redirects=True + ) + assert b"Watch added in Paused state, saving will unpause" in res.data res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid, unpause_on_save=1), + url_for("ui.ui_edit.edit_page", uuid="first", unpause_on_save=1), ) # check the proxy is offered as expected assert b'ui-0socks5proxy' in res.data res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid, unpause_on_save=1), + url_for("ui.ui_edit.edit_page", uuid="first", unpause_on_save=1), data={ "include_filters": "", "fetch_backend": 'html_webdriver' if os.getenv('PLAYWRIGHT_DRIVER_URL') else 'html_requests', @@ -70,7 +74,7 @@ def test_socks5(client, live_server, measure_memory_usage, datastore_path): wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) diff --git a/changedetectionio/tests/proxy_socks5/test_socks5_proxy_sources.py b/changedetectionio/tests/proxy_socks5/test_socks5_proxy_sources.py index 7d70d04f..f0bf81c6 100644 --- a/changedetectionio/tests/proxy_socks5/test_socks5_proxy_sources.py +++ b/changedetectionio/tests/proxy_socks5/test_socks5_proxy_sources.py @@ -31,16 +31,21 @@ def test_socks5_from_proxiesjson_file(client, live_server, measure_memory_usage, res = client.get(url_for("settings.settings_page")) assert b'name="requests-proxy" type="radio" value="socks5proxy"' in res.data - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url, extras={'paused': True}) + res = client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url, "tags": '', 'edit_and_watch_submit_button': 'Edit > Watch'}, + follow_redirects=True + ) + assert b"Watch added in Paused state, saving will unpause" in res.data res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid, unpause_on_save=1), + url_for("ui.ui_edit.edit_page", uuid="first", unpause_on_save=1), ) # check the proxy is offered as expected assert b'name="proxy" type="radio" value="socks5proxy"' in res.data res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid, unpause_on_save=1), + url_for("ui.ui_edit.edit_page", uuid="first", unpause_on_save=1), data={ "include_filters": "", "fetch_backend": 'html_webdriver' if os.getenv('PLAYWRIGHT_DRIVER_URL') else 'html_requests', @@ -56,7 +61,7 @@ def test_socks5_from_proxiesjson_file(client, live_server, measure_memory_usage, wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) diff --git a/changedetectionio/tests/smtp/test_notification_smtp.py b/changedetectionio/tests/smtp/test_notification_smtp.py index fd055665..01ee3390 100644 --- a/changedetectionio/tests/smtp/test_notification_smtp.py +++ b/changedetectionio/tests/smtp/test_notification_smtp.py @@ -377,7 +377,13 @@ def test_check_notification_email_formats_default_Text_override_HTML(client, liv # Add a watch and trigger a HTTP POST test_url = url_for('test_endpoint',content_type="text/html", _external=True) - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url, tag='nice one') + res = client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url, "tags": 'nice one'}, + follow_redirects=True + ) + + assert b"Watch added" in res.data #################################### FIRST SITUATION, PLAIN TEXT NOTIFICATION IS WANTED BUT WE HAVE HTML IN OUR TEMPLATE AND CONTENT ########## wait_for_all_checks(client) @@ -410,7 +416,7 @@ def test_check_notification_email_formats_default_Text_override_HTML(client, liv # Now override as HTML format res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, "notification_format": 'html', diff --git a/changedetectionio/tests/test_access_control.py b/changedetectionio/tests/test_access_control.py index d66df911..fc370195 100644 --- a/changedetectionio/tests/test_access_control.py +++ b/changedetectionio/tests/test_access_control.py @@ -12,7 +12,13 @@ def test_check_access_control(app, client, live_server, measure_memory_usage, da assert b"Remove password" not in res.data # add something that we can hit via diff page later - uuid = client.application.config.get('DATASTORE').add_watch(url=url_for('test_random_content_endpoint', _external=True)) + res = c.post( + url_for("imports.import_page"), + data={"urls": url_for('test_random_content_endpoint', _external=True)}, + follow_redirects=True + ) + + assert b"1 Imported" in res.data # causes a 'Popped wrong request context.' error when client. is accessed? wait_for_all_checks(client) @@ -39,7 +45,7 @@ def test_check_access_control(app, client, live_server, measure_memory_usage, da assert b"Login" in res.data # The diff page should return something valid when logged out - res = c.get(url_for("ui.ui_diff.diff_history_page", uuid=uuid)) + res = c.get(url_for("ui.ui_diff.diff_history_page", uuid="first")) assert b'Random content' in res.data # access to assets should work (check_authentication) @@ -175,5 +181,5 @@ def test_check_access_control(app, client, live_server, measure_memory_usage, da assert res.status_code == 403 # The diff page should return something valid when logged out - res = c.get(url_for("ui.ui_diff.diff_history_page", uuid=uuid)) + res = c.get(url_for("ui.ui_diff.diff_history_page", uuid="first")) assert b'Random content' not in res.data diff --git a/changedetectionio/tests/test_add_replace_remove_filter.py b/changedetectionio/tests/test_add_replace_remove_filter.py index 2f0f7109..5f715e33 100644 --- a/changedetectionio/tests/test_add_replace_remove_filter.py +++ b/changedetectionio/tests/test_add_replace_remove_filter.py @@ -57,7 +57,7 @@ def test_check_removed_line_contains_trigger(client, live_server, measure_memory # Goto the edit page, add our ignore text # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"trigger_text": 'The golden line', "url": test_url, 'fetch_backend': "html_requests", @@ -145,7 +145,7 @@ def test_check_add_line_contains_trigger(client, live_server, measure_memory_usa # Goto the edit page, add our ignore text # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"trigger_text": 'Oh yes please', "url": test_url, 'processor': 'text_json_diff', diff --git a/changedetectionio/tests/test_api.py b/changedetectionio/tests/test_api.py index c804b8de..19f1d0f6 100644 --- a/changedetectionio/tests/test_api.py +++ b/changedetectionio/tests/test_api.py @@ -253,7 +253,7 @@ def test_api_simple(client, live_server, measure_memory_usage, datastore_path): assert watch.get('viewed') == False # Loading the most recent snapshot should force viewed to become true - client.get(url_for("ui.ui_diff.diff_history_page", uuid=watch_uuid), follow_redirects=True) + client.get(url_for("ui.ui_diff.diff_history_page", uuid="first"), follow_redirects=True) time.sleep(3) # Fetch the whole watch again, viewed should be true diff --git a/changedetectionio/tests/test_auth.py b/changedetectionio/tests/test_auth.py index 6c89d131..2e073e21 100644 --- a/changedetectionio/tests/test_auth.py +++ b/changedetectionio/tests/test_auth.py @@ -18,7 +18,7 @@ def test_basic_auth(client, live_server, measure_memory_usage, datastore_path): time.sleep(1) # Check form validation res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": "", "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) @@ -26,7 +26,7 @@ def test_basic_auth(client, live_server, measure_memory_usage, datastore_path): wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) diff --git a/changedetectionio/tests/test_backend.py b/changedetectionio/tests/test_backend.py index 9f1add1a..c17fc8d7 100644 --- a/changedetectionio/tests/test_backend.py +++ b/changedetectionio/tests/test_backend.py @@ -44,7 +44,7 @@ def test_check_basic_change_detection_functionality(client, live_server, measure # Check HTML conversion detected and workd res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) # Check this class does not appear (that we didnt see the actual source) @@ -90,7 +90,7 @@ def test_check_basic_change_detection_functionality(client, live_server, measure # Check the [preview] pulls the right one res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) assert b'which has this one new line' in res.data @@ -272,7 +272,7 @@ got it\r\n ### check the front end res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) assert b"some random text that should be split by line\n" in res.data @@ -332,7 +332,7 @@ got it\r\n ### check the front end res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -377,7 +377,7 @@ def test_plaintext_even_if_xml_content(client, live_server, measure_memory_usage wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -404,7 +404,7 @@ def test_plaintext_even_if_xml_content_and_can_apply_filters(client, live_server wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) diff --git a/changedetectionio/tests/test_clone.py b/changedetectionio/tests/test_clone.py index 0220cde2..02231301 100644 --- a/changedetectionio/tests/test_clone.py +++ b/changedetectionio/tests/test_clone.py @@ -23,7 +23,7 @@ def test_clone_functionality(client, live_server, measure_memory_usage, datastor time.sleep(1) res = client.get( - url_for("ui.form_clone", uuid=uuid), + url_for("ui.form_clone", uuid="first"), follow_redirects=True ) existing_uuids = set() diff --git a/changedetectionio/tests/test_conditions.py b/changedetectionio/tests/test_conditions.py index 345f9b1b..2a35beca 100644 --- a/changedetectionio/tests/test_conditions.py +++ b/changedetectionio/tests/test_conditions.py @@ -69,7 +69,7 @@ def test_conditions_with_text_and_number(client, live_server, measure_memory_usa # 1. The page filtered text must contain "5" (first digit of value) # 2. The extracted number should be >= 20 and <= 100 res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, "fetch_backend": "html_requests", @@ -230,7 +230,7 @@ def test_wordcount_conditions_plugin(client, live_server, measure_memory_usage, # Check it saved res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), ) # Assert the word count is counted correctly diff --git a/changedetectionio/tests/test_css_selector.py b/changedetectionio/tests/test_css_selector.py index a87e1de2..03914ec4 100644 --- a/changedetectionio/tests/test_css_selector.py +++ b/changedetectionio/tests/test_css_selector.py @@ -91,7 +91,7 @@ def test_check_markup_include_filters_restriction(client, live_server, measure_m # Goto the edit page, add our ignore text # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": include_filters, "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) @@ -99,7 +99,7 @@ def test_check_markup_include_filters_restriction(client, live_server, measure_m time.sleep(1) # Check it saved res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), ) assert bytes(include_filters.encode('utf-8')) in res.data @@ -142,7 +142,7 @@ def test_check_multiple_filters(client, live_server, measure_memory_usage, datas # Goto the edit page, add our ignore text # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": include_filters, "url": test_url, "tags": "", @@ -157,7 +157,7 @@ def test_check_multiple_filters(client, live_server, measure_memory_usage, datas wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -193,7 +193,7 @@ def test_filter_is_empty_help_suggestion(client, live_server, measure_memory_usa # Goto the edit page, add our ignore text # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": include_filters, "url": test_url, "tags": "", diff --git a/changedetectionio/tests/test_element_removal.py b/changedetectionio/tests/test_element_removal.py index 5a14defd..5fde2206 100644 --- a/changedetectionio/tests/test_element_removal.py +++ b/changedetectionio/tests/test_element_removal.py @@ -155,15 +155,17 @@ def test_element_removal_full(client, live_server, measure_memory_usage, datasto # Add our URL to the import page test_url = url_for("test_endpoint", _external=True) - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) - + res = client.post( + url_for("imports.import_page"), data={"urls": test_url}, follow_redirects=True + ) + assert b"1 Imported" in res.data wait_for_all_checks(client) # 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" res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "subtractive_selectors": subtractive_selectors_data, "url": test_url, @@ -179,7 +181,7 @@ def test_element_removal_full(client, live_server, measure_memory_usage, datasto # Check it saved res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), ) assert bytes(subtractive_selectors_data.encode("utf-8")) in res.data @@ -190,7 +192,7 @@ def test_element_removal_full(client, live_server, measure_memory_usage, datasto wait_for_all_checks(client) # so that we set the state to 'has-unread-changes' after all the edits - client.get(url_for("ui.ui_diff.diff_history_page", uuid=uuid)) + client.get(url_for("ui.ui_diff.diff_history_page", uuid="first")) # Make a change to header/footer/nav set_modified_response(datastore_path=datastore_path) @@ -237,7 +239,7 @@ body > table > tr:nth-child(3) > td:nth-child(3)""", wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) diff --git a/changedetectionio/tests/test_encoding.py b/changedetectionio/tests/test_encoding.py index c8b59b3b..cbc1595b 100644 --- a/changedetectionio/tests/test_encoding.py +++ b/changedetectionio/tests/test_encoding.py @@ -41,7 +41,7 @@ def test_check_encoding_detection(client, live_server, measure_memory_usage, dat assert live_server.app.config['DATASTORE'].data['watching'][uuid]['content-type'] == "text/html" res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -63,7 +63,7 @@ def test_check_encoding_detection_missing_content_type_header(client, live_serve wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) diff --git a/changedetectionio/tests/test_errorhandling.py b/changedetectionio/tests/test_errorhandling.py index 9bd8879d..ace9f5e6 100644 --- a/changedetectionio/tests/test_errorhandling.py +++ b/changedetectionio/tests/test_errorhandling.py @@ -34,7 +34,7 @@ def _runner_test_http_errors(client, live_server, http_code, expected_text, data # Error viewing tabs should appear res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -90,8 +90,13 @@ def test_low_level_errors_clear_correctly(client, live_server, measure_memory_us # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - uuidA = client.application.config.get('DATASTORE').add_watch(url="https://dfkjasdkfjaidjfsdajfksdajfksdjfDOESNTEXIST.com") + res = client.post( + url_for("imports.import_page"), + data={"urls": "https://dfkjasdkfjaidjfsdajfksdajfksdjfDOESNTEXIST.com"}, + follow_redirects=True + ) + assert b"1 Imported" in res.data wait_for_all_checks(client) # We should see the DNS error @@ -108,7 +113,7 @@ def test_low_level_errors_clear_correctly(client, live_server, measure_memory_us # Update with what should work client.post( - url_for("ui.ui_edit.edit_page", uuid=uuidA), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, "fetch_backend": "html_requests", diff --git a/changedetectionio/tests/test_extract_csv.py b/changedetectionio/tests/test_extract_csv.py index 7b50f046..69466e43 100644 --- a/changedetectionio/tests/test_extract_csv.py +++ b/changedetectionio/tests/test_extract_csv.py @@ -18,9 +18,15 @@ def test_check_extract_text_from_diff(client, live_server, measure_memory_usage, # live_server_setup(live_server) # Setup on conftest per function # Add our URL to the import page - uuid = client.application.config.get('DATASTORE').add_watch(url=url_for('test_endpoint', _external=True)) + res = client.post( + url_for("imports.import_page"), + data={"urls": url_for('test_endpoint', _external=True)}, + follow_redirects=True + ) + + assert b"1 Imported" in res.data wait_for_all_checks(client) - res = client.get(url_for("ui.ui_diff.diff_history_page_extract_GET", uuid=uuid)) + res = client.get(url_for("ui.ui_diff.diff_history_page_extract_GET", uuid="first")) assert res.status_code == 200 assert b'extract_regex' in res.data @@ -40,7 +46,7 @@ def test_check_extract_text_from_diff(client, live_server, measure_memory_usage, res = client.post( - url_for("ui.ui_diff.diff_history_page_extract_POST", uuid=uuid), + url_for("ui.ui_diff.diff_history_page_extract_POST", uuid="first"), data={"extract_regex": "Now it's ([0-9\.]+)", "extract_submit_button": "Extract as CSV"}, follow_redirects=False diff --git a/changedetectionio/tests/test_extract_regex.py b/changedetectionio/tests/test_extract_regex.py index c4f1d626..c51ad42b 100644 --- a/changedetectionio/tests/test_extract_regex.py +++ b/changedetectionio/tests/test_extract_regex.py @@ -85,7 +85,7 @@ def test_check_filter_multiline(client, live_server, measure_memory_usage, datas # Goto the edit page, add our ignore text # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": '', # Test a regex and a plaintext 'extract_text': '/something.+?6 billion.+?lines/si\r\nand this should be', @@ -107,7 +107,7 @@ def test_check_filter_multiline(client, live_server, measure_memory_usage, datas assert b'not at the start of the expression' not in res.data res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) # Plaintext that doesnt look like a regex should match also @@ -137,7 +137,7 @@ def test_check_filter_and_regex_extract(client, live_server, measure_memory_usag # Goto the edit page, add our ignore text # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": include_filters, 'extract_text': '/\d+ online/\r\n/\d+ guests/\r\n/somecase insensitive \d+/i\r\n/somecase insensitive (345\d)/i\r\n/issue1828.+?2022/i', "url": test_url, @@ -174,7 +174,7 @@ def test_check_filter_and_regex_extract(client, live_server, measure_memory_usag # Check HTML conversion detected and workd res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) diff --git a/changedetectionio/tests/test_filter_exist_changes.py b/changedetectionio/tests/test_filter_exist_changes.py index c2f2b7f6..d5dccd72 100644 --- a/changedetectionio/tests/test_filter_exist_changes.py +++ b/changedetectionio/tests/test_filter_exist_changes.py @@ -51,8 +51,15 @@ def test_filter_doesnt_exist_then_exists_should_get_notification(client, live_se # Give the endpoint time to spin up time.sleep(1) set_response_without_filter(datastore_path=datastore_path) + + # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + res = client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url, "tags": 'cinema'}, + follow_redirects=True + ) + assert b"Watch added" in res.data # Give the thread time to pick up the first version time.sleep(3) @@ -93,7 +100,7 @@ def test_filter_doesnt_exist_then_exists_should_get_notification(client, live_se "time_between_check_use_default": "y"}) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data=notification_form_data, follow_redirects=True ) diff --git a/changedetectionio/tests/test_group.py b/changedetectionio/tests/test_group.py index 1d4441b5..e02a7e8d 100644 --- a/changedetectionio/tests/test_group.py +++ b/changedetectionio/tests/test_group.py @@ -51,27 +51,31 @@ def test_setup_group_tag(client, live_server, measure_memory_usage, datastore_pa ) assert b"Tag added" in res.data assert b"test-tag" in res.data - tag_uuid = get_UUID_for_tag_name(client, name="test-tag") res = client.post( - url_for("tags.form_tag_edit_submit", uuid=tag_uuid), + url_for("tags.form_tag_edit_submit", uuid="first"), data={"name": "test-tag", "include_filters": '#only-this', "subtractive_selectors": '#not-this'}, follow_redirects=True ) assert b"Updated" in res.data - + tag_uuid = get_UUID_for_tag_name(client, name="test-tag") res = client.get( - url_for("tags.form_tag_edit", uuid=tag_uuid) + url_for("tags.form_tag_edit", uuid="first") ) assert b"#only-this" in res.data assert b"#not-this" in res.data # Tag should be setup and ready, now add a watch - test_url = url_for('test_endpoint', _external=True)+"?first-imported=1" - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url, tag="test-tag, extra-import-tag") + test_url = url_for('test_endpoint', _external=True) + res = client.post( + url_for("imports.import_page"), + data={"urls": test_url + "?first-imported=1 test-tag, extra-import-tag"}, + follow_redirects=True + ) + assert b"1 Imported" in res.data res = client.get(url_for("watchlist.index")) assert b'import-tag' in res.data @@ -90,14 +94,14 @@ def test_setup_group_tag(client, live_server, measure_memory_usage, datastore_pa assert b'Warning, no filters were found' not in res.data res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) assert b'Should be only this' in res.data assert b'And never this' not in res.data res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), follow_redirects=True ) # 2307 the UI notice should appear in the placeholder @@ -142,7 +146,7 @@ def test_tag_import_singular(client, live_server, measure_memory_usage, datastor ) # Should be only 1 tag because they both had the same assert len(live_server.app.config['DATASTORE'].data['settings']['application'].get('tags')) ==1 - wait_for_all_checks() + delete_all_watches(client) def test_tag_add_in_ui(client, live_server, measure_memory_usage, datastore_path): @@ -339,17 +343,17 @@ def test_order_of_filters_tag_filter_and_watch_filter(client, live_server, measu '#only-this', '#only-this', ] - tag_uuid = get_UUID_for_tag_name(client, name="test-tag-keep-order") + res = client.post( - url_for("tags.form_tag_edit_submit", uuid=tag_uuid), + url_for("tags.form_tag_edit_submit", uuid="first"), data={"name": "test-tag-keep-order", "include_filters": '\n'.join(tag_filters) }, follow_redirects=True ) assert b"Updated" in res.data - + tag_uuid = get_UUID_for_tag_name(client, name="test-tag-keep-order") res = client.get( - url_for("tags.form_tag_edit", uuid=tag_uuid) + url_for("tags.form_tag_edit", uuid="first") ) assert b"#only-this" in res.data @@ -405,7 +409,7 @@ def test_order_of_filters_tag_filter_and_watch_filter(client, live_server, measu ] res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": '\n'.join(filters), "url": test_url, "tags": "test-tag-keep-order", @@ -418,7 +422,7 @@ def test_order_of_filters_tag_filter_and_watch_filter(client, live_server, measu wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) diff --git a/changedetectionio/tests/test_history_consistency.py b/changedetectionio/tests/test_history_consistency.py index c70087d0..3a344102 100644 --- a/changedetectionio/tests/test_history_consistency.py +++ b/changedetectionio/tests/test_history_consistency.py @@ -162,7 +162,7 @@ def test_check_text_history_view(client, live_server, measure_memory_usage, data client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) - res = client.get(url_for("ui.ui_diff.diff_history_page", uuid=uuid)) + res = client.get(url_for("ui.ui_diff.diff_history_page", uuid="first")) assert b'test-one' in res.data assert b'test-two' in res.data @@ -174,7 +174,7 @@ def test_check_text_history_view(client, live_server, measure_memory_usage, data wait_for_all_checks(client) # It should remember the last viewed time, so the first difference is not shown - res = client.get(url_for("ui.ui_diff.diff_history_page", uuid=uuid)) + res = client.get(url_for("ui.ui_diff.diff_history_page", uuid="first")) assert b'test-three' in res.data assert b'test-two' in res.data assert b'test-one' not in res.data diff --git a/changedetectionio/tests/test_ignore_text.py b/changedetectionio/tests/test_ignore_text.py index 9e5af96c..37868fac 100644 --- a/changedetectionio/tests/test_ignore_text.py +++ b/changedetectionio/tests/test_ignore_text.py @@ -107,7 +107,7 @@ def test_check_ignore_text_functionality(client, live_server, measure_memory_usa # Goto the edit page, add our ignore text # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"ignore_text": ignore_text, "url": test_url, 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) @@ -115,7 +115,7 @@ def test_check_ignore_text_functionality(client, live_server, measure_memory_usa # Check it saved res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), ) assert bytes(ignore_text.encode('utf-8')) in res.data @@ -131,7 +131,7 @@ def test_check_ignore_text_functionality(client, live_server, measure_memory_usa assert b'/test-endpoint' in res.data - res = client.get(url_for("ui.ui_preview.preview_page", uuid=uuid)) + res = client.get(url_for("ui.ui_preview.preview_page", uuid="first")) # nothing ignored because none of the text matched assert b'ignored_line_numbers = []' in res.data @@ -158,7 +158,7 @@ def test_check_ignore_text_functionality(client, live_server, measure_memory_usa res = client.get(url_for("watchlist.index")) assert b'has-unread-changes' in res.data - res = client.get(url_for("ui.ui_preview.preview_page", uuid=uuid)) + res = client.get(url_for("ui.ui_preview.preview_page", uuid="first")) # SHOULD BE be in the preview, it was added in set_modified_original_ignore_response() # and we have "new ignore stuff" in ignore_text @@ -203,7 +203,7 @@ def _run_test_global_ignore(client, datastore_path, as_source=False, extra_ignor #Adding some ignore text should not trigger a change res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"ignore_text": "something irrelevent but just to check", "url": test_url, 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) diff --git a/changedetectionio/tests/test_ignorehyperlinks.py b/changedetectionio/tests/test_ignorehyperlinks.py index 0165e387..2e870d5f 100644 --- a/changedetectionio/tests/test_ignorehyperlinks.py +++ b/changedetectionio/tests/test_ignorehyperlinks.py @@ -62,7 +62,11 @@ def test_render_anchor_tag_content_true(client, live_server, measure_memory_usag # Add our URL to the import page test_url = url_for("test_endpoint", _external=True) - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + res = client.post( + url_for("imports.import_page"), data={"urls": test_url}, + follow_redirects=True + ) + assert b"1 Imported" in res.data wait_for_all_checks(client) # Trigger a check @@ -78,7 +82,7 @@ def test_render_anchor_tag_content_true(client, live_server, measure_memory_usag wait_for_all_checks(client) # We should not see the rendered anchor tag - res = client.get(url_for("ui.ui_preview.preview_page", uuid=uuid)) + res = client.get(url_for("ui.ui_preview.preview_page", uuid="first")) assert '(/modified_link)' not in res.data.decode() # Goto the settings page, ENABLE render anchor tag @@ -102,7 +106,7 @@ def test_render_anchor_tag_content_true(client, live_server, measure_memory_usag # check that the anchor tag content is rendered - res = client.get(url_for("ui.ui_preview.preview_page", uuid=uuid)) + res = client.get(url_for("ui.ui_preview.preview_page", uuid="first")) assert '(/modified_link)' in res.data.decode() # since the link has changed, and we chose to render anchor tag content, diff --git a/changedetectionio/tests/test_ignorestatuscode.py b/changedetectionio/tests/test_ignorestatuscode.py index b65d0164..c93083fb 100644 --- a/changedetectionio/tests/test_ignorestatuscode.py +++ b/changedetectionio/tests/test_ignorestatuscode.py @@ -100,7 +100,7 @@ def test_403_page_check_works_with_ignore_status_code(client, live_server, measu # Goto the edit page, check our ignore option # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"ignore_status_codes": "y", "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) diff --git a/changedetectionio/tests/test_import.py b/changedetectionio/tests/test_import.py index c7fd1a8b..401e9e41 100644 --- a/changedetectionio/tests/test_import.py +++ b/changedetectionio/tests/test_import.py @@ -95,8 +95,8 @@ def test_import_distillio(client, live_server, measure_memory_usage, datastore_p assert b"Unable to read JSON file, was it broken?" not in res.data assert b"1 Imported from Distill.io" in res.data - uuids = list(client.application.config.get('DATASTORE').data['watching']) - res = client.get( url_for("ui.ui_edit.edit_page", uuid=uuids[0])) + + res = client.get( url_for("ui.ui_edit.edit_page", uuid="first")) assert b"https://unraid.net/blog" in res.data assert b"Unraid | News" in res.data diff --git a/changedetectionio/tests/test_jinja2.py b/changedetectionio/tests/test_jinja2.py index 779fd931..fcca6ab2 100644 --- a/changedetectionio/tests/test_jinja2.py +++ b/changedetectionio/tests/test_jinja2.py @@ -20,13 +20,17 @@ def test_jinja2_in_url_query(client, live_server, measure_memory_usage, datastor # because url_for() will URL-encode the var, but we dont here full_url = "{}?{}".format(test_url, "date={% now 'Europe/Berlin', '%Y' %}.{% now 'Europe/Berlin', '%m' %}.{% now 'Europe/Berlin', '%d' %}", ) - - uuid = client.application.config.get('DATASTORE').add_watch(url=full_url) + res = client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": full_url, "tags": "test"}, + follow_redirects=True + ) + assert b"Watch added" in res.data wait_for_all_checks(client) # It should report nothing found (no new 'has-unread-changes' class) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) assert b'date=2' in res.data @@ -42,13 +46,17 @@ def test_jinja2_time_offset_in_url_query(client, live_server, measure_memory_usa # This should work now with our custom TimeExtension full_url = "{}?{}".format(test_url, "timestamp={% now 'utc' - 'minutes=11', '%Y-%m-%d %H:%M' %}", ) - uuid = client.application.config.get('DATASTORE').add_watch(url=full_url) - + res = client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": full_url, "tags": "test"}, + follow_redirects=True + ) + assert b"Watch added" in res.data wait_for_all_checks(client) # Verify the URL was processed correctly (should not have errors) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) # Should have a valid timestamp in the response diff --git a/changedetectionio/tests/test_jsonpath_jq_selector.py b/changedetectionio/tests/test_jsonpath_jq_selector.py index 83764a9d..d598ecc6 100644 --- a/changedetectionio/tests/test_jsonpath_jq_selector.py +++ b/changedetectionio/tests/test_jsonpath_jq_selector.py @@ -208,9 +208,9 @@ def test_check_json_without_filter(client, live_server, measure_memory_usage, da # Give the thread time to pick it up wait_for_all_checks(client) - time.sleep(1) + res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -289,7 +289,7 @@ def check_json_filter_bool_val(json_filter, client, live_server, datastore_path) # Give the thread time to pick it up wait_for_all_checks(client) - res = client.get(url_for("ui.ui_diff.diff_history_page", uuid=uuid)) + res = client.get(url_for("ui.ui_diff.diff_history_page", uuid="first")) # 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 @@ -353,7 +353,6 @@ def check_json_ext_filter(json_filter, client, live_server, datastore_path): watch = live_server.app.config['DATASTORE'].data['watching'][uuid] dates = list(watch.history.keys()) - time.sleep(1) snapshot_contents = watch.get_history_snapshot(timestamp=dates[0]) assert snapshot_contents[0] == '[' @@ -362,7 +361,7 @@ def check_json_ext_filter(json_filter, client, live_server, datastore_path): res = client.get(url_for("watchlist.index")) assert b'has-unread-changes' in res.data - res = client.get(url_for("ui.ui_preview.preview_page", uuid=uuid)) + res = client.get(url_for("ui.ui_preview.preview_page", uuid="first")) # We should never see 'ForSale' because we are selecting on 'Sold' in the rule, # But we should know it triggered ('has-unread-changes' assert above) @@ -372,7 +371,7 @@ def check_json_ext_filter(json_filter, client, live_server, datastore_path): # And the difference should have both? - res = client.get(url_for("ui.ui_diff.diff_history_page", uuid=uuid)) + res = client.get(url_for("ui.ui_diff.diff_history_page", uuid="first")) assert b'ForSale' in res.data assert b'Sold' in res.data @@ -433,7 +432,7 @@ def test_correct_header_detect(client, live_server, measure_memory_usage, datast assert b'No parsable JSON found in this document' not in res.data res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) diff --git a/changedetectionio/tests/test_notification.py b/changedetectionio/tests/test_notification.py index f51e76ad..be1b5316 100644 --- a/changedetectionio/tests/test_notification.py +++ b/changedetectionio/tests/test_notification.py @@ -121,7 +121,7 @@ def test_check_notification(client, live_server, measure_memory_usage, datastore "time_between_check_use_default": "y"}) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data=notification_form_data, follow_redirects=True ) @@ -131,7 +131,7 @@ def test_check_notification(client, live_server, measure_memory_usage, datastore # Hit the edit page, be sure that we saved it # Re #242 - wasnt saving? res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid)) + url_for("ui.ui_edit.edit_page", uuid="first")) assert bytes(notification_url.encode('utf-8')) in res.data assert bytes("New ChangeDetection.io Notification".encode('utf-8')) in res.data @@ -227,7 +227,7 @@ def test_check_notification(client, live_server, measure_memory_usage, datastore set_original_response(datastore_path=datastore_path) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, "tags": "my tag", diff --git a/changedetectionio/tests/test_notification_errors.py b/changedetectionio/tests/test_notification_errors.py index ab3b342e..7e15fa62 100644 --- a/changedetectionio/tests/test_notification_errors.py +++ b/changedetectionio/tests/test_notification_errors.py @@ -11,7 +11,12 @@ def test_check_notification_error_handling(client, live_server, measure_memory_u # Set a URL and fetch it, then set a notification URL which is going to give errors test_url = url_for('test_endpoint', _external=True) - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + res = client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url, "tags": ''}, + follow_redirects=True + ) + assert b"Watch added" in res.data wait_for_all_checks(client) set_modified_response(datastore_path=datastore_path) @@ -20,7 +25,7 @@ def test_check_notification_error_handling(client, live_server, measure_memory_u broken_notification_url = "jsons://broken-url-xxxxxxxx123/test" res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), # A URL with errors should not block the one that is working data={"notification_urls": f"{broken_notification_url}\r\n{working_notification_url}", "notification_title": "xxx", diff --git a/changedetectionio/tests/test_obfuscations.py b/changedetectionio/tests/test_obfuscations.py index 526361b1..09d8b9b3 100644 --- a/changedetectionio/tests/test_obfuscations.py +++ b/changedetectionio/tests/test_obfuscations.py @@ -33,7 +33,7 @@ def test_obfuscations(client, live_server, measure_memory_usage, datastore_path) # Check HTML conversion detected and workd res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) diff --git a/changedetectionio/tests/test_pdf.py b/changedetectionio/tests/test_pdf.py index 0d12f040..58589309 100644 --- a/changedetectionio/tests/test_pdf.py +++ b/changedetectionio/tests/test_pdf.py @@ -56,7 +56,7 @@ def test_fetch_pdf(client, live_server, measure_memory_usage, datastore_path): # The original checksum should be not be here anymore (cdio adds it to the bottom of the text) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -64,7 +64,7 @@ def test_fetch_pdf(client, live_server, measure_memory_usage, datastore_path): assert changed_md5.encode('utf-8') in res.data res = client.get( - url_for("ui.ui_diff.diff_history_page", uuid=uuid), + url_for("ui.ui_diff.diff_history_page", uuid="first"), follow_redirects=True ) diff --git a/changedetectionio/tests/test_preview_endpoints.py b/changedetectionio/tests/test_preview_endpoints.py index 11b623f5..f595359b 100644 --- a/changedetectionio/tests/test_preview_endpoints.py +++ b/changedetectionio/tests/test_preview_endpoints.py @@ -20,7 +20,7 @@ def test_fetch_pdf(client, live_server, measure_memory_usage, datastore_path): wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -50,7 +50,7 @@ def test_fetch_pdf(client, live_server, measure_memory_usage, datastore_path): # The original checksum should be not be here anymore (cdio adds it to the bottom of the text) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -58,7 +58,7 @@ def test_fetch_pdf(client, live_server, measure_memory_usage, datastore_path): assert changed_md5.encode('utf-8') in res.data res = client.get( - url_for("ui.ui_diff.diff_history_page", uuid=uuid), + url_for("ui.ui_diff.diff_history_page", uuid="first"), follow_redirects=True ) diff --git a/changedetectionio/tests/test_request.py b/changedetectionio/tests/test_request.py index 7091146b..782b04aa 100644 --- a/changedetectionio/tests/test_request.py +++ b/changedetectionio/tests/test_request.py @@ -31,7 +31,7 @@ def test_headers_in_request(client, live_server, measure_memory_usage, datastore # Add some headers to a request res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, "tags": "", @@ -48,7 +48,7 @@ def test_headers_in_request(client, live_server, measure_memory_usage, datastore # The service should echo back the request headers res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -92,7 +92,7 @@ def test_body_in_request(client, live_server, measure_memory_usage, datastore_pa # add the first 'version' res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, "tags": "", @@ -110,7 +110,7 @@ def test_body_in_request(client, live_server, measure_memory_usage, datastore_pa body_value = 'Test Body Value {{ 1+1 }}' body_value_formatted = 'Test Body Value 2' res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, "tags": "", @@ -126,7 +126,7 @@ def test_body_in_request(client, live_server, measure_memory_usage, datastore_pa # The service should echo back the body res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -157,7 +157,7 @@ def test_body_in_request(client, live_server, measure_memory_usage, datastore_pa # Attempt to add a body with a GET method res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, "tags": "", @@ -190,7 +190,7 @@ def test_method_in_request(client, live_server, measure_memory_usage, datastore_ # Attempt to add a method which is not valid res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, "tags": "", @@ -203,7 +203,7 @@ def test_method_in_request(client, live_server, measure_memory_usage, datastore_ # Add a properly formatted body res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, "tags": "", @@ -213,14 +213,13 @@ def test_method_in_request(client, live_server, measure_memory_usage, datastore_ follow_redirects=True ) assert b"Updated watch." in res.data - res = client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) # Give the thread time to pick up the first version wait_for_all_checks(client) # The service should echo back the request verb res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -266,7 +265,7 @@ def test_ua_global_override(client, live_server, measure_memory_usage, datastore wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -277,7 +276,7 @@ def test_ua_global_override(client, live_server, measure_memory_usage, datastore # Add some headers to a request res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, "tags": "testtag", @@ -290,7 +289,7 @@ def test_ua_global_override(client, live_server, measure_memory_usage, datastore assert b"Updated watch." in res.data wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) assert b"agent-from-watch" in res.data @@ -343,7 +342,7 @@ def test_headers_textfile_in_request(client, live_server, measure_memory_usage, # Add some headers to a request res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, "tags": "testtag", @@ -376,7 +375,7 @@ def test_headers_textfile_in_request(client, live_server, measure_memory_usage, if os.getenv('FAST_PUPPETEER_CHROME_FETCHER'): time.sleep(6) - res = client.get(url_for("ui.ui_edit.edit_page", uuid=uuid)) + res = client.get(url_for("ui.ui_edit.edit_page", uuid="first")) assert b"Extra headers file found and will be added to this watch" in res.data # Not needed anymore @@ -385,7 +384,7 @@ def test_headers_textfile_in_request(client, live_server, measure_memory_usage, # The service should echo back the request verb res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -415,7 +414,7 @@ def test_headers_validation(client, live_server, measure_memory_usage, datastore client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, "fetch_backend": 'html_requests', diff --git a/changedetectionio/tests/test_restock_itemprop.py b/changedetectionio/tests/test_restock_itemprop.py index 1fb7e8ae..c2c729ac 100644 --- a/changedetectionio/tests/test_restock_itemprop.py +++ b/changedetectionio/tests/test_restock_itemprop.py @@ -3,8 +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, \ - delete_all_watches, get_UUID_for_tag_name +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 = [ @@ -84,7 +83,11 @@ def test_itemprop_price_change(client, live_server, measure_memory_usage, datast test_url = url_for('test_endpoint', _external=True) set_original_response(props_markup=instock_props[0], price="190.95", datastore_path=datastore_path) - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url, tag='restock tests', extras={'processor': 'restock_diff'}) + client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url, "tags": 'restock tests', 'processor': 'restock_diff'}, + follow_redirects=True + ) # A change in price, should trigger a change by default wait_for_all_checks(client) @@ -105,7 +108,7 @@ def test_itemprop_price_change(client, live_server, measure_memory_usage, datast # turning off price change trigger, but it should show the new price, with no change notification set_original_response(props_markup=instock_props[0], price='120.45', datastore_path=datastore_path) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"restock_settings-follow_price_changes": "", "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) @@ -126,9 +129,11 @@ def _run_test_minmax_limit(client, extra_watch_edit_form, datastore_path): test_url = url_for('test_endpoint', _external=True) set_original_response(props_markup=instock_props[0], price="950.95", datastore_path=datastore_path) - - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url, tag='restock tests', extras={'processor': 'restock_diff'}) - + client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url, "tags": 'restock tests', 'processor': 'restock_diff'}, + follow_redirects=True + ) wait_for_all_checks(client) data = { @@ -141,7 +146,7 @@ def _run_test_minmax_limit(client, extra_watch_edit_form, datastore_path): } data.update(extra_watch_edit_form) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data=data, follow_redirects=True ) @@ -206,18 +211,18 @@ def test_restock_itemprop_minmax(client, live_server, measure_memory_usage, data _run_test_minmax_limit(client, extra_watch_edit_form=extras, datastore_path=datastore_path) def test_restock_itemprop_with_tag(client, live_server, measure_memory_usage, datastore_path): + - tag_name = "test-tag" res = client.post( url_for("tags.form_tag_add"), - data={"name": tag_name}, + data={"name": "test-tag"}, follow_redirects=True ) assert b"Tag added" in res.data - tag_uuid = get_UUID_for_tag_name(client, name=tag_name) + res = client.post( - url_for("tags.form_tag_edit_submit", uuid=tag_uuid), - data={"name": tag_name, + url_for("tags.form_tag_edit_submit", uuid="first"), + data={"name": "test-tag", "restock_settings-follow_price_changes": "y", "restock_settings-price_change_min": 900.0, "restock_settings-price_change_max": 1100.10, @@ -227,7 +232,7 @@ def test_restock_itemprop_with_tag(client, live_server, measure_memory_usage, da ) extras = { - "tags": tag_name + "tags": "test-tag" } _run_test_minmax_limit(client, extra_watch_edit_form=extras,datastore_path=datastore_path) @@ -236,17 +241,22 @@ def test_restock_itemprop_with_tag(client, live_server, measure_memory_usage, da def test_itemprop_percent_threshold(client, live_server, measure_memory_usage, datastore_path): + delete_all_watches(client) + test_url = url_for('test_endpoint', _external=True) set_original_response(props_markup=instock_props[0], price="950.95", datastore_path=datastore_path) - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url, tag="restock tests", extras={'processor':"restock_diff"}) - res = client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) + client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url, "tags": 'restock tests', 'processor': 'restock_diff'}, + follow_redirects=True + ) # A change in price, should trigger a change by default wait_for_all_checks(client) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"restock_settings-follow_price_changes": "y", "restock_settings-price_change_threshold_percent": 5.0, "url": test_url, @@ -290,6 +300,7 @@ def test_itemprop_percent_threshold(client, live_server, measure_memory_usage, d # Re #2600 - Switch the mode to normal type and back, and see if the values stick.. ################################################################################### + uuid = next(iter(live_server.app.config['DATASTORE'].data['watching'])) res = client.post( url_for("ui.ui_edit.edit_page", uuid=uuid), @@ -308,6 +319,9 @@ def test_itemprop_percent_threshold(client, live_server, measure_memory_usage, d res = client.get(url_for("ui.ui_edit.edit_page", uuid=uuid)) assert b'type="text" value="5.05"' in res.data + delete_all_watches(client) + + def test_change_with_notification_values(client, live_server, measure_memory_usage, datastore_path): @@ -381,11 +395,16 @@ def test_change_with_notification_values(client, live_server, measure_memory_usa def test_data_sanity(client, live_server, measure_memory_usage, datastore_path): + delete_all_watches(client) + test_url = url_for('test_endpoint', _external=True) test_url2 = url_for('test_endpoint2', _external=True) set_original_response(props_markup=instock_props[0], price="950.95", datastore_path=datastore_path) - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url, tag="restock tests", extras={'processor':"restock_diff"}) - res = client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) + client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url, "tags": 'restock tests', 'processor': 'restock_diff'}, + follow_redirects=True + ) wait_for_all_checks(client) @@ -404,12 +423,16 @@ def test_data_sanity(client, live_server, measure_memory_usage, datastore_path): ## different test, check the edit page works on an empty request result delete_all_watches(client) - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url2, tag="restock tests", extras={'processor':"restock_diff"}) - res = client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) + + client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url2, "tags": 'restock tests', 'processor': 'restock_diff'}, + follow_redirects=True + ) wait_for_all_checks(client) res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid)) + url_for("ui.ui_edit.edit_page", uuid="first")) assert test_url2.encode('utf-8') in res.data delete_all_watches(client) diff --git a/changedetectionio/tests/test_rss.py b/changedetectionio/tests/test_rss.py index c98e0a74..c0845b2b 100644 --- a/changedetectionio/tests/test_rss.py +++ b/changedetectionio/tests/test_rss.py @@ -124,7 +124,7 @@ def test_basic_cdata_rss_markup(client, live_server, measure_memory_usage, datas wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) assert b'CDATA' not in res.data @@ -166,7 +166,7 @@ def test_rss_xpath_filtering(client, live_server, measure_memory_usage, datastor wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) assert b'CDATA' not in res.data diff --git a/changedetectionio/tests/test_rss_single_watch.py b/changedetectionio/tests/test_rss_single_watch.py index eb0985a5..7bcc88f2 100644 --- a/changedetectionio/tests/test_rss_single_watch.py +++ b/changedetectionio/tests/test_rss_single_watch.py @@ -6,8 +6,7 @@ import xml.etree.ElementTree as ET from flask import url_for from .restock.test_restock import set_original_response -from .util import live_server_setup, wait_for_all_checks, extract_rss_token_from_UI, extract_UUID_from_client, delete_all_watches, \ - set_modified_response, get_UUID_for_tag_name +from .util import live_server_setup, wait_for_all_checks, extract_rss_token_from_UI, extract_UUID_from_client, delete_all_watches, set_modified_response from ..notification import default_notification_format @@ -291,8 +290,6 @@ def test_rss_single_watch_follow_notification_body(client, live_server, measure_ # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) uuid = client.application.config.get('DATASTORE').add_watch(url=test_url, tag="RSS-Custom") - tag_uuid = get_UUID_for_tag_name(client=client, name="rss-custom") - client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) @@ -319,7 +316,7 @@ def test_rss_single_watch_follow_notification_body(client, live_server, measure_ ## Edit the tag notification_body, it should cascade up and become the RSS output res = client.post( - url_for("tags.form_tag_edit_submit", uuid=tag_uuid), + url_for("tags.form_tag_edit_submit", uuid="first"), data={"name": "rss-custom", "notification_body": 'Hello from the group/tag level'}, follow_redirects=True diff --git a/changedetectionio/tests/test_scheduler.py b/changedetectionio/tests/test_scheduler.py index 230bafdf..a8b0d006 100644 --- a/changedetectionio/tests/test_scheduler.py +++ b/changedetectionio/tests/test_scheduler.py @@ -65,13 +65,13 @@ def test_check_basic_scheduler_functionality(client, live_server, measure_memory data.update(scheduler_data) time.sleep(1) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data=data, follow_redirects=True ) assert b"Updated watch." in res.data - res = client.get(url_for("ui.ui_edit.edit_page", uuid=uuid)) + res = client.get(url_for("ui.ui_edit.edit_page", uuid="first")) assert b"Pacific/Kiritimati" in res.data, "Should be Pacific/Kiritimati in placeholder data" # "Edit" should not trigger a check because it's not enabled in the schedule. @@ -143,13 +143,13 @@ def test_check_basic_global_scheduler_functionality(client, live_server, measure # UI Sanity check - res = client.get(url_for("ui.ui_edit.edit_page", uuid=uuid)) + res = client.get(url_for("ui.ui_edit.edit_page", uuid="first")) assert b"Pacific/Kiritimati" in res.data, "Should be Pacific/Kiritimati in placeholder data" #### HITTING SAVE SHOULD NOT TRIGGER A CHECK last_check = live_server.app.config['DATASTORE'].data['watching'][uuid]['last_checked'] res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, "fetch_backend": "html_requests", @@ -179,7 +179,7 @@ def test_validation_time_interval_field(client, live_server, measure_memory_usag res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"trigger_text": 'The golden line', "url": test_url, 'fetch_backend': "html_requests", @@ -194,7 +194,7 @@ def test_validation_time_interval_field(client, live_server, measure_memory_usag # Now set atleast something res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"trigger_text": 'The golden line', "url": test_url, 'fetch_backend': "html_requests", diff --git a/changedetectionio/tests/test_search.py b/changedetectionio/tests/test_search.py index 77b68b8b..e89b7a14 100644 --- a/changedetectionio/tests/test_search.py +++ b/changedetectionio/tests/test_search.py @@ -1,55 +1,73 @@ from flask import url_for +from .util import set_original_response, set_modified_response, live_server_setup +import time + def test_basic_search(client, live_server, measure_memory_usage, datastore_path): - uuidA = client.application.config.get('DATASTORE').add_watch(url='https://localhost:12300?first-result=1') - uuidB = client.application.config.get('DATASTORE').add_watch(url='https://localhost:5000?second-result=1') + urls = ['https://localhost:12300?first-result=1', + 'https://localhost:5000?second-result=1' + ] + res = client.post( + url_for("imports.import_page"), + data={"urls": "\r\n".join(urls)}, + follow_redirects=True + ) + + assert b"2 Imported" in res.data # By URL res = client.get(url_for("watchlist.index") + "?q=first-res") - assert uuidA.encode('utf-8') in res.data - assert uuidB.encode('utf-8') not in res.data + assert urls[0].encode('utf-8') in res.data + assert urls[1].encode('utf-8') not in res.data # By Title res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuidA), - data={"title": "xxx-title", "url": 'https://localhost:12300?first-result=1', "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, + url_for("ui.ui_edit.edit_page", uuid="first"), + data={"title": "xxx-title", "url": urls[0], "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) assert b"Updated watch." in res.data res = client.get(url_for("watchlist.index") + "?q=xxx-title") - assert uuidA.encode('utf-8') in res.data - assert uuidB.encode('utf-8') not in res.data + assert urls[0].encode('utf-8') in res.data + assert urls[1].encode('utf-8') not in res.data def test_search_in_tag_limit(client, live_server, measure_memory_usage, datastore_path): + - uuidA = client.application.config.get('DATASTORE').add_watch(url='https://localhost:12300?first-result=1', tag='tag-one') - uuidB = client.application.config.get('DATASTORE').add_watch(url='https://localhost:5000?second-result=1', tag='tag-two') + urls = ['https://localhost:12300?first-result=1 tag-one', + 'https://localhost:5000?second-result=1 tag-two' + ] + res = client.post( + url_for("imports.import_page"), + data={"urls": "\r\n".join(urls)}, + follow_redirects=True + ) + + assert b"2 Imported" in res.data # By URL res = client.get(url_for("watchlist.index") + "?q=first-res") - - assert 'tag-one'.encode('utf-8') in res.data - # @todo filter from results? - #assert 'tag-two'.encode('utf-8') not in res.data + # Split because of the import tag separation + assert urls[0].split(' ')[0].encode('utf-8') in res.data, urls[0].encode('utf-8') + assert urls[1].split(' ')[0].encode('utf-8') not in res.data, urls[0].encode('utf-8') # By Title res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuidA), - data={"title": "xxx-title", "url": 'https://localhost:12300?first-result=1', "tags": "tag-one", "headers": "", + url_for("ui.ui_edit.edit_page", uuid="first"), + data={"title": "xxx-title", "url": urls[0].split(' ')[0], "tags": urls[0].split(' ')[1], "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) assert b"Updated watch." in res.data res = client.get(url_for("watchlist.index") + "?q=xxx-title") - assert "tag-one".encode('utf-8') in res.data - # @todo filter from results? - # assert "tag-two".encode('utf-8') not in res.data + assert urls[0].split(' ')[0].encode('utf-8') in res.data, urls[0].encode('utf-8') + assert urls[1].split(' ')[0].encode('utf-8') not in res.data, urls[0].encode('utf-8') diff --git a/changedetectionio/tests/test_security.py b/changedetectionio/tests/test_security.py index 42063c0f..c75b8d32 100644 --- a/changedetectionio/tests/test_security.py +++ b/changedetectionio/tests/test_security.py @@ -26,14 +26,18 @@ def set_original_response(datastore_path): def test_bad_access(client, live_server, measure_memory_usage, datastore_path): + res = client.post( + url_for("imports.import_page"), + data={"urls": 'https://localhost'}, + follow_redirects=True + ) - uuid = client.application.config.get('DATASTORE').add_watch(url='https://localhost') - + assert b"1 Imported" in res.data wait_for_all_checks(client) # Attempt to add a body with a GET method res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": 'javascript:alert(document.domain)', "tags": "", @@ -81,9 +85,11 @@ def test_bad_access(client, live_server, measure_memory_usage, datastore_path): def _runner_test_various_file_slash(client, file_uri): - test_url = url_for('test_endpoint', _external=True) - uuid = client.application.config.get('DATASTORE').add_watch(url=file_uri) - + client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": file_uri, "tags": ''}, + follow_redirects=True + ) wait_for_all_checks(client) res = client.get(url_for("watchlist.index")) @@ -95,7 +101,7 @@ def _runner_test_various_file_slash(client, file_uri): if file_uri.startswith('file:///'): # This one should be the full qualified path to the file and should get the contents of this file res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) assert b'_runner_test_various_file_slash' in res.data @@ -158,11 +164,18 @@ def test_xss(client, live_server, measure_memory_usage, datastore_path): def test_xss_watch_last_error(client, live_server, measure_memory_usage, datastore_path): set_original_response(datastore_path=datastore_path) - test_url = url_for('test_endpoint', _external=True) - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + # Add our URL to the import page + res = client.post( + url_for("imports.import_page"), + data={"urls": url_for('test_endpoint', _external=True)}, + follow_redirects=True + ) + + assert b"1 Imported" in res.data + wait_for_all_checks(client) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "include_filters": '', "url": url_for('test_endpoint', _external=True), @@ -347,8 +360,13 @@ def test_login_redirect_from_protected_page(client, live_server, measure_memory_ # Add a watch first set_original_response(datastore_path=datastore_path) - test_url = url_for('test_endpoint', _external=True) - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url) + res = client.post( + url_for("imports.import_page"), + data={"urls": url_for('test_endpoint', _external=True)}, + follow_redirects=True + ) + assert b"1 Imported" in res.data + wait_for_all_checks(client) # Set a password password = "test123" @@ -362,7 +380,7 @@ def test_login_redirect_from_protected_page(client, live_server, measure_memory_ # Try to access a protected page (edit page for first watch) res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), follow_redirects=False ) @@ -379,7 +397,7 @@ def test_login_redirect_from_protected_page(client, live_server, measure_memory_ # The redirect parameter should be preserved in the login form # It should contain the edit page URL assert b'name="redirect"' in res.data - assert f'value="/edit/{uuid}'.encode('utf8') in res.data or f'value="%2Fedit%2F{uuid}'.encode('utf-8') in res.data + assert b'value="/edit/first"' in res.data or b'value="%2Fedit%2Ffirst"' in res.data # Now login with correct password and the redirect parameter res = client.post( diff --git a/changedetectionio/tests/test_share_watch.py b/changedetectionio/tests/test_share_watch.py index 1d99a870..76cdc1cc 100644 --- a/changedetectionio/tests/test_share_watch.py +++ b/changedetectionio/tests/test_share_watch.py @@ -12,6 +12,8 @@ sleep_time_for_fetch_thread = 3 def test_share_watch(client, live_server, measure_memory_usage, datastore_path): set_original_response(datastore_path=datastore_path) + # live_server_setup(live_server) # Setup on conftest per function + test_url = url_for('test_endpoint', _external=True) include_filters = ".nice-filter" @@ -22,20 +24,20 @@ def test_share_watch(client, live_server, measure_memory_usage, datastore_path): # Goto the edit page, add our ignore text # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": include_filters, "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) assert b"Updated watch." in res.data # Check it saved res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), ) assert bytes(include_filters.encode('utf-8')) in res.data # click share the link res = client.get( - url_for("ui.form_share_put_watch", uuid=uuid), + url_for("ui.form_share_put_watch", uuid="first"), follow_redirects=True ) @@ -51,15 +53,20 @@ def test_share_watch(client, live_server, measure_memory_usage, datastore_path): delete_all_watches(client) # Add our URL to the import page - uuid = client.application.config.get('DATASTORE').add_watch(url=share_link_search.group(1)) + res = client.post( + url_for("imports.import_page"), + data={"urls": share_link_search.group(1)}, + follow_redirects=True + ) + assert b"1 Imported" in res.data # Now hit edit, we should see what we expect # that the import fetched the meta-data # Check it saved res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), ) assert bytes(include_filters.encode('utf-8')) in res.data diff --git a/changedetectionio/tests/test_source.py b/changedetectionio/tests/test_source.py index 60a933f6..14975c51 100644 --- a/changedetectionio/tests/test_source.py +++ b/changedetectionio/tests/test_source.py @@ -22,7 +22,7 @@ def test_check_basic_change_detection_functionality_source(client, live_server, # Check HTML conversion detected and workd res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -43,7 +43,7 @@ def test_check_basic_change_detection_functionality_source(client, live_server, assert b'has-unread-changes' in res.data res = client.get( - url_for("ui.ui_diff.diff_history_page", uuid=uuid), + url_for("ui.ui_diff.diff_history_page", uuid="first"), follow_redirects=True ) # With diff-match-patch, HTML tags are properly tokenized and excluded from diff spans @@ -67,7 +67,7 @@ def test_check_ignore_elements(client, live_server, measure_memory_usage, datast # We want and

ONLY, but ignore span with .foobar-detection client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": 'span,p', "url": test_url, "tags": "", "subtractive_selectors": ".foobar-detection", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) @@ -75,7 +75,7 @@ def test_check_ignore_elements(client, live_server, measure_memory_usage, datast time.sleep(sleep_time_for_fetch_thread) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) assert b'foobar-detection' not in res.data diff --git a/changedetectionio/tests/test_trigger.py b/changedetectionio/tests/test_trigger.py index b3935de5..25714d97 100644 --- a/changedetectionio/tests/test_trigger.py +++ b/changedetectionio/tests/test_trigger.py @@ -76,7 +76,7 @@ def test_trigger_functionality(client, live_server, measure_memory_usage, datast # Goto the edit page, add our ignore text # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"trigger_text": trigger_text, "ignore_text": "and more", "url": test_url, @@ -89,14 +89,14 @@ def test_trigger_functionality(client, live_server, measure_memory_usage, datast wait_for_all_checks(client) # Check it saved res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), ) assert bytes(trigger_text.encode('utf-8')) in res.data # so that we set the state to 'has-unread-changes' after all the edits - client.get(url_for("ui.ui_diff.diff_history_page", uuid=uuid)) + client.get(url_for("ui.ui_diff.diff_history_page", uuid="first")) # Trigger a check client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) @@ -129,11 +129,11 @@ def test_trigger_functionality(client, live_server, measure_memory_usage, datast # https://github.com/dgtlmoon/changedetection.io/issues/616 # Apparently the actual snapshot that contains the trigger never shows - res = client.get(url_for("ui.ui_diff.diff_history_page", uuid=uuid)) + res = client.get(url_for("ui.ui_diff.diff_history_page", uuid="first")) assert b'Add to cart' in res.data # Check the preview/highlighter, we should be able to see what we triggered on, but it should be highlighted - res = client.get(url_for("ui.ui_preview.preview_page", uuid=uuid)) + res = client.get(url_for("ui.ui_preview.preview_page", uuid="first")) assert b'ignored_line_numbers = [8]' in res.data # We should be able to see what we triggered on diff --git a/changedetectionio/tests/test_trigger_regex.py b/changedetectionio/tests/test_trigger_regex.py index 8fb2374b..c2cfed4a 100644 --- a/changedetectionio/tests/test_trigger_regex.py +++ b/changedetectionio/tests/test_trigger_regex.py @@ -43,7 +43,7 @@ def test_trigger_regex_functionality(client, live_server, measure_memory_usage, ### test regex res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"trigger_text": '/something \d{3}/', "url": test_url, "fetch_backend": "html_requests", @@ -52,7 +52,7 @@ def test_trigger_regex_functionality(client, live_server, measure_memory_usage, ) wait_for_all_checks(client) # so that we set the state to 'has-unread-changes' after all the edits - client.get(url_for("ui.ui_diff.diff_history_page", uuid=uuid)) + client.get(url_for("ui.ui_diff.diff_history_page", uuid="first")) with open(os.path.join(datastore_path, "endpoint-content.txt"), "w") as f: f.write("some new noise") diff --git a/changedetectionio/tests/test_trigger_regex_with_filter.py b/changedetectionio/tests/test_trigger_regex_with_filter.py index 31bb6a02..e3b85aa5 100644 --- a/changedetectionio/tests/test_trigger_regex_with_filter.py +++ b/changedetectionio/tests/test_trigger_regex_with_filter.py @@ -43,7 +43,7 @@ def test_trigger_regex_functionality_with_filter(client, live_server, measure_me ### test regex with filter res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"trigger_text": "/cool.stuff/", "url": test_url, "include_filters": '#in-here', @@ -55,7 +55,7 @@ def test_trigger_regex_functionality_with_filter(client, live_server, measure_me # Give the thread time to pick it up time.sleep(sleep_time_for_fetch_thread) - client.get(url_for("ui.ui_diff.diff_history_page", uuid=uuid)) + client.get(url_for("ui.ui_diff.diff_history_page", uuid="first")) # Check that we have the expected text.. but it's not in the css filter we want with open(os.path.join(datastore_path, "endpoint-content.txt"), "w") as f: diff --git a/changedetectionio/tests/test_ui.py b/changedetectionio/tests/test_ui.py index e112dd45..e3c9b3fe 100644 --- a/changedetectionio/tests/test_ui.py +++ b/changedetectionio/tests/test_ui.py @@ -40,7 +40,7 @@ def test_recheck_time_field_validation_single_watch(client, live_server, measure client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, 'fetch_backend': "html_requests", @@ -59,7 +59,7 @@ def test_recheck_time_field_validation_single_watch(client, live_server, measure # Now set some time res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, 'fetch_backend': "html_requests", @@ -78,7 +78,7 @@ def test_recheck_time_field_validation_single_watch(client, live_server, measure # Now set to use defaults res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": test_url, 'fetch_backend': "html_requests", @@ -184,7 +184,14 @@ def test_page_title_listing_behaviour(client, live_server, measure_memory_usage, assert b"Settings updated." in res.data - uuid = client.application.config.get('DATASTORE').add_watch(url=url_for('test_endpoint', _external=True)) + # Add our URL to the import page + res = client.post( + url_for("imports.import_page"), + data={"urls": url_for('test_endpoint', _external=True)}, + follow_redirects=True + ) + + assert b"1 Imported" in res.data wait_for_all_checks(client) # We see the URL only, no title/description was manually entered @@ -194,7 +201,7 @@ def test_page_title_listing_behaviour(client, live_server, measure_memory_usage, # Now 'my title' should override res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": url_for('test_endpoint', _external=True), "title": "my title", @@ -222,7 +229,7 @@ def test_page_title_listing_behaviour(client, live_server, measure_memory_usage, # Remove page title description override and it should fall back to title res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "url": url_for('test_endpoint', _external=True), "title": "", @@ -243,9 +250,14 @@ def test_ui_viewed_unread_flag(client, live_server, measure_memory_usage, datast set_original_response(datastore_path=datastore_path, extra_title="custom html") - uuidA = client.application.config.get('DATASTORE').add_watch(url= url_for('test_endpoint', _external=True)) - uuidB = client.application.config.get('DATASTORE').add_watch(url=url_for('test_endpoint', _external=True)) + # Add our URL to the import page + res = client.post( + url_for("imports.import_page"), + data={"urls": url_for('test_endpoint', _external=True)+"\r\n"+url_for('test_endpoint', _external=True)}, + follow_redirects=True + ) + assert b"2 Imported" in res.data wait_for_all_checks(client) set_modified_response(datastore_path=datastore_path) @@ -257,7 +269,7 @@ def test_ui_viewed_unread_flag(client, live_server, measure_memory_usage, datast assert res.data.count(b'data-watch-uuid') == 2 # one should now be viewed, but two in total still - client.get(url_for("ui.ui_diff.diff_history_page", uuid=uuidA)) + client.get(url_for("ui.ui_diff.diff_history_page", uuid="first")) res = client.get(url_for("watchlist.index")) assert b'1' in res.data assert res.data.count(b'data-watch-uuid') == 2 diff --git a/changedetectionio/tests/test_unique_lines.py b/changedetectionio/tests/test_unique_lines.py index 5f75e78d..294578c8 100644 --- a/changedetectionio/tests/test_unique_lines.py +++ b/changedetectionio/tests/test_unique_lines.py @@ -86,7 +86,7 @@ def test_unique_lines_functionality(client, live_server, measure_memory_usage, d # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"check_unique_lines": "y", "url": test_url, "fetch_backend": "html_requests", @@ -130,7 +130,7 @@ def test_sort_lines_functionality(client, live_server, measure_memory_usage, dat # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"sort_text_alphabetically": "n", "url": test_url, "fetch_backend": "html_requests", @@ -152,7 +152,7 @@ def test_sort_lines_functionality(client, live_server, measure_memory_usage, dat assert b'has-unread-changes' in res.data res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -176,7 +176,7 @@ def test_extra_filters(client, live_server, measure_memory_usage, datastore_path # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"remove_duplicate_lines": "y", "trim_text_whitespace": "y", "sort_text_alphabetically": "", # leave this OFF for testing @@ -195,7 +195,7 @@ def test_extra_filters(client, live_server, measure_memory_usage, datastore_path wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid) + url_for("ui.ui_preview.preview_page", uuid="first") ) assert res.data.count(b"see what happens.") == 1 diff --git a/changedetectionio/tests/test_watch_fields_storage.py b/changedetectionio/tests/test_watch_fields_storage.py index 60026a04..9cb32ecf 100644 --- a/changedetectionio/tests/test_watch_fields_storage.py +++ b/changedetectionio/tests/test_watch_fields_storage.py @@ -16,7 +16,7 @@ def test_check_watch_field_storage(client, live_server, measure_memory_usage, da res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={ "notification_urls": "json://127.0.0.1:30000\r\njson://128.0.0.1\r\n", "time_between_check-minutes": 126, "include_filters" : ".fooclass", @@ -33,7 +33,7 @@ def test_check_watch_field_storage(client, live_server, measure_memory_usage, da assert b"Updated watch." in res.data res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), follow_redirects=True ) # checks that we dont get an error when using blank lines in the field value diff --git a/changedetectionio/tests/test_xpath_selector.py b/changedetectionio/tests/test_xpath_selector.py index 5a71f564..2ed44ffb 100644 --- a/changedetectionio/tests/test_xpath_selector.py +++ b/changedetectionio/tests/test_xpath_selector.py @@ -118,7 +118,7 @@ def test_check_xpath_filter_utf8(client, live_server, measure_memory_usage, data 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=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": filter, "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) @@ -167,7 +167,7 @@ def test_check_xpath_text_function_utf8(client, live_server, measure_memory_usag 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=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": filter, "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) @@ -178,7 +178,7 @@ def test_check_xpath_text_function_utf8(client, live_server, measure_memory_usag # The service should echo back the request headers res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -204,7 +204,7 @@ def test_check_markup_xpath_filter_restriction(client, live_server, measure_memo # Goto the edit page, add our ignore text # Add our URL to the import page res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": xpath_filter, "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) @@ -214,7 +214,7 @@ def test_check_markup_xpath_filter_restriction(client, live_server, measure_memo wait_for_all_checks(client) # view it/reset state back to viewed - client.get(url_for("ui.ui_diff.diff_history_page", uuid=uuid), follow_redirects=True) + client.get(url_for("ui.ui_diff.diff_history_page", uuid="first"), follow_redirects=True) # Make a change set_modified_response(datastore_path=datastore_path) @@ -237,7 +237,7 @@ def test_xpath_validation(client, live_server, measure_memory_usage, datastore_p wait_for_all_checks(client) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": "/something horrible", "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) @@ -253,7 +253,7 @@ def test_xpath23_prefix_validation(client, live_server, measure_memory_usage, da wait_for_all_checks(client) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": "xpath:/something horrible", "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) @@ -298,7 +298,7 @@ def test_xpath1_lxml(client, live_server, measure_memory_usage, datastore_path): wait_for_all_checks(client) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": "xpath1://title/text()", "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True @@ -310,7 +310,7 @@ def test_xpath1_lxml(client, live_server, measure_memory_usage, datastore_path): assert b'_ElementStringResult' not in res.data # tested with 5.1.1 when it was removed and 5.1.0 assert b'Exception' not in res.data res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -328,7 +328,7 @@ def test_xpath1_validation(client, live_server, measure_memory_usage, datastore_ wait_for_all_checks(client) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": "xpath1:/something horrible", "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True ) @@ -349,7 +349,7 @@ def test_check_with_prefix_include_filters(client, live_server, measure_memory_u wait_for_all_checks(client) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": "xpath://*[contains(@class, 'sametext')]", "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests", "time_between_check_use_default": "y"}, follow_redirects=True @@ -359,7 +359,7 @@ def test_check_with_prefix_include_filters(client, live_server, measure_memory_u wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -396,7 +396,7 @@ def test_various_rules(client, live_server, measure_memory_usage, datastore_path for r in ['//div', '//a', 'xpath://div', 'xpath://a']: res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": r, "url": test_url, "tags": "", @@ -423,7 +423,7 @@ def test_xpath_20(client, live_server, measure_memory_usage, datastore_path): test_url = url_for('test_endpoint', _external=True) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": "//*[contains(@class, 'sametext')]|//*[contains(@class, 'changetext')]", "url": test_url, "tags": "", @@ -437,7 +437,7 @@ def test_xpath_20(client, live_server, measure_memory_usage, datastore_path): wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -457,7 +457,7 @@ def test_xpath_20_function_count(client, live_server, measure_memory_usage, data wait_for_all_checks(client) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": "xpath:count(//div) * 123456789987654321", "url": test_url, "tags": "", @@ -471,7 +471,7 @@ def test_xpath_20_function_count(client, live_server, measure_memory_usage, data wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -490,7 +490,7 @@ def test_xpath_20_function_count2(client, live_server, measure_memory_usage, dat wait_for_all_checks(client) res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), data={"include_filters": "/html/body/count(div) * 123456789987654321", "url": test_url, "tags": "", @@ -501,10 +501,12 @@ def test_xpath_20_function_count2(client, live_server, measure_memory_usage, dat ) assert b"Updated watch." in res.data + client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) + wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) @@ -551,11 +553,16 @@ def _subtest_xpath_rss(client, datastore_path, content_type='text/html'): # Add our URL to the import page test_url = url_for('test_endpoint', content_type=content_type, _external=True) + res = client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url, "tags": '', 'edit_and_watch_submit_button': 'Edit > Watch'}, + follow_redirects=True + ) - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url, extras={'paused': True}) + assert b"Watch added in Paused state, saving will unpause" in res.data res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid, unpause_on_save=1), + url_for("ui.ui_edit.edit_page", uuid="first", unpause_on_save=1), data={ "url": test_url, "include_filters": "xpath://item", @@ -566,10 +573,11 @@ def _subtest_xpath_rss(client, datastore_path, content_type='text/html'): follow_redirects=True ) + assert b"unpaused" in res.data wait_for_all_checks(client) res = client.get( - url_for("ui.ui_preview.preview_page", uuid=uuid), + url_for("ui.ui_preview.preview_page", uuid="first"), follow_redirects=True ) diff --git a/changedetectionio/tests/util.py b/changedetectionio/tests/util.py index 96510ed6..440beef3 100644 --- a/changedetectionio/tests/util.py +++ b/changedetectionio/tests/util.py @@ -144,8 +144,8 @@ def wait_for_all_checks(client=None): """ from changedetectionio.flask_app import update_q as global_update_q from changedetectionio import worker_pool - time.sleep(0.15) - # Use the shared wait logic from worker_handler + time.sleep(0.25) + # Use the shared wait logic from worker_pool return worker_pool.wait_for_all_checks(global_update_q, timeout=150) def wait_for_watch_history(client, min_history_count=2, timeout=10): diff --git a/changedetectionio/tests/visualselector/test_fetch_data.py b/changedetectionio/tests/visualselector/test_fetch_data.py index c7d46a54..072f5870 100644 --- a/changedetectionio/tests/visualselector/test_fetch_data.py +++ b/changedetectionio/tests/visualselector/test_fetch_data.py @@ -77,7 +77,7 @@ def test_visual_selector_content_ready(client, live_server, measure_memory_usage # Some options should be enabled # @todo - in the future, the visibility should be toggled by JS from the request type setting res = client.get( - url_for("ui.ui_edit.edit_page", uuid=uuid), + url_for("ui.ui_edit.edit_page", uuid="first"), follow_redirects=True ) assert b'notification_screenshot' in res.data @@ -93,11 +93,17 @@ def test_basic_browserstep(client, live_server, measure_memory_usage, datastore_ test_url = url_for('test_interactive_html_endpoint', _external=True) test_url = test_url.replace('localhost.localdomain', 'cdio') test_url = test_url.replace('localhost', 'cdio') - uuid = client.application.config.get('DATASTORE').add_watch(url=test_url, tag='nice one', extras={'paused': True}) - res = client.post( - url_for("ui.ui_edit.edit_page", uuid=uuid, unpause_on_save=1), + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url, "tags": '', 'edit_and_watch_submit_button': 'Edit > Watch'}, + follow_redirects=True + ) + + assert b"Watch added in Paused state, saving will unpause" in res.data + + res = client.post( + url_for("ui.ui_edit.edit_page", uuid="first", unpause_on_save=1), data={ "url": test_url, "tags": "",