changedetection.io/changedetectionio/tests/test_backend.py

151 wiersze
5.0 KiB
Python
Czysty Zwykły widok Historia

#!/usr/bin/python3
import time
2021-02-21 12:41:00 +00:00
from flask import url_for
from urllib.request import urlopen
from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks, extract_rss_token_from_UI
2021-02-21 12:41:00 +00:00
2021-02-27 08:05:25 +00:00
sleep_time_for_fetch_thread = 3
# Basic test to check inscriptus is not adding return line chars, basically works etc
def test_inscriptus():
from inscriptis import get_text
html_content = "<html><body>test!<br>ok man</body></html>"
stripped_text_from_html = get_text(html_content)
assert stripped_text_from_html == 'test!\nok man'
2021-02-27 08:05:25 +00:00
2021-02-21 13:05:52 +00:00
def test_check_basic_change_detection_functionality(client, live_server):
2021-02-21 12:41:00 +00:00
set_original_response()
live_server_setup(live_server)
2021-02-21 12:41:00 +00:00
# Add our URL to the import page
res = client.post(
url_for("import_page"),
data={"urls": url_for('test_endpoint', _external=True)},
follow_redirects=True
)
2021-02-21 12:41:00 +00:00
assert b"1 Imported" in res.data
wait_for_all_checks(client)
2021-02-21 20:08:04 +00:00
# Do this a few times.. ensures we dont accidently set the status
for n in range(3):
2022-05-20 14:27:51 +00:00
client.get(url_for("form_watch_checknow"), follow_redirects=True)
2021-02-21 12:41:00 +00:00
# Give the thread time to pick it up
2022-10-28 16:36:07 +00:00
wait_for_all_checks(client)
2021-02-21 12:41:00 +00:00
# It should report nothing found (no new 'unviewed' class)
res = client.get(url_for("index"))
assert b'unviewed' not in res.data
assert b'test-endpoint' in res.data
2021-02-21 12:41:00 +00:00
# Default no password set, this stuff should be always available.
assert b"SETTINGS" in res.data
assert b"BACKUP" in res.data
assert b"IMPORT" in res.data
2021-02-21 13:26:19 +00:00
#####################
# Check HTML conversion detected and workd
res = client.get(
url_for("preview_page", uuid="first"),
follow_redirects=True
)
# Check this class does not appear (that we didnt see the actual source)
assert b'foobar-detection' not in res.data
2021-02-21 12:41:00 +00:00
# Make a change
set_modified_response()
2021-02-21 12:41:00 +00:00
res = urlopen(url_for('test_endpoint', _external=True))
assert b'which has this one new line' in res.read()
2021-02-21 12:41:00 +00:00
# Force recheck
2022-05-20 14:27:51 +00:00
res = client.get(url_for("form_watch_checknow"), follow_redirects=True)
assert b'1 watches queued for rechecking.' in res.data
2022-10-28 16:36:07 +00:00
wait_for_all_checks(client)
2021-02-21 12:41:00 +00:00
# Now something should be ready, indicated by having a 'unviewed' class
res = client.get(url_for("index"))
assert b'unviewed' in res.data
# #75, and it should be in the RSS feed
rss_token = extract_rss_token_from_UI(client)
res = client.get(url_for("rss", token=rss_token, _external=True))
expected_url = url_for('test_endpoint', _external=True)
assert b'<rss' in res.data
# re #16 should have the diff in here too
assert b'(into) which has this one new line' in res.data
assert b'CDATA' in res.data
assert expected_url.encode('utf-8') in res.data
# Following the 'diff' link, it should no longer display as 'unviewed' even after we recheck it a few times
2021-02-27 08:05:25 +00:00
res = client.get(url_for("diff_history_page", uuid="first"))
assert b'selected=""' in res.data, "Confirm diff history page loaded"
# Check the [preview] pulls the right one
res = client.get(
url_for("preview_page", uuid="first"),
follow_redirects=True
)
assert b'which has this one new line' in res.data
assert b'Which is across multiple lines' not in res.data
2022-10-28 16:36:07 +00:00
wait_for_all_checks(client)
2021-02-21 19:54:15 +00:00
# Do this a few times.. ensures we dont accidently set the status
2021-02-27 08:05:25 +00:00
for n in range(2):
2022-05-20 14:27:51 +00:00
client.get(url_for("form_watch_checknow"), follow_redirects=True)
# Give the thread time to pick it up
2022-10-28 16:36:07 +00:00
wait_for_all_checks(client)
# It should report nothing found (no new 'unviewed' class)
res = client.get(url_for("index"))
assert b'unviewed' not in res.data
assert b'Mark all viewed' not in res.data
assert b'head title' not in res.data # Should not be present because this is off by default
assert b'test-endpoint' in res.data
2021-02-21 19:54:15 +00:00
set_original_response()
# Enable auto pickup of <title> in settings
res = client.post(
url_for("settings_page"),
data={"application-extract_title_as_title": "1", "requests-time_between_check-minutes": 180,
'application-fetch_backend': "html_requests"},
follow_redirects=True
)
2022-05-20 14:27:51 +00:00
client.get(url_for("form_watch_checknow"), follow_redirects=True)
2022-10-28 16:36:07 +00:00
wait_for_all_checks(client)
2021-02-21 19:54:15 +00:00
res = client.get(url_for("index"))
2021-02-27 08:05:25 +00:00
assert b'unviewed' in res.data
assert b'Mark all viewed' in res.data
# It should have picked up the <title>
assert b'head title' in res.data
2021-02-27 08:05:25 +00:00
# Be sure the last_viewed is going to be greater than the last snapshot
time.sleep(1)
# hit the mark all viewed link
res = client.get(url_for("mark_all_viewed"), follow_redirects=True)
assert b'Mark all viewed' not in res.data
assert b'unviewed' not in res.data
#
2021-02-27 21:01:42 +00:00
# Cleanup everything
2022-05-20 14:27:51 +00:00
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
2021-02-27 08:37:40 +00:00
assert b'Deleted' in res.data