diff --git a/changedetectionio/forms.py b/changedetectionio/forms.py index c91722b5..1630907e 100644 --- a/changedetectionio/forms.py +++ b/changedetectionio/forms.py @@ -220,14 +220,16 @@ def validate_time_between_check_has_values(form): Custom validation function for TimeBetweenCheckForm. Returns True if at least one time interval field has a value > 0. """ - return any([ - form.weeks.data and form.weeks.data > 0, - form.days.data and form.days.data > 0, - form.hours.data and form.hours.data > 0, - form.minutes.data and form.minutes.data > 0, - form.seconds.data and form.seconds.data > 0 + res = any([ + form.weeks.data and int(form.weeks.data) > 0, + form.days.data and int(form.days.data) > 0, + form.hours.data and int(form.hours.data) > 0, + form.minutes.data and int(form.minutes.data) > 0, + form.seconds.data and int(form.seconds.data) > 0 ]) + return res + class RequiredTimeInterval(object): """ diff --git a/changedetectionio/templates/_helpers.html b/changedetectionio/templates/_helpers.html index e7ec5112..3ab14758 100644 --- a/changedetectionio/templates/_helpers.html +++ b/changedetectionio/templates/_helpers.html @@ -1,21 +1,29 @@ {% macro render_field(field) %} -
{{ field.label }}
-
{{ field(**kwargs)|safe }} - {% if field.top_errors %} - - {% endif %} - {% if field.errors %} - - {% endif %} -
+
{{ field.label }}
+
{{ field(**kwargs)|safe }} + {% if field.top_errors %} + top + + {% endif %} + {% if field.errors %} + + {% endif %} +
{% endmacro %} {% macro render_checkbox_field(field) %} diff --git a/changedetectionio/tests/test_ui.py b/changedetectionio/tests/test_ui.py index e28bc476..5c9ee51e 100644 --- a/changedetectionio/tests/test_ui.py +++ b/changedetectionio/tests/test_ui.py @@ -2,6 +2,103 @@ from flask import url_for from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks +from ..forms import REQUIRE_ATLEAST_ONE_TIME_PART_WHEN_NOT_GLOBAL_DEFAULT, REQUIRE_ATLEAST_ONE_TIME_PART_MESSAGE_DEFAULT + + +def test_recheck_time_field_validation_global_settings(client, live_server): + """ + Tests that the global settings time field has atleast one value for week/day/hours/minute/seconds etc entered + class globalSettingsRequestForm(Form): + time_between_check = RequiredFormField(TimeBetweenCheckForm) + """ + res = client.post( + url_for("settings.settings_page"), + data={ + "requests-time_between_check-weeks": '', + "requests-time_between_check-days": '', + "requests-time_between_check-hours": '', + "requests-time_between_check-minutes": '', + "requests-time_between_check-seconds": '', + }, + follow_redirects=True + ) + + + assert REQUIRE_ATLEAST_ONE_TIME_PART_MESSAGE_DEFAULT.encode('utf-8') in res.data + + +def test_recheck_time_field_validation_single_watch(client, live_server): + """ + Tests that the global settings time field has atleast one value for week/day/hours/minute/seconds etc entered + class globalSettingsRequestForm(Form): + time_between_check = RequiredFormField(TimeBetweenCheckForm) + """ + test_url = url_for('test_endpoint', _external=True) + + # Add our URL to the import page + res = client.post( + url_for("imports.import_page"), + data={"urls": test_url}, + follow_redirects=True + ) + + assert b"1 Imported" in res.data + + res = client.post( + url_for("ui.ui_edit.edit_page", uuid="first"), + data={ + "url": test_url, + 'fetch_backend': "html_requests", + "time_between_check_use_default": "", # OFF + "time_between_check-weeks": '', + "time_between_check-days": '', + "time_between_check-hours": '', + "time_between_check-minutes": '', + "time_between_check-seconds": '', + }, + follow_redirects=True + ) + + + assert REQUIRE_ATLEAST_ONE_TIME_PART_WHEN_NOT_GLOBAL_DEFAULT.encode('utf-8') in res.data + + # Now set some time + res = client.post( + url_for("ui.ui_edit.edit_page", uuid="first"), + data={ + "url": test_url, + 'fetch_backend': "html_requests", + "time_between_check_use_default": "", # OFF + "time_between_check-weeks": '', + "time_between_check-days": '', + "time_between_check-hours": '', + "time_between_check-minutes": '5', + "time_between_check-seconds": '', + }, + follow_redirects=True + ) + + assert b"Updated watch." in res.data + assert REQUIRE_ATLEAST_ONE_TIME_PART_WHEN_NOT_GLOBAL_DEFAULT.encode('utf-8') not in res.data + + # Now set to use defaults + res = client.post( + url_for("ui.ui_edit.edit_page", uuid="first"), + data={ + "url": test_url, + 'fetch_backend': "html_requests", + "time_between_check_use_default": "y", # ON YES + "time_between_check-weeks": '', + "time_between_check-days": '', + "time_between_check-hours": '', + "time_between_check-minutes": '', + "time_between_check-seconds": '', + }, + follow_redirects=True + ) + + assert b"Updated watch." in res.data + assert REQUIRE_ATLEAST_ONE_TIME_PART_WHEN_NOT_GLOBAL_DEFAULT.encode('utf-8') not in res.data def test_checkbox_open_diff_in_new_tab(client, live_server):