mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2025-12-14 20:16:13 +00:00
more fixes
This commit is contained in:
@@ -206,6 +206,13 @@ class ValidateJinja2Template(object):
|
|||||||
from jinja2 import Environment, BaseLoader, TemplateSyntaxError
|
from jinja2 import Environment, BaseLoader, TemplateSyntaxError
|
||||||
from jinja2.meta import find_undeclared_variables
|
from jinja2.meta import find_undeclared_variables
|
||||||
|
|
||||||
|
regex = re.compile('{{(.*?)}}')
|
||||||
|
valid_tokens = list(notification.valid_tokens.keys())
|
||||||
|
for p in re.findall(regex, field.data):
|
||||||
|
if not p.strip() in valid_tokens:
|
||||||
|
message = field.gettext('Token \'%s\' is not a valid token or is unknown')
|
||||||
|
raise ValidationError(message % (p))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
jinja2_env = Environment(loader=BaseLoader)
|
jinja2_env = Environment(loader=BaseLoader)
|
||||||
jinja2_env.globals.update(notification.valid_tokens)
|
jinja2_env.globals.update(notification.valid_tokens)
|
||||||
@@ -220,12 +227,6 @@ class ValidateJinja2Template(object):
|
|||||||
f"The following tokens used in the notification are not valid: {undefined}"
|
f"The following tokens used in the notification are not valid: {undefined}"
|
||||||
)
|
)
|
||||||
|
|
||||||
regex = re.compile('{{(.*?)}}')
|
|
||||||
valid_tokens = list(notification.valid_tokens.keys())
|
|
||||||
for p in re.findall(regex, field.data):
|
|
||||||
if not p.strip() in valid_tokens:
|
|
||||||
message = field.gettext('Token \'%s\' is not a valid token.')
|
|
||||||
raise ValidationError(message % (p))
|
|
||||||
|
|
||||||
class validateURL(object):
|
class validateURL(object):
|
||||||
|
|
||||||
|
|||||||
@@ -185,10 +185,10 @@ def test_check_notification(client, live_server):
|
|||||||
|
|
||||||
res = client.post(
|
res = client.post(
|
||||||
url_for("settings_page"),
|
url_for("settings_page"),
|
||||||
data={"notification_title": "New ChangeDetection.io Notification - {{ watch_url }}",
|
data={"application-notification_title": "New ChangeDetection.io Notification - {{ watch_url }}",
|
||||||
"notification_urls": "json://foobar.com", #Re #143 should not see that it sent without [test checkbox]
|
"application-notification_urls": "json://foobar.com", #Re #143 should not see that it sent without [test checkbox]
|
||||||
"minutes_between_check": 180,
|
"application-minutes_between_check": 180,
|
||||||
"fetch_backend": "html_requests",
|
"application-fetch_backend": "html_requests",
|
||||||
},
|
},
|
||||||
follow_redirects=True
|
follow_redirects=True
|
||||||
)
|
)
|
||||||
@@ -254,10 +254,14 @@ def test_check_notification(client, live_server):
|
|||||||
follow_redirects=True
|
follow_redirects=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_notification_validation(client, live_server):
|
def test_notification_validation(client, live_server):
|
||||||
#live_server_setup(live_server)
|
#live_server_setup(live_server)
|
||||||
time.sleep(3)
|
time.sleep(1)
|
||||||
|
# cleanup for the next
|
||||||
|
client.get(
|
||||||
|
url_for("form_delete", uuid="all"),
|
||||||
|
follow_redirects=True
|
||||||
|
)
|
||||||
# re #242 - when you edited an existing new entry, it would not correctly show the notification settings
|
# re #242 - when you edited an existing new entry, it would not correctly show the notification settings
|
||||||
# Add our URL to the import page
|
# Add our URL to the import page
|
||||||
test_url = url_for('test_endpoint', _external=True)
|
test_url = url_for('test_endpoint', _external=True)
|
||||||
@@ -297,28 +301,26 @@ def test_notification_validation(client, live_server):
|
|||||||
},
|
},
|
||||||
follow_redirects=True
|
follow_redirects=True
|
||||||
)
|
)
|
||||||
assert bytes("The following tokens used in the notification are not valid".encode('utf-8')) in res.data
|
assert bytes("Token 'rubbish' is not a valid token or is unknown".encode('utf-8')) in res.data
|
||||||
|
|
||||||
|
|
||||||
# And trying to define an invalid Jinja2 template should also throw an error
|
# And trying to define an invalid Jinja2 template should also throw an error
|
||||||
res = client.post(
|
res = client.post(
|
||||||
url_for("settings_page"),
|
url_for("settings_page"),
|
||||||
data={"notification_title": "New ChangeDetection.io Notification - {{ watch_url }}",
|
data={"application-notification_title": "New ChangeDetection.io Notification - {{ watch_url }}",
|
||||||
"notification_body": "Rubbish: {{ rubbish }\n",
|
"application-notification_body": "Rubbish: {{ rubbish }\n",
|
||||||
"notification_urls": "json://foobar.com",
|
"application-notification_urls": "json://foobar.com",
|
||||||
"minutes_between_check": 180,
|
"application-minutes_between_check": 180,
|
||||||
"fetch_backend": "html_requests"
|
"application-fetch_backend": "html_requests"
|
||||||
},
|
},
|
||||||
follow_redirects=True
|
follow_redirects=True
|
||||||
)
|
)
|
||||||
assert bytes("This is not a valid Jinja2 template".encode('utf-8')) in res.data
|
assert bytes("This is not a valid Jinja2 template".encode('utf-8')) in res.data
|
||||||
|
|
||||||
|
|
||||||
assert bytes("is not a valid token".encode('utf-8')) in res.data
|
|
||||||
|
|
||||||
# cleanup for the next
|
# cleanup for the next
|
||||||
client.get(
|
client.get(
|
||||||
url_for("form_delete", uuid="all"),
|
url_for("form_delete", uuid="all"),
|
||||||
follow_redirects=True
|
follow_redirects=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user