mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2026-10-25 08:11:24 +00:00
Tests - Add get_form_field() helper (BeautifulSoup), use it for the restock threshold value instead of a regex
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f4071e970
commit
a5b645c7ac
2 files changed
+15
-5
No files matched your search
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
import re
|
||||
import os
|
||||
import time
|
||||
|
||||
from flask import url_for
|
||||
from .util import live_server_setup, wait_for_all_checks, wait_for_notification_endpoint_output, extract_UUID_from_client, delete_all_watches
|
||||
from .util import live_server_setup, wait_for_all_checks, wait_for_notification_endpoint_output, extract_UUID_from_client, delete_all_watches, \
|
||||
get_form_field
|
||||
from ..notification import default_notification_format
|
||||
|
||||
instock_props = [
|
||||
@@ -340,9 +340,8 @@ def test_itemprop_percent_threshold(client, live_server, measure_memory_usage, d
|
||||
# And back again
|
||||
live_server.app.config['DATASTORE'].data['watching'][uuid]['processor'] = 'restock_diff'
|
||||
res = client.get(url_for("ui.ui_edit.edit_page", uuid=uuid))
|
||||
# Don't assert the input type: WTForms 3.3 renders FloatField as type="number", older versions as type="text"
|
||||
threshold_input = re.search(rb'<input[^>]*name="processor_config_restock_diff-price_change_threshold_percent"[^>]*>', res.data)
|
||||
assert threshold_input and b'value="5.05"' in threshold_input.group(0)
|
||||
threshold_input = get_form_field(res.data, 'processor_config_restock_diff-price_change_threshold_percent')
|
||||
assert threshold_input and threshold_input['value'] == '5.05'
|
||||
|
||||
delete_all_watches(client)
|
||||
|
||||
|
||||
@@ -159,6 +159,17 @@ def extract_UUID_from_client(client):
|
||||
uuid = m.group(1)
|
||||
return uuid.strip()
|
||||
|
||||
|
||||
def get_form_field(html, name):
|
||||
"""Return the <input>, <select> or <textarea> named `name` in the page, or None.
|
||||
|
||||
Use this to assert a field's value (field['value'], field.has_attr('checked')) instead of matching raw
|
||||
bytes like b'type="text" value="5"', which breaks on attribute order, quoting or a changed input type
|
||||
(WTForms 3.3 renders FloatField as type="number"). Keep raw byte checks where the escaping is the point.
|
||||
"""
|
||||
from bs4 import BeautifulSoup
|
||||
return BeautifulSoup(html, 'html.parser').find(['input', 'select', 'textarea'], attrs={'name': name})
|
||||
|
||||
def delete_all_watches(client=None):
|
||||
wait_for_all_checks(client)
|
||||
|
||||
|
||||
Reference in new issue
Block a user