Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On editing filters for a watch, it should not return an empty change #1748

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changedetectionio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ def edit_page(uuid):
datastore.needs_write_urgent = True

# Queue the watch for immediate recheck, with a higher priority
# 'False' - fully reprocess the diff so we can see any new filters added
update_q.put(queuedWatchMetaData.PrioritizedItem(priority=1, item={'uuid': uuid, 'skip_when_checksum_same': False}))

# Diff page [edit] link should go back to diff page
Expand Down Expand Up @@ -1254,6 +1255,9 @@ def form_clone():
@app.route("/api/checknow", methods=['GET'])
@login_optionally_required
def form_watch_checknow():

# 'skip_when_checksum_same': should be False so that 'FilterNotFoundInResponse' can be checked

# Forced recheck will skip the 'skip if content is the same' rule (, 'reprocess_existing_data': True})))
tag = request.args.get('tag')
uuid = request.args.get('uuid')
Expand Down
4 changes: 2 additions & 2 deletions changedetectionio/processors/text_json_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ def run(self, uuid, skip_when_checksum_same=True, preferred_proxy=None):
if not rendered_diff and stripped_text_from_html:
# We had some content, but no differences were found
# Store our new file as the MD5 so it will trigger in the future
c = hashlib.md5(text_content_before_ignored_filter.translate(None, b'\r\n\t ')).hexdigest()
return False, {'previous_md5': c}, stripped_text_from_html.encode('utf-8')
update_obj['previous_md5'] = hashlib.md5(text_content_before_ignored_filter.translate(None, b'\r\n\t ')).hexdigest()
return False, update_obj, stripped_text_from_html.encode('utf-8')
else:
stripped_text_from_html = rendered_diff

Expand Down
20 changes: 14 additions & 6 deletions changedetectionio/tests/test_add_replace_remove_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def set_original(excluding=None, add_line=None):
for i in test_return_data.splitlines():
if not excluding in i:
output += f"{i}\n"

test_return_data = output

with open("test-datastore/endpoint-content.txt", "w") as f:
Expand All @@ -39,9 +38,8 @@ def test_setup(client, live_server):
live_server_setup(live_server)

def test_check_removed_line_contains_trigger(client, live_server):

#live_server_setup(live_server)
# Give the endpoint time to spin up
time.sleep(1)
set_original()
# Add our URL to the import page
test_url = url_for('test_endpoint', _external=True)
Expand All @@ -52,9 +50,14 @@ def test_check_removed_line_contains_trigger(client, live_server):
)
assert b"1 Imported" in res.data

from .util import extract_UUID_from_client
uuid = extract_UUID_from_client(client)

# Give the thread time to pick it up
wait_for_all_checks(client)

#assert live_server.app.config['DATASTORE'].data['watching'][uuid]['previous_md5_before_filters'] == '3f10f9d7e3bc2b04197f525b30ca05af'

# Goto the edit page, add our ignore text
# Add our URL to the import page
res = client.post(
Expand All @@ -67,12 +70,13 @@ def test_check_removed_line_contains_trigger(client, live_server):
)
assert b"Updated watch." in res.data
wait_for_all_checks(client)
set_original(excluding='Something irrelevant')

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
wait_for_all_checks(client)
assert live_server.app.config['DATASTORE'].data['watching'][uuid]['previous_md5_before_filters'] == '1262fa651e226e126fabe0275e131e82'
res = client.get(url_for("index"))
assert b'unviewed' not in res.data

Expand All @@ -92,10 +96,14 @@ def test_check_removed_line_contains_trigger(client, live_server):
res = client.get(url_for("index"))
assert b'unviewed' not in res.data

# Remove it again, and we should get a trigger
# It should now have 'The golden line' back, so we remove it, check again
# We should get a trigger
set_original(excluding='The golden line')
client.get(url_for("form_watch_checknow"), follow_redirects=True)
wait_for_all_checks(client)
#assert live_server.app.config['DATASTORE'].data['watching'][uuid]['previous_md5_before_filters'] == '2288c23519a6a90809defb37d79f98f4'
res = client.get(url_for("preview_page", uuid="first"))
assert b'The golden line' not in res.data
res = client.get(url_for("index"))
assert b'unviewed' in res.data

Expand All @@ -107,7 +115,7 @@ def test_check_add_line_contains_trigger(client, live_server):
#live_server_setup(live_server)

# Give the endpoint time to spin up
time.sleep(1)
#time.sleep(1)
test_notification_url = url_for('test_notification_endpoint', _external=True).replace('http://', 'post://') + "?xxx={{ watch_url }}"

res = client.post(
Expand Down
1 change: 0 additions & 1 deletion changedetectionio/update_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ def run(self):
if update_handler.xpath_data:
self.datastore.save_xpath_data(watch_uuid=uuid, data=update_handler.xpath_data)


self.current_uuid = None # Done
self.q.task_done()

Expand Down
Loading