diff --git a/changedetectionio/forms.py b/changedetectionio/forms.py index d169e8bc..ce441df9 100644 --- a/changedetectionio/forms.py +++ b/changedetectionio/forms.py @@ -503,7 +503,9 @@ class ValidateJinja2Template(object): jinja2_env = create_jinja_env(loader=BaseLoader) # Add notification tokens for validation - jinja2_env.globals.update(NotificationContextData()) + static_token_placeholders = NotificationContextData() + static_token_placeholders.set_random_for_validation() + jinja2_env.globals.update(static_token_placeholders) if hasattr(field, 'extra_notification_tokens'): jinja2_env.globals.update(field.extra_notification_tokens) diff --git a/changedetectionio/tests/test_notification.py b/changedetectionio/tests/test_notification.py index 1f7f04ca..7f5ea678 100644 --- a/changedetectionio/tests/test_notification.py +++ b/changedetectionio/tests/test_notification.py @@ -302,15 +302,20 @@ def test_notification_urls_jinja2_apprise_integration(client, live_server, measu data={ "application-fetch_backend": "html_requests", "application-minutes_between_check": 180, - "application-notification_body": '{ "url" : "{{ watch_url }}", "secret": 444, "somebug": "网站监测 内容更新了" }', + "application-notification_body": '{ "url" : "{{ watch_url }}", "secret": 444, "somebug": "网站监测 内容更新了", "another": "{{diff|truncate(1500)}}" }', "application-notification_format": default_notification_format, "application-notification_urls": test_notification_url, # https://github.com/caronc/apprise/wiki/Notify_Custom_JSON#get-parameter-manipulation - "application-notification_title": "New ChangeDetection.io Notification - {{ watch_url }} ", + "application-notification_title": "New ChangeDetection.io Notification - {{ watch_url }} {{diff|truncate(200)}} ", }, follow_redirects=True ) assert b'Settings updated' in res.data + assert '网站监测'.encode() in res.data + assert b'{{diff|truncate(1500)}}' in res.data + assert b'{{diff|truncate(200)}}' in res.data + + def test_notification_custom_endpoint_and_jinja2(client, live_server, measure_memory_usage, datastore_path):