Refactor code layout, add extra tests
Some checks failed
Build and push containers / metadata (push) Has been cancelled
Build and push containers / build-push-containers (push) Has been cancelled
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Has been cancelled
ChangeDetection.io App Test / lint-code (push) Has been cancelled
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Test the built 📦 package works basically. (push) Has been cancelled
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Publish Python 🐍 distribution 📦 to PyPI (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-10 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-11 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-12 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-13 (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled

This commit is contained in:
dgtlmoon
2025-03-18 10:40:22 +01:00
committed by GitHub
parent 7e7d5dc383
commit 73189672c3
89 changed files with 2541 additions and 1836 deletions

View File

@@ -1,4 +1,6 @@
#!/usr/bin/env python3
import json
import urllib
from flask import url_for
from .util import live_server_setup, wait_for_all_checks
@@ -53,7 +55,7 @@ def test_conditions_with_text_and_number(client, live_server):
# Add our URL to the import page
res = client.post(
url_for("import_page"),
url_for("imports.import_page"),
data={"urls": test_url},
follow_redirects=True
)
@@ -64,7 +66,7 @@ def test_conditions_with_text_and_number(client, live_server):
# 1. The page filtered text must contain "5" (first digit of value)
# 2. The extracted number should be >= 20 and <= 100
res = client.post(
url_for("edit_page", uuid="first"),
url_for("ui.ui_edit.edit_page", uuid="first"),
data={
"url": test_url,
"fetch_backend": "html_requests",
@@ -103,12 +105,12 @@ def test_conditions_with_text_and_number(client, live_server):
assert b"Updated watch." in res.data
wait_for_all_checks(client)
client.get(url_for("mark_all_viewed"), follow_redirects=True)
client.get(url_for("ui.mark_all_viewed"), follow_redirects=True)
wait_for_all_checks(client)
# Case 1
set_number_in_range_response("70.5")
client.get(url_for("form_watch_checknow"), follow_redirects=True)
client.get(url_for("ui.form_watch_checknow"), follow_redirects=True)
wait_for_all_checks(client)
# 75 is > 20 and < 100 and contains "5"
@@ -118,16 +120,77 @@ def test_conditions_with_text_and_number(client, live_server):
# Case 2: Change with one condition violated
# Number out of range (150) but contains '5'
client.get(url_for("mark_all_viewed"), follow_redirects=True)
client.get(url_for("ui.mark_all_viewed"), follow_redirects=True)
set_number_out_of_range_response("150.5")
client.get(url_for("form_watch_checknow"), follow_redirects=True)
client.get(url_for("ui.form_watch_checknow"), follow_redirects=True)
wait_for_all_checks(client)
# Should NOT be marked as having changes since not all conditions are met
res = client.get(url_for("index"))
assert b'unviewed' not in res.data
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True)
assert b'Deleted' in res.data
# The 'validate' button next to each rule row
def test_condition_validate_rule_row(client, live_server):
set_original_response("50")
test_url = url_for('test_endpoint', _external=True)
# Add our URL to the import page
res = client.post(
url_for("imports.import_page"),
data={"urls": test_url},
follow_redirects=True
)
assert b"1 Imported" in res.data
wait_for_all_checks(client)
uuid = next(iter(live_server.app.config['DATASTORE'].data['watching']))
# the front end submits the current form state which should override the watch in a temporary copy
res = client.post(
url_for("conditions.verify_condition_single_rule", watch_uuid=uuid), # Base URL
query_string={"rule": json.dumps({"field": "extracted_number", "operator": "==", "value": "50"})},
data={'include_filter': ""},
follow_redirects=True
)
assert res.status_code == 200
assert b'success' in res.data
# Now a number that does not equal what is found in the last fetch
res = client.post(
url_for("conditions.verify_condition_single_rule", watch_uuid=uuid), # Base URL
query_string={"rule": json.dumps({"field": "extracted_number", "operator": "==", "value": "111111"})},
data={'include_filter': ""},
follow_redirects=True
)
assert res.status_code == 200
assert b'false' in res.data
# Now custom filter that exists
res = client.post(
url_for("conditions.verify_condition_single_rule", watch_uuid=uuid), # Base URL
query_string={"rule": json.dumps({"field": "extracted_number", "operator": "==", "value": "50"})},
data={'include_filter': ".number-container"},
follow_redirects=True
)
assert res.status_code == 200
assert b'success' in res.data
# Now custom filter that DOES NOT exists
res = client.post(
url_for("conditions.verify_condition_single_rule", watch_uuid=uuid), # Base URL
query_string={"rule": json.dumps({"field": "extracted_number", "operator": "==", "value": "50"})},
data={'include_filters': ".NOT-container"},
follow_redirects=True
)
assert res.status_code == 200
assert b'false' in res.data