From b598c742f2ffc99e96de004880c0f7c87fb9b580 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Tue, 16 Sep 2025 17:28:36 +0200 Subject: [PATCH] adding test --- changedetectionio/forms.py | 7 ++-- changedetectionio/tests/test_scheduler.py | 42 +++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/changedetectionio/forms.py b/changedetectionio/forms.py index ea1e4d91..cb1b9211 100644 --- a/changedetectionio/forms.py +++ b/changedetectionio/forms.py @@ -57,6 +57,8 @@ valid_method = { default_method = 'GET' allow_simplehost = not strtobool(os.getenv('BLOCK_SIMPLEHOSTS', 'False')) +REQUIRE_ATLEAST_ONE_TIME_PART_MESSAGE_DEFAULT='At least one time interval (weeks, days, hours, minutes, or seconds) must be specified.' +REQUIRE_ATLEAST_ONE_TIME_PART_WHEN_NOT_GLOBAL_DEFAULT='At least one time interval (weeks, days, hours, minutes, or seconds) must be specified when not using global settings.' class StringListField(StringField): widget = widgets.TextArea() @@ -251,8 +253,7 @@ class TimeBetweenCheckForm(Form): def __init__(self, formdata=None, obj=None, prefix="", data=None, meta=None, **kwargs): super().__init__(formdata, obj, prefix, data, meta, **kwargs) self.require_at_least_one = kwargs.get('require_at_least_one', False) - self.require_at_least_one_message = kwargs.get('require_at_least_one_message', - 'At least one time interval (weeks, days, hours, minutes, or seconds) must be specified.') + self.require_at_least_one_message = kwargs.get('require_at_least_one_message', REQUIRE_ATLEAST_ONE_TIME_PART_MESSAGE_DEFAULT) def validate(self, **kwargs): """Custom validation that can optionally require at least one time interval.""" @@ -732,7 +733,7 @@ class processor_text_json_diff_form(commonSettingsForm): time_between_check = EnhancedFormField( TimeBetweenCheckForm, conditional_field='time_between_check_use_default', - conditional_message='At least one time interval (weeks, days, hours, minutes, or seconds) must be specified when not using global settings.', + conditional_message=REQUIRE_ATLEAST_ONE_TIME_PART_WHEN_NOT_GLOBAL_DEFAULT, conditional_test_function=validate_time_between_check_has_values ) diff --git a/changedetectionio/tests/test_scheduler.py b/changedetectionio/tests/test_scheduler.py index 51610d60..26c16687 100644 --- a/changedetectionio/tests/test_scheduler.py +++ b/changedetectionio/tests/test_scheduler.py @@ -5,6 +5,8 @@ from datetime import datetime, timezone from zoneinfo import ZoneInfo from flask import url_for from .util import live_server_setup, wait_for_all_checks, extract_UUID_from_client +from ..forms import REQUIRE_ATLEAST_ONE_TIME_PART_MESSAGE_DEFAULT, REQUIRE_ATLEAST_ONE_TIME_PART_WHEN_NOT_GLOBAL_DEFAULT + # def test_setup(client, live_server): # live_server_setup(live_server) # Setup on conftest per function @@ -177,3 +179,43 @@ def test_check_basic_global_scheduler_functionality(client, live_server, measure # Cleanup everything res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) assert b'Deleted' in res.data + + +def test_validation_time_interval_field(client, live_server, measure_memory_usage): + test_url = url_for('test_endpoint', _external=True) + res = client.post( + url_for("imports.import_page"), + data={"urls": test_url}, + follow_redirects=True + ) + assert b"1 Imported" in res.data + + + res = client.post( + url_for("ui.ui_edit.edit_page", uuid="first"), + data={"trigger_text": 'The golden line', + "url": test_url, + 'fetch_backend': "html_requests", + 'filter_text_removed': 'y', + "time_between_check_use_default": "" + }, + follow_redirects=True + ) + + assert REQUIRE_ATLEAST_ONE_TIME_PART_WHEN_NOT_GLOBAL_DEFAULT.encode('utf-8') in res.data + + # Now set atleast something + + res = client.post( + url_for("ui.ui_edit.edit_page", uuid="first"), + data={"trigger_text": 'The golden line', + "url": test_url, + 'fetch_backend': "html_requests", + "time_between_check-minutes": 1, + "time_between_check_use_default": "" + }, + follow_redirects=True + ) + + assert REQUIRE_ATLEAST_ONE_TIME_PART_WHEN_NOT_GLOBAL_DEFAULT.encode('utf-8') not in res.data + \ No newline at end of file