Skip to content

Commit 0ec9fd4

Browse files
committed
Add test for the validate rule row button
1 parent 317048d commit 0ec9fd4

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

changedetectionio/conditions/blueprint.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def verify_condition_single_rule(watch_uuid):
4646
# Override the conditions in the temporary watch
4747
rule_json = request.args.get("rule")
4848
rule = json.loads(rule_json) if rule_json else None
49+
50+
# Should be key/value of field, operator, value
4951
tmp_watch_data['conditions'] = [rule]
5052
tmp_watch_data['conditions_match_logic'] = "ALL" # Single rule, so use ALL
5153

changedetectionio/tests/test_conditions.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env python3
2+
import json
3+
import urllib
24

35
from flask import url_for
46
from .util import live_server_setup, wait_for_all_checks
@@ -131,3 +133,64 @@ def test_conditions_with_text_and_number(client, live_server):
131133

132134
res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True)
133135
assert b'Deleted' in res.data
136+
137+
# The 'validate' button next to each rule row
138+
def test_condition_validate_rule_row(client, live_server):
139+
140+
set_original_response("50")
141+
142+
test_url = url_for('test_endpoint', _external=True)
143+
144+
# Add our URL to the import page
145+
res = client.post(
146+
url_for("imports.import_page"),
147+
data={"urls": test_url},
148+
follow_redirects=True
149+
)
150+
assert b"1 Imported" in res.data
151+
wait_for_all_checks(client)
152+
153+
uuid = next(iter(live_server.app.config['DATASTORE'].data['watching']))
154+
155+
# the front end submits the current form state which should override the watch in a temporary copy
156+
res = client.post(
157+
url_for("conditions.verify_condition_single_rule", watch_uuid=uuid), # Base URL
158+
query_string={"rule": json.dumps({"field": "extracted_number", "operator": "==", "value": "50"})},
159+
data={'include_filter': ""},
160+
follow_redirects=True
161+
)
162+
assert res.status_code == 200
163+
assert b'success' in res.data
164+
165+
# Now a number that does not equal what is found in the last fetch
166+
res = client.post(
167+
url_for("conditions.verify_condition_single_rule", watch_uuid=uuid), # Base URL
168+
query_string={"rule": json.dumps({"field": "extracted_number", "operator": "==", "value": "111111"})},
169+
data={'include_filter': ""},
170+
follow_redirects=True
171+
)
172+
assert res.status_code == 200
173+
assert b'false' in res.data
174+
175+
# Now custom filter that exists
176+
res = client.post(
177+
url_for("conditions.verify_condition_single_rule", watch_uuid=uuid), # Base URL
178+
query_string={"rule": json.dumps({"field": "extracted_number", "operator": "==", "value": "50"})},
179+
data={'include_filter': ".number-container"},
180+
follow_redirects=True
181+
)
182+
assert res.status_code == 200
183+
assert b'success' in res.data
184+
185+
# Now custom filter that DOES NOT exists
186+
res = client.post(
187+
url_for("conditions.verify_condition_single_rule", watch_uuid=uuid), # Base URL
188+
query_string={"rule": json.dumps({"field": "extracted_number", "operator": "==", "value": "50"})},
189+
data={'include_filters': ".NOT-container"},
190+
follow_redirects=True
191+
)
192+
assert res.status_code == 200
193+
assert b'false' in res.data
194+
195+
196+

0 commit comments

Comments
 (0)