|
1 | 1 | #!/usr/bin/env python3 |
| 2 | +import json |
| 3 | +import urllib |
2 | 4 |
|
3 | 5 | from flask import url_for |
4 | 6 | from .util import live_server_setup, wait_for_all_checks |
@@ -131,3 +133,64 @@ def test_conditions_with_text_and_number(client, live_server): |
131 | 133 |
|
132 | 134 | res = client.get(url_for("ui.form_delete", uuid="all"), follow_redirects=True) |
133 | 135 | 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