|
|
|
@ -6,7 +6,7 @@ from .util import live_server_setup
|
|
|
|
|
from changedetectionio import html_tools
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_original(excluding=None):
|
|
|
|
|
def set_original(excluding=None, add_line=None):
|
|
|
|
|
test_return_data = """<html>
|
|
|
|
|
<body>
|
|
|
|
|
<p>Some initial text</p>
|
|
|
|
@ -19,6 +19,11 @@ def set_original(excluding=None):
|
|
|
|
|
</html>
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
if add_line:
|
|
|
|
|
c=test_return_data.splitlines()
|
|
|
|
|
c.insert(5, add_line)
|
|
|
|
|
test_return_data = "\n".join(c)
|
|
|
|
|
|
|
|
|
|
if excluding:
|
|
|
|
|
output = ""
|
|
|
|
|
for i in test_return_data.splitlines():
|
|
|
|
@ -30,10 +35,10 @@ def set_original(excluding=None):
|
|
|
|
|
with open("test-datastore/endpoint-content.txt", "w") as f:
|
|
|
|
|
f.write(test_return_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_removed_line_contains_trigger(client, live_server):
|
|
|
|
|
def test_setup(client, live_server):
|
|
|
|
|
live_server_setup(live_server)
|
|
|
|
|
|
|
|
|
|
def test_check_removed_line_contains_trigger(client, live_server):
|
|
|
|
|
sleep_time_for_fetch_thread = 3
|
|
|
|
|
|
|
|
|
|
# Give the endpoint time to spin up
|
|
|
|
@ -97,3 +102,75 @@ def test_check_removed_line_contains_trigger(client, live_server):
|
|
|
|
|
|
|
|
|
|
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
|
|
|
|
assert b'Deleted' in res.data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_add_line_contains_trigger(client, live_server):
|
|
|
|
|
|
|
|
|
|
sleep_time_for_fetch_thread = 3
|
|
|
|
|
|
|
|
|
|
# Give the endpoint time to spin up
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
test_notification_url = url_for('test_notification_endpoint', _external=True).replace('http://', 'post://') + "?xxx={{ watch_url }}"
|
|
|
|
|
|
|
|
|
|
res = client.post(
|
|
|
|
|
url_for("settings_page"),
|
|
|
|
|
data={"application-notification_title": "New ChangeDetection.io Notification - {{ watch_url }}",
|
|
|
|
|
"application-notification_body": 'triggered text was -{{triggered_text}}-',
|
|
|
|
|
# https://github.com/caronc/apprise/wiki/Notify_Custom_JSON#get-parameter-manipulation
|
|
|
|
|
"application-notification_urls": test_notification_url,
|
|
|
|
|
"application-minutes_between_check": 180,
|
|
|
|
|
"application-fetch_backend": "html_requests"
|
|
|
|
|
},
|
|
|
|
|
follow_redirects=True
|
|
|
|
|
)
|
|
|
|
|
assert b'Settings updated' in res.data
|
|
|
|
|
|
|
|
|
|
set_original()
|
|
|
|
|
# Add our URL to the import page
|
|
|
|
|
test_url = url_for('test_endpoint', _external=True)
|
|
|
|
|
res = client.post(
|
|
|
|
|
url_for("import_page"),
|
|
|
|
|
data={"urls": test_url},
|
|
|
|
|
follow_redirects=True
|
|
|
|
|
)
|
|
|
|
|
assert b"1 Imported" in res.data
|
|
|
|
|
|
|
|
|
|
# Give the thread time to pick it up
|
|
|
|
|
time.sleep(sleep_time_for_fetch_thread)
|
|
|
|
|
|
|
|
|
|
# Goto the edit page, add our ignore text
|
|
|
|
|
# Add our URL to the import page
|
|
|
|
|
res = client.post(
|
|
|
|
|
url_for("edit_page", uuid="first"),
|
|
|
|
|
data={"trigger_text": 'Oh yes please',
|
|
|
|
|
"url": test_url,
|
|
|
|
|
'fetch_backend': "html_requests",
|
|
|
|
|
'filter_text_removed': '',
|
|
|
|
|
'filter_text_added': 'y'},
|
|
|
|
|
follow_redirects=True
|
|
|
|
|
)
|
|
|
|
|
assert b"Updated watch." in res.data
|
|
|
|
|
time.sleep(sleep_time_for_fetch_thread)
|
|
|
|
|
set_original(excluding='Something irrelevant')
|
|
|
|
|
|
|
|
|
|
# A line thats not the trigger should not trigger anything
|
|
|
|
|
res = client.get(url_for("form_watch_checknow"), follow_redirects=True)
|
|
|
|
|
assert b'1 watches queued for rechecking.' in res.data
|
|
|
|
|
time.sleep(sleep_time_for_fetch_thread)
|
|
|
|
|
res = client.get(url_for("index"))
|
|
|
|
|
assert b'unviewed' not in res.data
|
|
|
|
|
|
|
|
|
|
# The trigger line is ADDED, this should trigger
|
|
|
|
|
set_original(add_line='<p>Oh yes please</p>')
|
|
|
|
|
client.get(url_for("form_watch_checknow"), follow_redirects=True)
|
|
|
|
|
time.sleep(sleep_time_for_fetch_thread)
|
|
|
|
|
res = client.get(url_for("index"))
|
|
|
|
|
assert b'unviewed' in res.data
|
|
|
|
|
|
|
|
|
|
with open("test-datastore/notification.txt", 'r') as f:
|
|
|
|
|
response= f.read()
|
|
|
|
|
assert '-Oh yes please-' in response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
|
|
|
|
assert b'Deleted' in res.data
|
|
|
|
|