mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2025-11-08 02:26:31 +00:00
Compare commits
19 Commits
upgrade-pl
...
selectable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6fb6d01e2a | ||
|
|
bfe69de549 | ||
|
|
c437e5d740 | ||
|
|
7cc2afbb8f | ||
|
|
2877a639dc | ||
|
|
2f16aee0dd | ||
|
|
cdf611f173 | ||
|
|
77ec1da0ff | ||
|
|
7477ce11d6 | ||
|
|
858b66efb4 | ||
|
|
0bcbcb80f1 | ||
|
|
b6bdc2738b | ||
|
|
ebc7a7e568 | ||
|
|
d7bc2bd3f6 | ||
|
|
2bd32b261a | ||
|
|
572a169a47 | ||
|
|
68d1e2736c | ||
|
|
97e591fa24 | ||
|
|
5d9a5d9fa8 |
1
.github/workflows/test-only.yml
vendored
1
.github/workflows/test-only.yml
vendored
@@ -51,7 +51,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
# Unit tests
|
# Unit tests
|
||||||
docker run test-changedetectionio bash -c 'python3 -m unittest changedetectionio.tests.unit.test_notification_diff'
|
docker run test-changedetectionio bash -c 'python3 -m unittest changedetectionio.tests.unit.test_notification_diff'
|
||||||
docker run test-changedetectionio bash -c 'python3 -m unittest changedetectionio.tests.unit.test_watch_model'
|
|
||||||
|
|
||||||
# All tests
|
# All tests
|
||||||
docker run --network changedet-network test-changedetectionio bash -c 'cd changedetectionio && ./run_basic_tests.sh'
|
docker run --network changedet-network test-changedetectionio bash -c 'cd changedetectionio && ./run_basic_tests.sh'
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ RUN pip install --target=/dependencies -r /requirements.txt
|
|||||||
# Playwright is an alternative to Selenium
|
# Playwright is an alternative to Selenium
|
||||||
# Excluded this package from requirements.txt to prevent arm/v6 and arm/v7 builds from failing
|
# Excluded this package from requirements.txt to prevent arm/v6 and arm/v7 builds from failing
|
||||||
# https://github.com/dgtlmoon/changedetection.io/pull/1067 also musl/alpine (not supported)
|
# https://github.com/dgtlmoon/changedetection.io/pull/1067 also musl/alpine (not supported)
|
||||||
RUN pip install --target=/dependencies playwright~=1.40 \
|
RUN pip install --target=/dependencies playwright~=1.39 \
|
||||||
|| echo "WARN: Failed to install Playwright. The application can still run, but the Playwright option will be disabled."
|
|| echo "WARN: Failed to install Playwright. The application can still run, but the Playwright option will be disabled."
|
||||||
|
|
||||||
# Final image stage
|
# Final image stage
|
||||||
|
|||||||
@@ -268,7 +268,3 @@ I offer commercial support, this software is depended on by network security, ae
|
|||||||
[license-shield]: https://img.shields.io/github/license/dgtlmoon/changedetection.io.svg?style=for-the-badge
|
[license-shield]: https://img.shields.io/github/license/dgtlmoon/changedetection.io.svg?style=for-the-badge
|
||||||
[release-link]: https://github.com/dgtlmoon/changedetection.io/releases
|
[release-link]: https://github.com/dgtlmoon/changedetection.io/releases
|
||||||
[docker-link]: https://hub.docker.com/r/dgtlmoon/changedetection.io
|
[docker-link]: https://hub.docker.com/r/dgtlmoon/changedetection.io
|
||||||
|
|
||||||
## Third-party licenses
|
|
||||||
|
|
||||||
changedetectionio.html_tools.elementpath_tostring: Copyright (c), 2018-2021, SISSA (Scuola Internazionale Superiore di Studi Avanzati), Licensed under [MIT license](https://github.com/sissaschool/elementpath/blob/master/LICENSE)
|
|
||||||
|
|||||||
@@ -821,16 +821,6 @@ def changedetection_app(config=None, datastore_o=None):
|
|||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
@app.route("/settings/reset-api-key", methods=['GET'])
|
|
||||||
@login_optionally_required
|
|
||||||
def settings_reset_api_key():
|
|
||||||
import secrets
|
|
||||||
secret = secrets.token_hex(16)
|
|
||||||
datastore.data['settings']['application']['api_access_token'] = secret
|
|
||||||
datastore.needs_write_urgent = True
|
|
||||||
flash("API Key was regenerated.")
|
|
||||||
return redirect(url_for('settings_page')+'#api')
|
|
||||||
|
|
||||||
@app.route("/import", methods=['GET', "POST"])
|
@app.route("/import", methods=['GET', "POST"])
|
||||||
@login_optionally_required
|
@login_optionally_required
|
||||||
def import_page():
|
def import_page():
|
||||||
@@ -961,7 +951,7 @@ def changedetection_app(config=None, datastore_o=None):
|
|||||||
# Read as binary and force decode as UTF-8
|
# Read as binary and force decode as UTF-8
|
||||||
# Windows may fail decode in python if we just use 'r' mode (chardet decode exception)
|
# Windows may fail decode in python if we just use 'r' mode (chardet decode exception)
|
||||||
from_version = request.args.get('from_version')
|
from_version = request.args.get('from_version')
|
||||||
from_version_index = -2 # second newest
|
from_version_index = -2 # second newest
|
||||||
if from_version and from_version in dates:
|
if from_version and from_version in dates:
|
||||||
from_version_index = dates.index(from_version)
|
from_version_index = dates.index(from_version)
|
||||||
else:
|
else:
|
||||||
@@ -970,7 +960,7 @@ def changedetection_app(config=None, datastore_o=None):
|
|||||||
try:
|
try:
|
||||||
from_version_file_contents = watch.get_history_snapshot(dates[from_version_index])
|
from_version_file_contents = watch.get_history_snapshot(dates[from_version_index])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
from_version_file_contents = f"Unable to read to-version at index {dates[from_version_index]}.\n"
|
from_version_file_contents = "Unable to read to-version at index{}.\n".format(dates[from_version_index])
|
||||||
|
|
||||||
to_version = request.args.get('to_version')
|
to_version = request.args.get('to_version')
|
||||||
to_version_index = -1
|
to_version_index = -1
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ def construct_blueprint(datastore: ChangeDetectionStore):
|
|||||||
@browser_steps_blueprint.route("/browsersteps_update", methods=['POST'])
|
@browser_steps_blueprint.route("/browsersteps_update", methods=['POST'])
|
||||||
def browsersteps_ui_update():
|
def browsersteps_ui_update():
|
||||||
import base64
|
import base64
|
||||||
import playwright._impl._errors
|
import playwright._impl._api_types
|
||||||
global browsersteps_sessions
|
global browsersteps_sessions
|
||||||
from changedetectionio.blueprint.browser_steps import browser_steps
|
from changedetectionio.blueprint.browser_steps import browser_steps
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class steppable_browser_interface():
|
|||||||
self.page.click(selector=selector, timeout=30 * 1000, delay=randint(200, 500))
|
self.page.click(selector=selector, timeout=30 * 1000, delay=randint(200, 500))
|
||||||
|
|
||||||
def action_click_element_if_exists(self, selector, value):
|
def action_click_element_if_exists(self, selector, value):
|
||||||
import playwright._impl._errors as _api_types
|
import playwright._impl._api_types as _api_types
|
||||||
print("Clicking element if exists")
|
print("Clicking element if exists")
|
||||||
if not len(selector.strip()):
|
if not len(selector.strip()):
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -69,12 +69,11 @@ xpath://body/div/span[contains(@class, 'example-class')]",
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>XPath - Limit text to this XPath rule, simply start with a forward-slash. To specify XPath to be used explicitly or the XPath rule starts with an XPath function: Prefix with <code>xpath:</code>
|
<li>XPath - Limit text to this XPath rule, simply start with a forward-slash,
|
||||||
<ul>
|
<ul>
|
||||||
<li>Example: <code>//*[contains(@class, 'sametext')]</code> or <code>xpath:count(//*[contains(@class, 'sametext')])</code>, <a
|
<li>Example: <code>//*[contains(@class, 'sametext')]</code> or <code>xpath://*[contains(@class, 'sametext')]</code>, <a
|
||||||
href="http://xpather.com/" target="new">test your XPath here</a></li>
|
href="http://xpather.com/" target="new">test your XPath here</a></li>
|
||||||
<li>Example: Get all titles from an RSS feed <code>//title/text()</code></li>
|
<li>Example: Get all titles from an RSS feed <code>//title/text()</code></li>
|
||||||
<li>To use XPath1.0: Prefix with <code>xpath1:</code></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ class Fetcher():
|
|||||||
|
|
||||||
def iterate_browser_steps(self):
|
def iterate_browser_steps(self):
|
||||||
from changedetectionio.blueprint.browser_steps.browser_steps import steppable_browser_interface
|
from changedetectionio.blueprint.browser_steps.browser_steps import steppable_browser_interface
|
||||||
from playwright._impl._errors import TimeoutError
|
from playwright._impl._api_types import TimeoutError
|
||||||
from jinja2 import Environment
|
from jinja2 import Environment
|
||||||
jinja2_env = Environment(extensions=['jinja2_time.TimeExtension'])
|
jinja2_env = Environment(extensions=['jinja2_time.TimeExtension'])
|
||||||
|
|
||||||
@@ -436,7 +436,7 @@ class base_html_playwright(Fetcher):
|
|||||||
is_binary)
|
is_binary)
|
||||||
|
|
||||||
from playwright.sync_api import sync_playwright
|
from playwright.sync_api import sync_playwright
|
||||||
import playwright._impl._errors
|
import playwright._impl._api_types
|
||||||
|
|
||||||
self.delete_browser_steps_screenshots()
|
self.delete_browser_steps_screenshots()
|
||||||
response = None
|
response = None
|
||||||
@@ -489,7 +489,7 @@ class base_html_playwright(Fetcher):
|
|||||||
try:
|
try:
|
||||||
if self.webdriver_js_execute_code is not None and len(self.webdriver_js_execute_code):
|
if self.webdriver_js_execute_code is not None and len(self.webdriver_js_execute_code):
|
||||||
browsersteps_interface.action_execute_js(value=self.webdriver_js_execute_code, selector=None)
|
browsersteps_interface.action_execute_js(value=self.webdriver_js_execute_code, selector=None)
|
||||||
except playwright._impl._errors.TimeoutError as e:
|
except playwright._impl._api_types.TimeoutError as e:
|
||||||
context.close()
|
context.close()
|
||||||
browser.close()
|
browser.close()
|
||||||
# This can be ok, we will try to grab what we could retrieve
|
# This can be ok, we will try to grab what we could retrieve
|
||||||
|
|||||||
@@ -328,30 +328,11 @@ class ValidateCSSJSONXPATHInput(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Does it look like XPath?
|
# Does it look like XPath?
|
||||||
if line.strip()[0] == '/' or line.strip().startswith('xpath:'):
|
if line.strip()[0] == '/':
|
||||||
if not self.allow_xpath:
|
|
||||||
raise ValidationError("XPath not permitted in this field!")
|
|
||||||
from lxml import etree, html
|
|
||||||
import elementpath
|
|
||||||
# xpath 2.0-3.1
|
|
||||||
from elementpath.xpath3 import XPath3Parser
|
|
||||||
tree = html.fromstring("<html></html>")
|
|
||||||
line = line.replace('xpath:', '')
|
|
||||||
|
|
||||||
try:
|
|
||||||
elementpath.select(tree, line.strip(), parser=XPath3Parser)
|
|
||||||
except elementpath.ElementPathError as e:
|
|
||||||
message = field.gettext('\'%s\' is not a valid XPath expression. (%s)')
|
|
||||||
raise ValidationError(message % (line, str(e)))
|
|
||||||
except:
|
|
||||||
raise ValidationError("A system-error occurred when validating your XPath expression")
|
|
||||||
|
|
||||||
if line.strip().startswith('xpath1:'):
|
|
||||||
if not self.allow_xpath:
|
if not self.allow_xpath:
|
||||||
raise ValidationError("XPath not permitted in this field!")
|
raise ValidationError("XPath not permitted in this field!")
|
||||||
from lxml import etree, html
|
from lxml import etree, html
|
||||||
tree = html.fromstring("<html></html>")
|
tree = html.fromstring("<html></html>")
|
||||||
line = re.sub(r'^xpath1:', '', line)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tree.xpath(line.strip())
|
tree.xpath(line.strip())
|
||||||
|
|||||||
@@ -69,89 +69,10 @@ def element_removal(selectors: List[str], html_content):
|
|||||||
selector = ",".join(selectors)
|
selector = ",".join(selectors)
|
||||||
return subtractive_css_selector(selector, html_content)
|
return subtractive_css_selector(selector, html_content)
|
||||||
|
|
||||||
def elementpath_tostring(obj):
|
|
||||||
"""
|
|
||||||
change elementpath.select results to string type
|
|
||||||
# The MIT License (MIT), Copyright (c), 2018-2021, SISSA (Scuola Internazionale Superiore di Studi Avanzati)
|
|
||||||
# https://github.com/sissaschool/elementpath/blob/dfcc2fd3d6011b16e02bf30459a7924f547b47d0/elementpath/xpath_tokens.py#L1038
|
|
||||||
"""
|
|
||||||
|
|
||||||
import elementpath
|
|
||||||
from decimal import Decimal
|
|
||||||
import math
|
|
||||||
|
|
||||||
if obj is None:
|
|
||||||
return ''
|
|
||||||
# https://elementpath.readthedocs.io/en/latest/xpath_api.html#elementpath.select
|
|
||||||
elif isinstance(obj, elementpath.XPathNode):
|
|
||||||
return obj.string_value
|
|
||||||
elif isinstance(obj, bool):
|
|
||||||
return 'true' if obj else 'false'
|
|
||||||
elif isinstance(obj, Decimal):
|
|
||||||
value = format(obj, 'f')
|
|
||||||
if '.' in value:
|
|
||||||
return value.rstrip('0').rstrip('.')
|
|
||||||
return value
|
|
||||||
|
|
||||||
elif isinstance(obj, float):
|
|
||||||
if math.isnan(obj):
|
|
||||||
return 'NaN'
|
|
||||||
elif math.isinf(obj):
|
|
||||||
return str(obj).upper()
|
|
||||||
|
|
||||||
value = str(obj)
|
|
||||||
if '.' in value:
|
|
||||||
value = value.rstrip('0').rstrip('.')
|
|
||||||
if '+' in value:
|
|
||||||
value = value.replace('+', '')
|
|
||||||
if 'e' in value:
|
|
||||||
return value.upper()
|
|
||||||
return value
|
|
||||||
|
|
||||||
return str(obj)
|
|
||||||
|
|
||||||
# Return str Utf-8 of matched rules
|
# Return str Utf-8 of matched rules
|
||||||
def xpath_filter(xpath_filter, html_content, append_pretty_line_formatting=False, is_rss=False):
|
def xpath_filter(xpath_filter, html_content, append_pretty_line_formatting=False, is_rss=False):
|
||||||
from lxml import etree, html
|
from lxml import etree, html
|
||||||
import elementpath
|
|
||||||
# xpath 2.0-3.1
|
|
||||||
from elementpath.xpath3 import XPath3Parser
|
|
||||||
|
|
||||||
parser = etree.HTMLParser()
|
|
||||||
if is_rss:
|
|
||||||
# So that we can keep CDATA for cdata_in_document_to_text() to process
|
|
||||||
parser = etree.XMLParser(strip_cdata=False)
|
|
||||||
|
|
||||||
tree = html.fromstring(bytes(html_content, encoding='utf-8'), parser=parser)
|
|
||||||
html_block = ""
|
|
||||||
|
|
||||||
r = elementpath.select(tree, xpath_filter.strip(), namespaces={'re': 'http://exslt.org/regular-expressions'}, parser=XPath3Parser)
|
|
||||||
#@note: //title/text() wont work where <title>CDATA..
|
|
||||||
|
|
||||||
if type(r) != list:
|
|
||||||
r = [r]
|
|
||||||
|
|
||||||
for element in r:
|
|
||||||
# When there's more than 1 match, then add the suffix to separate each line
|
|
||||||
# And where the matched result doesn't include something that will cause Inscriptis to add a newline
|
|
||||||
# (This way each 'match' reliably has a new-line in the diff)
|
|
||||||
# Divs are converted to 4 whitespaces by inscriptis
|
|
||||||
if append_pretty_line_formatting and len(html_block) and (not hasattr( element, 'tag' ) or not element.tag in (['br', 'hr', 'div', 'p'])):
|
|
||||||
html_block += TEXT_FILTER_LIST_LINE_SUFFIX
|
|
||||||
|
|
||||||
if type(element) == str:
|
|
||||||
html_block += element
|
|
||||||
elif issubclass(type(element), etree._Element) or issubclass(type(element), etree._ElementTree):
|
|
||||||
html_block += etree.tostring(element, pretty_print=True).decode('utf-8')
|
|
||||||
else:
|
|
||||||
html_block += elementpath_tostring(element)
|
|
||||||
|
|
||||||
return html_block
|
|
||||||
|
|
||||||
# Return str Utf-8 of matched rules
|
|
||||||
# 'xpath1:'
|
|
||||||
def xpath1_filter(xpath_filter, html_content, append_pretty_line_formatting=False, is_rss=False):
|
|
||||||
from lxml import etree, html
|
|
||||||
|
|
||||||
parser = None
|
parser = None
|
||||||
if is_rss:
|
if is_rss:
|
||||||
|
|||||||
@@ -262,38 +262,6 @@ class model(dict):
|
|||||||
bump = self.history
|
bump = self.history
|
||||||
return self.__newest_history_key
|
return self.__newest_history_key
|
||||||
|
|
||||||
# Given an arbitrary timestamp, find the closest next key
|
|
||||||
# For example, last_viewed = 1000 so it should return the next 1001 timestamp
|
|
||||||
#
|
|
||||||
# used for the [diff] button so it can preset a smarter from_version
|
|
||||||
@property
|
|
||||||
def get_next_snapshot_key_to_last_viewed(self):
|
|
||||||
|
|
||||||
"""Unfortunately for now timestamp is stored as string key"""
|
|
||||||
keys = list(self.history.keys())
|
|
||||||
if not keys:
|
|
||||||
return None
|
|
||||||
|
|
||||||
last_viewed = int(self.get('last_viewed'))
|
|
||||||
prev_k = keys[0]
|
|
||||||
sorted_keys = sorted(keys, key=lambda x: int(x))
|
|
||||||
sorted_keys.reverse()
|
|
||||||
|
|
||||||
# When the 'last viewed' timestamp is greater than the newest snapshot, return second last
|
|
||||||
if last_viewed > int(sorted_keys[0]):
|
|
||||||
return sorted_keys[1]
|
|
||||||
|
|
||||||
for k in sorted_keys:
|
|
||||||
if int(k) < last_viewed:
|
|
||||||
if prev_k == sorted_keys[0]:
|
|
||||||
# Return the second last one so we dont recommend the same version compares itself
|
|
||||||
return sorted_keys[1]
|
|
||||||
|
|
||||||
return prev_k
|
|
||||||
prev_k = k
|
|
||||||
|
|
||||||
return keys[0]
|
|
||||||
|
|
||||||
def get_history_snapshot(self, timestamp):
|
def get_history_snapshot(self, timestamp):
|
||||||
import brotli
|
import brotli
|
||||||
filepath = self.history[timestamp]
|
filepath = self.history[timestamp]
|
||||||
|
|||||||
@@ -173,11 +173,6 @@ class perform_site_check(difference_detection_processor):
|
|||||||
html_content=self.fetcher.content,
|
html_content=self.fetcher.content,
|
||||||
append_pretty_line_formatting=not watch.is_source_type_url,
|
append_pretty_line_formatting=not watch.is_source_type_url,
|
||||||
is_rss=is_rss)
|
is_rss=is_rss)
|
||||||
elif filter_rule.startswith('xpath1:'):
|
|
||||||
html_content += html_tools.xpath1_filter(xpath_filter=filter_rule.replace('xpath1:', ''),
|
|
||||||
html_content=self.fetcher.content,
|
|
||||||
append_pretty_line_formatting=not watch.is_source_type_url,
|
|
||||||
is_rss=is_rss)
|
|
||||||
else:
|
else:
|
||||||
# CSS Filter, extract the HTML that matches and feed that into the existing inscriptis::get_text
|
# CSS Filter, extract the HTML that matches and feed that into the existing inscriptis::get_text
|
||||||
html_content += html_tools.include_filters(include_filters=filter_rule,
|
html_content += html_tools.include_filters(include_filters=filter_rule,
|
||||||
|
|||||||
@@ -170,12 +170,9 @@ if (include_filters.length) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// is it xpath?
|
// is it xpath?
|
||||||
if (f.startsWith('/') || f.startsWith('xpath')) {
|
if (f.startsWith('/') || f.startsWith('xpath:')) {
|
||||||
var qry_f = f.replace(/xpath(:|\d:)/, '')
|
q = document.evaluate(f.replace('xpath:', ''), document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
||||||
console.log("[xpath] Scanning for included filter " + qry_f)
|
|
||||||
q = document.evaluate(qry_f, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
|
||||||
} else {
|
} else {
|
||||||
console.log("[css] Scanning for included filter " + f)
|
|
||||||
q = document.querySelector(f);
|
q = document.querySelector(f);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -185,18 +182,8 @@ if (include_filters.length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (q) {
|
if (q) {
|
||||||
// Try to resolve //something/text() back to its /something so we can atleast get the bounding box
|
|
||||||
try {
|
|
||||||
if (typeof q.nodeName == 'string' && q.nodeName === '#text') {
|
|
||||||
q = q.parentElement
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e)
|
|
||||||
console.log("xpath_element_scraper: #text resolver")
|
|
||||||
}
|
|
||||||
|
|
||||||
// #1231 - IN the case XPath attribute filter is applied, we will have to traverse up and find the element.
|
// #1231 - IN the case XPath attribute filter is applied, we will have to traverse up and find the element.
|
||||||
if (typeof q.getBoundingClientRect == 'function') {
|
if (q.hasOwnProperty('getBoundingClientRect')) {
|
||||||
bbox = q.getBoundingClientRect();
|
bbox = q.getBoundingClientRect();
|
||||||
console.log("xpath_element_scraper: Got filter element, scroll from top was " + scroll_y)
|
console.log("xpath_element_scraper: Got filter element, scroll from top was " + scroll_y)
|
||||||
} else {
|
} else {
|
||||||
@@ -205,8 +192,7 @@ if (include_filters.length) {
|
|||||||
bbox = q.ownerElement.getBoundingClientRect();
|
bbox = q.ownerElement.getBoundingClientRect();
|
||||||
console.log("xpath_element_scraper: Got filter by ownerElement element, scroll from top was " + scroll_y)
|
console.log("xpath_element_scraper: Got filter by ownerElement element, scroll from top was " + scroll_y)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log("xpath_element_scraper: error looking up ownerElement")
|
||||||
console.log("xpath_element_scraper: error looking up q.ownerElement")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ $(document).ready(function () {
|
|||||||
// @todo In the future paint all that match
|
// @todo In the future paint all that match
|
||||||
for (const c of current_default_xpath) {
|
for (const c of current_default_xpath) {
|
||||||
for (var i = selector_data['size_pos'].length; i !== 0; i--) {
|
for (var i = selector_data['size_pos'].length; i !== 0; i--) {
|
||||||
if (selector_data['size_pos'][i - 1].xpath.trim() === c.trim()) {
|
if (selector_data['size_pos'][i - 1].xpath === c) {
|
||||||
console.log("highlighting " + c);
|
console.log("highlighting " + c);
|
||||||
current_selected_i = i - 1;
|
current_selected_i = i - 1;
|
||||||
highlight_current_selected_i();
|
highlight_current_selected_i();
|
||||||
|
|||||||
@@ -848,13 +848,3 @@ class ChangeDetectionStore:
|
|||||||
self.data['watching'][uuid]['date_created'] = i
|
self.data['watching'][uuid]['date_created'] = i
|
||||||
i+=1
|
i+=1
|
||||||
return
|
return
|
||||||
|
|
||||||
# #1774 - protect xpath1 against migration
|
|
||||||
def update_14(self):
|
|
||||||
for awatch in self.__data["watching"]:
|
|
||||||
if self.__data["watching"][awatch]['include_filters']:
|
|
||||||
for num, selector in enumerate(self.__data["watching"][awatch]['include_filters']):
|
|
||||||
if selector.startswith('/'):
|
|
||||||
self.__data["watching"][awatch]['include_filters'][num] = 'xpath1:' + selector
|
|
||||||
if selector.startswith('xpath:'):
|
|
||||||
self.__data["watching"][awatch]['include_filters'][num] = selector.replace('xpath:', 'xpath1:', 1)
|
|
||||||
|
|||||||
@@ -290,12 +290,11 @@ xpath://body/div/span[contains(@class, 'example-class')]",
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>XPath - Limit text to this XPath rule, simply start with a forward-slash. To specify XPath to be used explicitly or the XPath rule starts with an XPath function: Prefix with <code>xpath:</code>
|
<li>XPath - Limit text to this XPath rule, simply start with a forward-slash,
|
||||||
<ul>
|
<ul>
|
||||||
<li>Example: <code>//*[contains(@class, 'sametext')]</code> or <code>xpath:count(//*[contains(@class, 'sametext')])</code>, <a
|
<li>Example: <code>//*[contains(@class, 'sametext')]</code> or <code>xpath://*[contains(@class, 'sametext')]</code>, <a
|
||||||
href="http://xpather.com/" target="new">test your XPath here</a></li>
|
href="http://xpather.com/" target="new">test your XPath here</a></li>
|
||||||
<li>Example: Get all titles from an RSS feed <code>//title/text()</code></li>
|
<li>Example: Get all titles from an RSS feed <code>//title/text()</code></li>
|
||||||
<li>To use XPath1.0: Prefix with <code>xpath1:</code></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -178,9 +178,6 @@ nav
|
|||||||
<span style="display:none;" id="api-key-copy" >copy</span>
|
<span style="display:none;" id="api-key-copy" >copy</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="pure-control-group">
|
|
||||||
<a href="{{url_for('settings_reset_api_key')}}" class="pure-button button-small button-cancel">Regenerate API key</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane-inner" id="proxies">
|
<div class="tab-pane-inner" id="proxies">
|
||||||
<div id="recommended-proxy">
|
<div id="recommended-proxy">
|
||||||
|
|||||||
@@ -82,15 +82,12 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for watch in (watches|sort(attribute=sort_attribute, reverse=sort_order == 'asc'))|pagination_slice(skip=pagination.skip) %}
|
{% for watch in (watches|sort(attribute=sort_attribute, reverse=sort_order == 'asc'))|pagination_slice(skip=pagination.skip) %}
|
||||||
|
|
||||||
{% set is_unviewed = watch.newest_history_key| int > watch.last_viewed and watch.history_n>=2 %}
|
|
||||||
|
|
||||||
<tr id="{{ watch.uuid }}"
|
<tr id="{{ watch.uuid }}"
|
||||||
class="{{ loop.cycle('pure-table-odd', 'pure-table-even') }} processor-{{ watch['processor'] }}
|
class="{{ loop.cycle('pure-table-odd', 'pure-table-even') }} processor-{{ watch['processor'] }}
|
||||||
{% if watch.last_error is defined and watch.last_error != False %}error{% endif %}
|
{% if watch.last_error is defined and watch.last_error != False %}error{% endif %}
|
||||||
{% if watch.last_notification_error is defined and watch.last_notification_error != False %}error{% endif %}
|
{% if watch.last_notification_error is defined and watch.last_notification_error != False %}error{% endif %}
|
||||||
{% if watch.paused is defined and watch.paused != False %}paused{% endif %}
|
{% if watch.paused is defined and watch.paused != False %}paused{% endif %}
|
||||||
{% if is_unviewed %}unviewed{% endif %}
|
{% if watch.newest_history_key| int > watch.last_viewed and watch.history_n>=2 %}unviewed{% endif %}
|
||||||
{% if watch.uuid in queued_uuids %}queued{% endif %}">
|
{% if watch.uuid in queued_uuids %}queued{% endif %}">
|
||||||
<td class="inline checkbox-uuid" ><input name="uuids" type="checkbox" value="{{ watch.uuid}} " > <span>{{ loop.index+pagination.skip }}</span></td>
|
<td class="inline checkbox-uuid" ><input name="uuids" type="checkbox" value="{{ watch.uuid}} " > <span>{{ loop.index+pagination.skip }}</span></td>
|
||||||
<td class="inline watch-controls">
|
<td class="inline watch-controls">
|
||||||
@@ -170,13 +167,7 @@
|
|||||||
class="recheck pure-button pure-button-primary">{% if watch.uuid in queued_uuids %}Queued{% else %}Recheck{% endif %}</a>
|
class="recheck pure-button pure-button-primary">{% if watch.uuid in queued_uuids %}Queued{% else %}Recheck{% endif %}</a>
|
||||||
<a href="{{ url_for('edit_page', uuid=watch.uuid)}}" class="pure-button pure-button-primary">Edit</a>
|
<a href="{{ url_for('edit_page', uuid=watch.uuid)}}" class="pure-button pure-button-primary">Edit</a>
|
||||||
{% if watch.history_n >= 2 %}
|
{% if watch.history_n >= 2 %}
|
||||||
|
<a href="{{ url_for('diff_history_page', uuid=watch.uuid) }}" target="{{watch.uuid}}" class="pure-button pure-button-primary diff-link">Diff</a>
|
||||||
{% if is_unviewed %}
|
|
||||||
<a href="{{ url_for('diff_history_page', uuid=watch.uuid, from_version=watch.get_next_snapshot_key_to_last_viewed) }}" target="{{watch.uuid}}" class="pure-button pure-button-primary diff-link">Diff</a>
|
|
||||||
{% else %}
|
|
||||||
<a href="{{ url_for('diff_history_page', uuid=watch.uuid)}}" target="{{watch.uuid}}" class="pure-button pure-button-primary diff-link">Diff</a>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if watch.history_n == 1 or (watch.history_n ==0 and watch.error_text_ctime )%}
|
{% if watch.history_n == 1 or (watch.history_n ==0 and watch.error_text_ctime )%}
|
||||||
<a href="{{ url_for('preview_page', uuid=watch.uuid)}}" target="{{watch.uuid}}" class="pure-button pure-button-primary">Preview</a>
|
<a href="{{ url_for('preview_page', uuid=watch.uuid)}}" target="{{watch.uuid}}" class="pure-button pure-button-primary">Preview</a>
|
||||||
|
|||||||
Binary file not shown.
@@ -227,6 +227,9 @@ def test_regex_error_handling(client, live_server):
|
|||||||
follow_redirects=True
|
follow_redirects=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
with open('/tmp/fuck.html', 'wb') as f:
|
||||||
|
f.write(res.data)
|
||||||
|
|
||||||
assert b'is not a valid regular expression.' in res.data
|
assert b'is not a valid regular expression.' in res.data
|
||||||
|
|
||||||
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks
|
from .util import set_original_response, set_modified_response, live_server_setup
|
||||||
|
|
||||||
|
sleep_time_for_fetch_thread = 3
|
||||||
|
|
||||||
# `subtractive_selectors` should still work in `source:` type requests
|
# `subtractive_selectors` should still work in `source:` type requests
|
||||||
def test_fetch_pdf(client, live_server):
|
def test_fetch_pdf(client, live_server):
|
||||||
@@ -21,9 +22,7 @@ def test_fetch_pdf(client, live_server):
|
|||||||
|
|
||||||
assert b"1 Imported" in res.data
|
assert b"1 Imported" in res.data
|
||||||
|
|
||||||
|
time.sleep(sleep_time_for_fetch_thread)
|
||||||
wait_for_all_checks(client)
|
|
||||||
|
|
||||||
res = client.get(
|
res = client.get(
|
||||||
url_for("preview_page", uuid="first"),
|
url_for("preview_page", uuid="first"),
|
||||||
follow_redirects=True
|
follow_redirects=True
|
||||||
@@ -34,42 +33,8 @@ def test_fetch_pdf(client, live_server):
|
|||||||
|
|
||||||
# So we know if the file changes in other ways
|
# So we know if the file changes in other ways
|
||||||
import hashlib
|
import hashlib
|
||||||
original_md5 = hashlib.md5(open("test-datastore/endpoint-test.pdf", 'rb').read()).hexdigest().upper()
|
md5 = hashlib.md5(open("test-datastore/endpoint-test.pdf", 'rb').read()).hexdigest().upper()
|
||||||
# We should have one
|
# We should have one
|
||||||
assert len(original_md5) >0
|
assert len(md5) >0
|
||||||
# And it's going to be in the document
|
# And it's going to be in the document
|
||||||
assert b'Document checksum - '+bytes(str(original_md5).encode('utf-8')) in res.data
|
assert b'Document checksum - '+bytes(str(md5).encode('utf-8')) in res.data
|
||||||
|
|
||||||
|
|
||||||
shutil.copy("tests/test2.pdf", "test-datastore/endpoint-test.pdf")
|
|
||||||
changed_md5 = hashlib.md5(open("test-datastore/endpoint-test.pdf", 'rb').read()).hexdigest().upper()
|
|
||||||
res = client.get(url_for("form_watch_checknow"), follow_redirects=True)
|
|
||||||
assert b'1 watches queued for rechecking.' in res.data
|
|
||||||
|
|
||||||
wait_for_all_checks(client)
|
|
||||||
|
|
||||||
# Now something should be ready, indicated by having a 'unviewed' class
|
|
||||||
res = client.get(url_for("index"))
|
|
||||||
assert b'unviewed' in res.data
|
|
||||||
|
|
||||||
# The original checksum should be not be here anymore (cdio adds it to the bottom of the text)
|
|
||||||
|
|
||||||
res = client.get(
|
|
||||||
url_for("preview_page", uuid="first"),
|
|
||||||
follow_redirects=True
|
|
||||||
)
|
|
||||||
|
|
||||||
assert original_md5.encode('utf-8') not in res.data
|
|
||||||
assert changed_md5.encode('utf-8') in res.data
|
|
||||||
|
|
||||||
|
|
||||||
res = client.get(
|
|
||||||
url_for("diff_history_page", uuid="first"),
|
|
||||||
follow_redirects=True
|
|
||||||
)
|
|
||||||
|
|
||||||
assert original_md5.encode('utf-8') in res.data
|
|
||||||
assert changed_md5.encode('utf-8') in res.data
|
|
||||||
|
|
||||||
assert b'here is a change' in res.data
|
|
||||||
|
|
||||||
@@ -6,11 +6,9 @@ from .util import live_server_setup, wait_for_all_checks
|
|||||||
|
|
||||||
from ..html_tools import *
|
from ..html_tools import *
|
||||||
|
|
||||||
|
|
||||||
def test_setup(live_server):
|
def test_setup(live_server):
|
||||||
live_server_setup(live_server)
|
live_server_setup(live_server)
|
||||||
|
|
||||||
|
|
||||||
def set_original_response():
|
def set_original_response():
|
||||||
test_return_data = """<html>
|
test_return_data = """<html>
|
||||||
<body>
|
<body>
|
||||||
@@ -28,7 +26,6 @@ def set_original_response():
|
|||||||
f.write(test_return_data)
|
f.write(test_return_data)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def set_modified_response():
|
def set_modified_response():
|
||||||
test_return_data = """<html>
|
test_return_data = """<html>
|
||||||
<body>
|
<body>
|
||||||
@@ -47,12 +44,11 @@ def set_modified_response():
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# Handle utf-8 charset replies https://github.com/dgtlmoon/changedetection.io/pull/613
|
# Handle utf-8 charset replies https://github.com/dgtlmoon/changedetection.io/pull/613
|
||||||
def test_check_xpath_filter_utf8(client, live_server):
|
def test_check_xpath_filter_utf8(client, live_server):
|
||||||
filter = '//item/*[self::description]'
|
filter='//item/*[self::description]'
|
||||||
|
|
||||||
d = '''<?xml version="1.0" encoding="UTF-8"?>
|
d='''<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<rss xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
|
<rss xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
|
||||||
<channel>
|
<channel>
|
||||||
<title>rpilocator.com</title>
|
<title>rpilocator.com</title>
|
||||||
@@ -106,9 +102,9 @@ def test_check_xpath_filter_utf8(client, live_server):
|
|||||||
|
|
||||||
# Handle utf-8 charset replies https://github.com/dgtlmoon/changedetection.io/pull/613
|
# Handle utf-8 charset replies https://github.com/dgtlmoon/changedetection.io/pull/613
|
||||||
def test_check_xpath_text_function_utf8(client, live_server):
|
def test_check_xpath_text_function_utf8(client, live_server):
|
||||||
filter = '//item/title/text()'
|
filter='//item/title/text()'
|
||||||
|
|
||||||
d = '''<?xml version="1.0" encoding="UTF-8"?>
|
d='''<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<rss xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
|
<rss xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
|
||||||
<channel>
|
<channel>
|
||||||
<title>rpilocator.com</title>
|
<title>rpilocator.com</title>
|
||||||
@@ -167,12 +163,15 @@ def test_check_xpath_text_function_utf8(client, live_server):
|
|||||||
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
||||||
assert b'Deleted' in res.data
|
assert b'Deleted' in res.data
|
||||||
|
|
||||||
|
|
||||||
def test_check_markup_xpath_filter_restriction(client, live_server):
|
def test_check_markup_xpath_filter_restriction(client, live_server):
|
||||||
|
|
||||||
xpath_filter = "//*[contains(@class, 'sametext')]"
|
xpath_filter = "//*[contains(@class, 'sametext')]"
|
||||||
|
|
||||||
set_original_response()
|
set_original_response()
|
||||||
|
|
||||||
|
# Give the endpoint time to spin up
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
# 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)
|
||||||
res = client.post(
|
res = client.post(
|
||||||
@@ -215,6 +214,7 @@ def test_check_markup_xpath_filter_restriction(client, live_server):
|
|||||||
|
|
||||||
|
|
||||||
def test_xpath_validation(client, live_server):
|
def test_xpath_validation(client, live_server):
|
||||||
|
|
||||||
# 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)
|
||||||
res = client.post(
|
res = client.post(
|
||||||
@@ -235,48 +235,6 @@ def test_xpath_validation(client, live_server):
|
|||||||
assert b'Deleted' in res.data
|
assert b'Deleted' in res.data
|
||||||
|
|
||||||
|
|
||||||
def test_xpath23_prefix_validation(client, live_server):
|
|
||||||
# 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
|
|
||||||
wait_for_all_checks(client)
|
|
||||||
|
|
||||||
res = client.post(
|
|
||||||
url_for("edit_page", uuid="first"),
|
|
||||||
data={"include_filters": "xpath:/something horrible", "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests"},
|
|
||||||
follow_redirects=True
|
|
||||||
)
|
|
||||||
assert b"is not a valid XPath expression" in res.data
|
|
||||||
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
|
||||||
assert b'Deleted' in res.data
|
|
||||||
|
|
||||||
|
|
||||||
def test_xpath1_validation(client, live_server):
|
|
||||||
# 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
|
|
||||||
wait_for_all_checks(client)
|
|
||||||
|
|
||||||
res = client.post(
|
|
||||||
url_for("edit_page", uuid="first"),
|
|
||||||
data={"include_filters": "xpath1:/something horrible", "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests"},
|
|
||||||
follow_redirects=True
|
|
||||||
)
|
|
||||||
assert b"is not a valid XPath expression" in res.data
|
|
||||||
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
|
||||||
assert b'Deleted' in res.data
|
|
||||||
|
|
||||||
|
|
||||||
# actually only really used by the distll.io importer, but could be handy too
|
# actually only really used by the distll.io importer, but could be handy too
|
||||||
def test_check_with_prefix_include_filters(client, live_server):
|
def test_check_with_prefix_include_filters(client, live_server):
|
||||||
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
||||||
@@ -296,8 +254,7 @@ def test_check_with_prefix_include_filters(client, live_server):
|
|||||||
|
|
||||||
res = client.post(
|
res = client.post(
|
||||||
url_for("edit_page", uuid="first"),
|
url_for("edit_page", uuid="first"),
|
||||||
data={"include_filters": "xpath://*[contains(@class, 'sametext')]", "url": test_url, "tags": "", "headers": "",
|
data={"include_filters": "xpath://*[contains(@class, 'sametext')]", "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests"},
|
||||||
'fetch_backend': "html_requests"},
|
|
||||||
follow_redirects=True
|
follow_redirects=True
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -309,15 +266,13 @@ def test_check_with_prefix_include_filters(client, live_server):
|
|||||||
follow_redirects=True
|
follow_redirects=True
|
||||||
)
|
)
|
||||||
|
|
||||||
assert b"Some text thats the same" in res.data # in selector
|
assert b"Some text thats the same" in res.data #in selector
|
||||||
assert b"Some text that will change" not in res.data # not in selector
|
assert b"Some text that will change" not in res.data #not in selector
|
||||||
|
|
||||||
client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
||||||
|
|
||||||
|
|
||||||
def test_various_rules(client, live_server):
|
def test_various_rules(client, live_server):
|
||||||
# Just check these don't error
|
# Just check these don't error
|
||||||
# live_server_setup(live_server)
|
#live_server_setup(live_server)
|
||||||
with open("test-datastore/endpoint-content.txt", "w") as f:
|
with open("test-datastore/endpoint-content.txt", "w") as f:
|
||||||
f.write("""<html>
|
f.write("""<html>
|
||||||
<body>
|
<body>
|
||||||
@@ -334,7 +289,6 @@ def test_various_rules(client, live_server):
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
""")
|
""")
|
||||||
|
|
||||||
test_url = url_for('test_endpoint', _external=True)
|
test_url = url_for('test_endpoint', _external=True)
|
||||||
res = client.post(
|
res = client.post(
|
||||||
url_for("import_page"),
|
url_for("import_page"),
|
||||||
@@ -344,6 +298,7 @@ def test_various_rules(client, live_server):
|
|||||||
assert b"1 Imported" in res.data
|
assert b"1 Imported" in res.data
|
||||||
wait_for_all_checks(client)
|
wait_for_all_checks(client)
|
||||||
|
|
||||||
|
|
||||||
for r in ['//div', '//a', 'xpath://div', 'xpath://a']:
|
for r in ['//div', '//a', 'xpath://div', 'xpath://a']:
|
||||||
res = client.post(
|
res = client.post(
|
||||||
url_for("edit_page", uuid="first"),
|
url_for("edit_page", uuid="first"),
|
||||||
@@ -358,153 +313,3 @@ def test_various_rules(client, live_server):
|
|||||||
assert b"Updated watch." in res.data
|
assert b"Updated watch." in res.data
|
||||||
res = client.get(url_for("index"))
|
res = client.get(url_for("index"))
|
||||||
assert b'fetch-error' not in res.data, f"Should not see errors after '{r} filter"
|
assert b'fetch-error' not in res.data, f"Should not see errors after '{r} filter"
|
||||||
|
|
||||||
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
|
||||||
assert b'Deleted' in res.data
|
|
||||||
|
|
||||||
|
|
||||||
def test_xpath_20(client, live_server):
|
|
||||||
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
|
|
||||||
wait_for_all_checks(client)
|
|
||||||
|
|
||||||
set_original_response()
|
|
||||||
|
|
||||||
test_url = url_for('test_endpoint', _external=True)
|
|
||||||
res = client.post(
|
|
||||||
url_for("edit_page", uuid="first"),
|
|
||||||
data={"include_filters": "//*[contains(@class, 'sametext')]|//*[contains(@class, 'changetext')]",
|
|
||||||
"url": test_url,
|
|
||||||
"tags": "",
|
|
||||||
"headers": "",
|
|
||||||
'fetch_backend': "html_requests"},
|
|
||||||
follow_redirects=True
|
|
||||||
)
|
|
||||||
|
|
||||||
assert b"Updated watch." in res.data
|
|
||||||
wait_for_all_checks(client)
|
|
||||||
|
|
||||||
res = client.get(
|
|
||||||
url_for("preview_page", uuid="first"),
|
|
||||||
follow_redirects=True
|
|
||||||
)
|
|
||||||
|
|
||||||
assert b"Some text thats the same" in res.data # in selector
|
|
||||||
assert b"Some text that will change" in res.data # in selector
|
|
||||||
|
|
||||||
client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
|
||||||
|
|
||||||
|
|
||||||
def test_xpath_20_function_count(client, live_server):
|
|
||||||
set_original_response()
|
|
||||||
|
|
||||||
# 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
|
|
||||||
wait_for_all_checks(client)
|
|
||||||
|
|
||||||
res = client.post(
|
|
||||||
url_for("edit_page", uuid="first"),
|
|
||||||
data={"include_filters": "xpath:count(//div) * 123456789987654321",
|
|
||||||
"url": test_url,
|
|
||||||
"tags": "",
|
|
||||||
"headers": "",
|
|
||||||
'fetch_backend': "html_requests"},
|
|
||||||
follow_redirects=True
|
|
||||||
)
|
|
||||||
|
|
||||||
assert b"Updated watch." in res.data
|
|
||||||
wait_for_all_checks(client)
|
|
||||||
|
|
||||||
res = client.get(
|
|
||||||
url_for("preview_page", uuid="first"),
|
|
||||||
follow_redirects=True
|
|
||||||
)
|
|
||||||
|
|
||||||
assert b"246913579975308642" in res.data # in selector
|
|
||||||
|
|
||||||
client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
|
||||||
|
|
||||||
|
|
||||||
def test_xpath_20_function_count2(client, live_server):
|
|
||||||
set_original_response()
|
|
||||||
|
|
||||||
# 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
|
|
||||||
wait_for_all_checks(client)
|
|
||||||
|
|
||||||
res = client.post(
|
|
||||||
url_for("edit_page", uuid="first"),
|
|
||||||
data={"include_filters": "/html/body/count(div) * 123456789987654321",
|
|
||||||
"url": test_url,
|
|
||||||
"tags": "",
|
|
||||||
"headers": "",
|
|
||||||
'fetch_backend': "html_requests"},
|
|
||||||
follow_redirects=True
|
|
||||||
)
|
|
||||||
|
|
||||||
assert b"Updated watch." in res.data
|
|
||||||
wait_for_all_checks(client)
|
|
||||||
|
|
||||||
res = client.get(
|
|
||||||
url_for("preview_page", uuid="first"),
|
|
||||||
follow_redirects=True
|
|
||||||
)
|
|
||||||
|
|
||||||
assert b"246913579975308642" in res.data # in selector
|
|
||||||
|
|
||||||
client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
|
||||||
|
|
||||||
|
|
||||||
def test_xpath_20_function_string_join_matches(client, live_server):
|
|
||||||
set_original_response()
|
|
||||||
|
|
||||||
# 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
|
|
||||||
wait_for_all_checks(client)
|
|
||||||
|
|
||||||
res = client.post(
|
|
||||||
url_for("edit_page", uuid="first"),
|
|
||||||
data={
|
|
||||||
"include_filters": "xpath:string-join(//*[contains(@class, 'sametext')]|//*[matches(@class, 'changetext')], 'specialconjunction')",
|
|
||||||
"url": test_url,
|
|
||||||
"tags": "",
|
|
||||||
"headers": "",
|
|
||||||
'fetch_backend': "html_requests"},
|
|
||||||
follow_redirects=True
|
|
||||||
)
|
|
||||||
|
|
||||||
assert b"Updated watch." in res.data
|
|
||||||
wait_for_all_checks(client)
|
|
||||||
|
|
||||||
res = client.get(
|
|
||||||
url_for("preview_page", uuid="first"),
|
|
||||||
follow_redirects=True
|
|
||||||
)
|
|
||||||
|
|
||||||
assert b"Some text thats the samespecialconjunctionSome text that will change" in res.data # in selector
|
|
||||||
|
|
||||||
client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,203 +0,0 @@
|
|||||||
import sys
|
|
||||||
import os
|
|
||||||
import pytest
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
||||||
import html_tools
|
|
||||||
|
|
||||||
# test generation guide.
|
|
||||||
# 1. Do not include encoding in the xml declaration if the test object is a str type.
|
|
||||||
# 2. Always paraphrase test.
|
|
||||||
|
|
||||||
hotels = """
|
|
||||||
<hotel>
|
|
||||||
<branch location="California">
|
|
||||||
<staff>
|
|
||||||
<given_name>Christopher</given_name>
|
|
||||||
<surname>Anderson</surname>
|
|
||||||
<age>25</age>
|
|
||||||
</staff>
|
|
||||||
<staff>
|
|
||||||
<given_name>Christopher</given_name>
|
|
||||||
<surname>Carter</surname>
|
|
||||||
<age>30</age>
|
|
||||||
</staff>
|
|
||||||
</branch>
|
|
||||||
<branch location="Las Vegas">
|
|
||||||
<staff>
|
|
||||||
<given_name>Lisa</given_name>
|
|
||||||
<surname>Walker</surname>
|
|
||||||
<age>60</age>
|
|
||||||
</staff>
|
|
||||||
<staff>
|
|
||||||
<given_name>Jessica</given_name>
|
|
||||||
<surname>Walker</surname>
|
|
||||||
<age>32</age>
|
|
||||||
</staff>
|
|
||||||
<staff>
|
|
||||||
<given_name>Jennifer</given_name>
|
|
||||||
<surname>Roberts</surname>
|
|
||||||
<age>50</age>
|
|
||||||
</staff>
|
|
||||||
</branch>
|
|
||||||
</hotel>"""
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("html_content", [hotels])
|
|
||||||
@pytest.mark.parametrize("xpath, answer", [('(//staff/given_name, //staff/age)', '25'),
|
|
||||||
("xs:date('2023-10-10')", '2023-10-10'),
|
|
||||||
("if (/hotel/branch[@location = 'California']/staff[1]/age = 25) then 'is 25' else 'is not 25'", 'is 25'),
|
|
||||||
("if (//hotel/branch[@location = 'California']/staff[1]/age = 25) then 'is 25' else 'is not 25'", 'is 25'),
|
|
||||||
("if (count(/hotel/branch/staff) = 5) then true() else false()", 'true'),
|
|
||||||
("if (count(//hotel/branch/staff) = 5) then true() else false()", 'true'),
|
|
||||||
("for $i in /hotel/branch/staff return if ($i/age >= 40) then upper-case($i/surname) else lower-case($i/surname)", 'anderson'),
|
|
||||||
("given_name = 'Christopher' and age = 40", 'false'),
|
|
||||||
("//given_name = 'Christopher' and //age = 40", 'false'),
|
|
||||||
#("(staff/given_name, staff/age)", 'Lisa'),
|
|
||||||
("(//staff/given_name, //staff/age)", 'Lisa'),
|
|
||||||
#("hotel/branch[@location = 'California']/staff/age union hotel/branch[@location = 'Las Vegas']/staff/age", ''),
|
|
||||||
("(//hotel/branch[@location = 'California']/staff/age union //hotel/branch[@location = 'Las Vegas']/staff/age)", '60'),
|
|
||||||
("(200 to 210)", "205"),
|
|
||||||
("(//hotel/branch[@location = 'California']/staff/age union //hotel/branch[@location = 'Las Vegas']/staff/age)", "50"),
|
|
||||||
("(1, 9, 9, 5)", "5"),
|
|
||||||
("(3, (), (14, 15), 92, 653)", "653"),
|
|
||||||
("for $i in /hotel/branch/staff return $i/given_name", "Christopher"),
|
|
||||||
("for $i in //hotel/branch/staff return $i/given_name", "Christopher"),
|
|
||||||
("distinct-values(for $i in /hotel/branch/staff return $i/given_name)", "Jessica"),
|
|
||||||
("distinct-values(for $i in //hotel/branch/staff return $i/given_name)", "Jessica"),
|
|
||||||
("for $i in (7 to 15) return $i*10", "130"),
|
|
||||||
("some $i in /hotel/branch/staff satisfies $i/age < 20", "false"),
|
|
||||||
("some $i in //hotel/branch/staff satisfies $i/age < 20", "false"),
|
|
||||||
("every $i in /hotel/branch/staff satisfies $i/age > 20", "true"),
|
|
||||||
("every $i in //hotel/branch/staff satisfies $i/age > 20 ", "true"),
|
|
||||||
("let $x := branch[@location = 'California'], $y := branch[@location = 'Las Vegas'] return (avg($x/staff/age), avg($y/staff/age))", "27.5"),
|
|
||||||
("let $x := //branch[@location = 'California'], $y := //branch[@location = 'Las Vegas'] return (avg($x/staff/age), avg($y/staff/age))", "27.5"),
|
|
||||||
("let $nu := 1, $de := 1000 return 'probability = ' || $nu div $de * 100 || '%'", "0.1%"),
|
|
||||||
("let $nu := 2, $probability := function ($argument) { 'probability = ' || $nu div $argument * 100 || '%'}, $de := 5 return $probability($de)", "40%"),
|
|
||||||
("'XPATH2.0-3.1 dissemination' instance of xs:string ", "true"),
|
|
||||||
("'new stackoverflow question incoming' instance of xs:integer ", "false"),
|
|
||||||
("'50000' cast as xs:integer", "50000"),
|
|
||||||
("//branch[@location = 'California']/staff[1]/surname eq 'Anderson'", "true"),
|
|
||||||
("fn:false()", "false")])
|
|
||||||
def test_hotels(html_content, xpath, answer):
|
|
||||||
html_content = html_tools.xpath_filter(xpath, html_content, append_pretty_line_formatting=True)
|
|
||||||
assert type(html_content) == str
|
|
||||||
assert answer in html_content
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
branches_to_visit = """<?xml version="1.0" ?>
|
|
||||||
<branches_to_visit>
|
|
||||||
<manager name="Godot" room_no="501">
|
|
||||||
<branch>Area 51</branch>
|
|
||||||
<branch>A place with no name</branch>
|
|
||||||
<branch>Stalsk12</branch>
|
|
||||||
</manager>
|
|
||||||
<manager name="Freya" room_no="305">
|
|
||||||
<branch>Stalsk12</branch>
|
|
||||||
<branch>Barcelona</branch>
|
|
||||||
<branch>Paris</branch>
|
|
||||||
</manager>
|
|
||||||
</branches_to_visit>"""
|
|
||||||
@pytest.mark.parametrize("html_content", [branches_to_visit])
|
|
||||||
@pytest.mark.parametrize("xpath, answer", [
|
|
||||||
("manager[@name = 'Godot']/branch union manager[@name = 'Freya']/branch", "Area 51"),
|
|
||||||
("//manager[@name = 'Godot']/branch union //manager[@name = 'Freya']/branch", "Stalsk12"),
|
|
||||||
("manager[@name = 'Godot']/branch | manager[@name = 'Freya']/branch", "Stalsk12"),
|
|
||||||
("//manager[@name = 'Godot']/branch | //manager[@name = 'Freya']/branch", "Stalsk12"),
|
|
||||||
("manager/branch intersect manager[@name = 'Godot']/branch", "A place with no name"),
|
|
||||||
("//manager/branch intersect //manager[@name = 'Godot']/branch", "A place with no name"),
|
|
||||||
("manager[@name = 'Godot']/branch intersect manager[@name = 'Freya']/branch", ""),
|
|
||||||
("manager/branch except manager[@name = 'Godot']/branch", "Barcelona"),
|
|
||||||
("manager[@name = 'Godot']/branch[1] eq 'Area 51'", "true"),
|
|
||||||
("//manager[@name = 'Godot']/branch[1] eq 'Area 51'", "true"),
|
|
||||||
("manager[@name = 'Godot']/branch[1] eq 'Seoul'", "false"),
|
|
||||||
("//manager[@name = 'Godot']/branch[1] eq 'Seoul'", "false"),
|
|
||||||
("manager[@name = 'Godot']/branch[2] eq manager[@name = 'Freya']/branch[2]", "false"),
|
|
||||||
("//manager[@name = 'Godot']/branch[2] eq //manager[@name = 'Freya']/branch[2]", "false"),
|
|
||||||
("manager[1]/@room_no lt manager[2]/@room_no", "false"),
|
|
||||||
("//manager[1]/@room_no lt //manager[2]/@room_no", "false"),
|
|
||||||
("manager[1]/@room_no gt manager[2]/@room_no", "true"),
|
|
||||||
("//manager[1]/@room_no gt //manager[2]/@room_no", "true"),
|
|
||||||
("manager[@name = 'Godot']/branch[1] = 'Area 51'", "true"),
|
|
||||||
("//manager[@name = 'Godot']/branch[1] = 'Area 51'", "true"),
|
|
||||||
("manager[@name = 'Godot']/branch[1] = 'Seoul'", "false"),
|
|
||||||
("//manager[@name = 'Godot']/branch[1] = 'Seoul'", "false"),
|
|
||||||
("manager[@name = 'Godot']/branch = 'Area 51'", "true"),
|
|
||||||
("//manager[@name = 'Godot']/branch = 'Area 51'", "true"),
|
|
||||||
("manager[@name = 'Godot']/branch = 'Barcelona'", "false"),
|
|
||||||
("//manager[@name = 'Godot']/branch = 'Barcelona'", "false"),
|
|
||||||
("manager[1]/@room_no > manager[2]/@room_no", "true"),
|
|
||||||
("//manager[1]/@room_no > //manager[2]/@room_no", "true"),
|
|
||||||
("manager[@name = 'Godot']/branch[ . = 'Stalsk12'] is manager[1]/branch[1]", "false"),
|
|
||||||
("//manager[@name = 'Godot']/branch[ . = 'Stalsk12'] is //manager[1]/branch[1]", "false"),
|
|
||||||
("manager[@name = 'Godot']/branch[ . = 'Stalsk12'] is manager[1]/branch[3]", "true"),
|
|
||||||
("//manager[@name = 'Godot']/branch[ . = 'Stalsk12'] is //manager[1]/branch[3]", "true"),
|
|
||||||
("manager[@name = 'Godot']/branch[ . = 'Stalsk12'] << manager[1]/branch[1]", "false"),
|
|
||||||
("//manager[@name = 'Godot']/branch[ . = 'Stalsk12'] << //manager[1]/branch[1]", "false"),
|
|
||||||
("manager[@name = 'Godot']/branch[ . = 'Stalsk12'] >> manager[1]/branch[1]", "true"),
|
|
||||||
("//manager[@name = 'Godot']/branch[ . = 'Stalsk12'] >> //manager[1]/branch[1]", "true"),
|
|
||||||
("manager[@name = 'Godot']/branch[ . = 'Stalsk12'] is manager[@name = 'Freya']/branch[ . = 'Stalsk12']", "false"),
|
|
||||||
("//manager[@name = 'Godot']/branch[ . = 'Stalsk12'] is //manager[@name = 'Freya']/branch[ . = 'Stalsk12']", "false"),
|
|
||||||
("manager[1]/@name || manager[2]/@name", "GodotFreya"),
|
|
||||||
("//manager[1]/@name || //manager[2]/@name", "GodotFreya"),
|
|
||||||
])
|
|
||||||
def test_branches_to_visit(html_content, xpath, answer):
|
|
||||||
html_content = html_tools.xpath_filter(xpath, html_content, append_pretty_line_formatting=True)
|
|
||||||
assert type(html_content) == str
|
|
||||||
assert answer in html_content
|
|
||||||
|
|
||||||
trips = """
|
|
||||||
<trips>
|
|
||||||
<trip reservation_number="10">
|
|
||||||
<depart>2023-10-06</depart>
|
|
||||||
<arrive>2023-10-10</arrive>
|
|
||||||
<traveler name="Christopher Anderson">
|
|
||||||
<duration>4</duration>
|
|
||||||
<price>2000.00</price>
|
|
||||||
</traveler>
|
|
||||||
</trip>
|
|
||||||
<trip reservation_number="12">
|
|
||||||
<depart>2023-10-06</depart>
|
|
||||||
<arrive>2023-10-12</arrive>
|
|
||||||
<traveler name="Frank Carter">
|
|
||||||
<duration>6</duration>
|
|
||||||
<price>3500.34</price>
|
|
||||||
</traveler>
|
|
||||||
</trip>
|
|
||||||
</trips>"""
|
|
||||||
@pytest.mark.parametrize("html_content", [trips])
|
|
||||||
@pytest.mark.parametrize("xpath, answer", [
|
|
||||||
("1 + 9 * 9 + 5 div 5", "83"),
|
|
||||||
("(1 + 9 * 9 + 5) div 6", "14.5"),
|
|
||||||
("23 idiv 3", "7"),
|
|
||||||
("23 div 3", "7.66666666"),
|
|
||||||
("for $i in ./trip return $i/traveler/duration * $i/traveler/price", "21002.04"),
|
|
||||||
("for $i in ./trip return $i/traveler/duration ", "4"),
|
|
||||||
("for $i in .//trip return $i/traveler/duration * $i/traveler/price", "21002.04"),
|
|
||||||
("sum(for $i in ./trip return $i/traveler/duration * $i/traveler/price)", "29002.04"),
|
|
||||||
("sum(for $i in .//trip return $i/traveler/duration * $i/traveler/price)", "29002.04"),
|
|
||||||
#("trip[1]/depart - trip[1]/arrive", "fail_to_get_answer"),
|
|
||||||
#("//trip[1]/depart - //trip[1]/arrive", "fail_to_get_answer"),
|
|
||||||
#("trip[1]/depart + trip[1]/arrive", "fail_to_get_answer"),
|
|
||||||
#("xs:date(trip[1]/depart) + xs:date(trip[1]/arrive)", "fail_to_get_answer"),
|
|
||||||
("(//trip[1]/arrive cast as xs:date) - (//trip[1]/depart cast as xs:date)", "P4D"),
|
|
||||||
("(//trip[1]/depart cast as xs:date) - (//trip[1]/arrive cast as xs:date)", "-P4D"),
|
|
||||||
("(//trip[1]/depart cast as xs:date) + xs:dayTimeDuration('P3D')", "2023-10-09"),
|
|
||||||
("(//trip[1]/depart cast as xs:date) - xs:dayTimeDuration('P3D')", "2023-10-03"),
|
|
||||||
("(456, 623) instance of xs:integer", "false"),
|
|
||||||
("(456, 623) instance of xs:integer*", "true"),
|
|
||||||
("/trips/trip instance of element()", "false"),
|
|
||||||
("/trips/trip instance of element()*", "true"),
|
|
||||||
("/trips/trip[1]/arrive instance of xs:date", "false"),
|
|
||||||
("date(/trips/trip[1]/arrive) instance of xs:date", "true"),
|
|
||||||
("'8' cast as xs:integer", "8"),
|
|
||||||
("'11.1E3' cast as xs:double", "11100"),
|
|
||||||
("6.5 cast as xs:integer", "6"),
|
|
||||||
#("/trips/trip[1]/arrive cast as xs:dateTime", "fail_to_get_answer"),
|
|
||||||
("/trips/trip[1]/arrive cast as xs:date", "2023-10-10"),
|
|
||||||
("('2023-10-12') cast as xs:date", "2023-10-12"),
|
|
||||||
("for $i in //trip return concat($i/depart, ' ', $i/arrive)", "2023-10-06 2023-10-10"),
|
|
||||||
])
|
|
||||||
def test_trips(html_content, xpath, answer):
|
|
||||||
html_content = html_tools.xpath_filter(xpath, html_content, append_pretty_line_formatting=True)
|
|
||||||
assert type(html_content) == str
|
|
||||||
assert answer in html_content
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
# run from dir above changedetectionio/ dir
|
|
||||||
# python3 -m unittest changedetectionio.tests.unit.test_notification_diff
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
import os
|
|
||||||
|
|
||||||
from changedetectionio.model import Watch
|
|
||||||
|
|
||||||
# mostly
|
|
||||||
class TestDiffBuilder(unittest.TestCase):
|
|
||||||
|
|
||||||
def test_watch_get_suggested_from_diff_timestamp(self):
|
|
||||||
import uuid as uuid_builder
|
|
||||||
watch = Watch.model(datastore_path='/tmp', default={})
|
|
||||||
watch.ensure_data_dir_exists()
|
|
||||||
|
|
||||||
watch['last_viewed'] = 110
|
|
||||||
|
|
||||||
watch.save_history_text(contents=b"hello world", timestamp=100, snapshot_id=str(uuid_builder.uuid4()))
|
|
||||||
watch.save_history_text(contents=b"hello world", timestamp=105, snapshot_id=str(uuid_builder.uuid4()))
|
|
||||||
watch.save_history_text(contents=b"hello world", timestamp=109, snapshot_id=str(uuid_builder.uuid4()))
|
|
||||||
watch.save_history_text(contents=b"hello world", timestamp=112, snapshot_id=str(uuid_builder.uuid4()))
|
|
||||||
watch.save_history_text(contents=b"hello world", timestamp=115, snapshot_id=str(uuid_builder.uuid4()))
|
|
||||||
watch.save_history_text(contents=b"hello world", timestamp=117, snapshot_id=str(uuid_builder.uuid4()))
|
|
||||||
|
|
||||||
p = watch.get_next_snapshot_key_to_last_viewed
|
|
||||||
assert p == "112", "Correct last-viewed timestamp was detected"
|
|
||||||
|
|
||||||
# When there is only one step of difference from the end of the list, it should return second-last change
|
|
||||||
watch['last_viewed'] = 116
|
|
||||||
p = watch.get_next_snapshot_key_to_last_viewed
|
|
||||||
assert p == "115", "Correct 'second last' last-viewed timestamp was detected when using the last timestamp"
|
|
||||||
|
|
||||||
watch['last_viewed'] = 99
|
|
||||||
p = watch.get_next_snapshot_key_to_last_viewed
|
|
||||||
assert p == "100"
|
|
||||||
|
|
||||||
watch['last_viewed'] = 200
|
|
||||||
p = watch.get_next_snapshot_key_to_last_viewed
|
|
||||||
assert p == "115", "When the 'last viewed' timestamp is greater than the newest snapshot, return second last "
|
|
||||||
|
|
||||||
watch['last_viewed'] = 109
|
|
||||||
p = watch.get_next_snapshot_key_to_last_viewed
|
|
||||||
assert p == "109", "Correct when its the same time"
|
|
||||||
|
|
||||||
# new empty one
|
|
||||||
watch = Watch.model(datastore_path='/tmp', default={})
|
|
||||||
p = watch.get_next_snapshot_key_to_last_viewed
|
|
||||||
assert p == None, "None when no history available"
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
@@ -46,9 +46,6 @@ beautifulsoup4
|
|||||||
# XPath filtering, lxml is required by bs4 anyway, but put it here to be safe.
|
# XPath filtering, lxml is required by bs4 anyway, but put it here to be safe.
|
||||||
lxml
|
lxml
|
||||||
|
|
||||||
# XPath 2.0-3.1 support
|
|
||||||
elementpath
|
|
||||||
|
|
||||||
selenium~=4.14.0
|
selenium~=4.14.0
|
||||||
|
|
||||||
werkzeug~=3.0
|
werkzeug~=3.0
|
||||||
|
|||||||
Reference in New Issue
Block a user