mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2026-09-29 00:36:18 +00:00
UI - Splitting off notifications to its own tab/menu - apprise split off
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Has been cancelled
ChangeDetection.io App Test / lint-code (push) Has been cancelled
ChangeDetection.io App Test / lint-translations (push) Has been cancelled
ChangeDetection.io App Test / lint-template-i18n (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
ChangeDetection.io App Test / test-application-3-14 (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
ChangeDetection.io App Test / lint-translations (push) Has been cancelled
ChangeDetection.io App Test / lint-template-i18n (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
ChangeDetection.io App Test / test-application-3-14 (push) Has been cancelled
This commit is contained in:
@@ -28,7 +28,7 @@ def test_check_notification(client, live_server, measure_memory_usage, datastore
|
||||
|
||||
# Re 360 - new install should have defaults set
|
||||
# Notification UI lives on its own page since the global settings refactor.
|
||||
res = client.get(url_for("settings.notifications_page"))
|
||||
res = client.get(url_for("settings.notifications.apprise"))
|
||||
notification_url = url_for('test_notification_endpoint', _external=True).replace('http', 'json')+"?status_code=204"
|
||||
|
||||
assert default_notification_body.encode() in res.data
|
||||
@@ -37,7 +37,7 @@ def test_check_notification(client, live_server, measure_memory_usage, datastore
|
||||
#####################
|
||||
# Set this up for when we remove the notification from the watch, it should fallback with these details
|
||||
res = client.post(
|
||||
url_for("settings.notifications_page"),
|
||||
url_for("settings.notifications.apprise"),
|
||||
data={"notification_urls": notification_url,
|
||||
"notification_title": "fallback-title "+default_notification_title,
|
||||
"notification_body": "fallback-body "+default_notification_body,
|
||||
@@ -47,7 +47,7 @@ def test_check_notification(client, live_server, measure_memory_usage, datastore
|
||||
|
||||
assert b"Settings updated." in res.data
|
||||
|
||||
res = client.get(url_for("settings.notifications_page"))
|
||||
res = client.get(url_for("settings.notifications.apprise"))
|
||||
for k,v in valid_notification_formats.items():
|
||||
if k == USE_SYSTEM_DEFAULT_NOTIFICATION_FORMAT_FOR_WATCH:
|
||||
continue
|
||||
@@ -59,7 +59,7 @@ def test_check_notification(client, live_server, measure_memory_usage, datastore
|
||||
env_base_url = os.getenv('BASE_URL', '').strip()
|
||||
if len(env_base_url):
|
||||
logging.debug(">>> BASE_URL enabled, looking for %s", env_base_url)
|
||||
res = client.get(url_for("settings.notifications_page"))
|
||||
res = client.get(url_for("settings.notifications.apprise"))
|
||||
assert bytes(env_base_url.encode('utf-8')) in res.data
|
||||
else:
|
||||
logging.debug(">>> SKIPPING BASE_URL check")
|
||||
@@ -279,7 +279,7 @@ def test_notification_urls_jinja2_apprise_integration(client, live_server, measu
|
||||
test_notification_url = "hassio://127.0.0.1/longaccesstoken?verify=no&nid={{watch_uuid}}"
|
||||
|
||||
res = client.post(
|
||||
url_for("settings.notifications_page"),
|
||||
url_for("settings.notifications.apprise"),
|
||||
data={
|
||||
"notification_body": '{ "url" : "{{ watch_url }}", "secret": 444, "somebug": "网站监测 内容更新了", "another": "{{diff|truncate(1500)}}" }',
|
||||
"notification_format": default_notification_format,
|
||||
@@ -309,7 +309,7 @@ def test_notification_custom_endpoint_and_jinja2(client, live_server, measure_me
|
||||
test_notification_url = url_for('test_notification_endpoint', _external=True).replace('http://', 'post://')+"?status_code=204&watch_uuid={{ watch_uuid }}&xxx={{ watch_url }}&now={% now 'Europe/London', '%Y-%m-%d' %}&+custom-header=123&+second=hello+world%20%22space%22"
|
||||
|
||||
res = client.post(
|
||||
url_for("settings.notifications_page"),
|
||||
url_for("settings.notifications.apprise"),
|
||||
data={
|
||||
"notification_body": '{ "url" : "{{ watch_url }}", "secret": 444, "somebug": "网站监测 内容更新了" }',
|
||||
"notification_format": default_notification_format,
|
||||
@@ -392,7 +392,7 @@ def test_global_send_test_notification(client, live_server, measure_memory_usage
|
||||
|
||||
# otherwise other settings would have already existed from previous tests in this file
|
||||
res = client.post(
|
||||
url_for("settings.notifications_page"),
|
||||
url_for("settings.notifications.apprise"),
|
||||
data={
|
||||
"notification_body": test_body,
|
||||
"notification_format": default_notification_format,
|
||||
@@ -580,7 +580,7 @@ def _test_color_notifications(client, notification_body_token, datastore_path):
|
||||
|
||||
# otherwise other settings would have already existed from previous tests in this file
|
||||
res = client.post(
|
||||
url_for("settings.notifications_page"),
|
||||
url_for("settings.notifications.apprise"),
|
||||
data={
|
||||
"notification_body": notification_body_token,
|
||||
"notification_format": "htmlcolor",
|
||||
@@ -652,7 +652,7 @@ def _test_custom_html_in_notification_body_not_escaped(client, datastore_path, c
|
||||
test_url = url_for('test_endpoint', _external=True, **kwargs)
|
||||
|
||||
res = client.post(
|
||||
url_for("settings.notifications_page"),
|
||||
url_for("settings.notifications.apprise"),
|
||||
data={
|
||||
"notification_body": '<a href="{{watch_url}}">Watch Link</a> had changes\n\n{{diff}}',
|
||||
"notification_format": "htmlcolor",
|
||||
@@ -730,7 +730,7 @@ def test_html_watch_diff_content_escaped_in_html_notification(client, live_serve
|
||||
# HTML-format notification body that embeds the snapshot directly. Operators do this
|
||||
# when they want the full changed content in the alert (e.g. an email digest).
|
||||
res = client.post(
|
||||
url_for("settings.notifications_page"),
|
||||
url_for("settings.notifications.apprise"),
|
||||
data={
|
||||
"notification_body": 'Watch had changes:\n{{current_snapshot}}',
|
||||
"notification_format": "html",
|
||||
@@ -808,7 +808,7 @@ def test_source_url_diff_content_escaped_in_html_notification(client, live_serve
|
||||
test_url = 'source:' + url_for('test_endpoint', _external=True, content_type='text/html')
|
||||
|
||||
res = client.post(
|
||||
url_for("settings.notifications_page"),
|
||||
url_for("settings.notifications.apprise"),
|
||||
data={
|
||||
"notification_body": 'Watch had changes:\n{{current_snapshot}}',
|
||||
"notification_format": "html",
|
||||
|
||||
@@ -33,7 +33,7 @@ def test_notifications_page_renders_form_inputs(
|
||||
Scans for each field's `name="..."` attribute (widget-agnostic — works for
|
||||
StringField/TextAreaField/SelectField/StringListField alike) plus the
|
||||
submit button and the notifications.js wiring."""
|
||||
res = client.get(url_for('settings.notifications_page'))
|
||||
res = client.get(url_for('settings.notifications.apprise'))
|
||||
assert res.status_code == 200
|
||||
body = res.data.decode('utf-8', errors='replace')
|
||||
|
||||
@@ -43,8 +43,8 @@ def test_notifications_page_renders_form_inputs(
|
||||
f"Form input for {field!r} missing from /settings/notifications HTML"
|
||||
|
||||
# Submit form actually wired to the right route
|
||||
assert f'action="{url_for("settings.notifications_page")}"' in body, \
|
||||
"Form should POST back to /settings/notifications"
|
||||
assert f'action="{url_for("settings.notifications.apprise")}"' in body, \
|
||||
"Form should POST back to /settings/notifications/apprise"
|
||||
|
||||
# notifications.js needs the JS-side ajax endpoint to test sends from this page
|
||||
assert 'notification_base_url' in body, \
|
||||
@@ -72,7 +72,7 @@ def test_notifications_page_get_renders_stored_values(
|
||||
ds = client.application.config.get('DATASTORE')
|
||||
_seed_notification_config(ds)
|
||||
|
||||
res = client.get(url_for('settings.notifications_page'))
|
||||
res = client.get(url_for('settings.notifications.apprise'))
|
||||
assert res.status_code == 200
|
||||
body = res.data.decode('utf-8', errors='replace')
|
||||
|
||||
@@ -91,7 +91,7 @@ def test_notifications_page_post_saves_values(
|
||||
ds = client.application.config.get('DATASTORE')
|
||||
|
||||
res = client.post(
|
||||
url_for('settings.notifications_page'),
|
||||
url_for('settings.notifications.apprise'),
|
||||
data={
|
||||
'notification_urls': 'json://example.invalid/new',
|
||||
'notification_title': 'New title - {{ watch_url }}',
|
||||
@@ -173,14 +173,36 @@ def test_notifications_page_save_does_not_clobber_other_settings(
|
||||
"""
|
||||
Inverse of the above — saving notifications must NOT reach over and zero
|
||||
out unrelated application settings (pager_size, fetch_backend, etc.).
|
||||
|
||||
The notifications-page handler explicitly writes a known list of five
|
||||
notification fields rather than doing app.update(form.data) — this test
|
||||
pins that behaviour so a refactor that switches to .update() (which would
|
||||
silently zero out every non-notification key) fails loudly here.
|
||||
"""
|
||||
ds = client.application.config.get('DATASTORE')
|
||||
app = ds.data['settings']['application']
|
||||
app['pager_size'] = 42
|
||||
app['fetch_backend'] = 'html_requests'
|
||||
# Plant a representative mix of application-level fields: ints, lists,
|
||||
# strings, bools, nested dicts. If the notifications save ever does a
|
||||
# blanket .update(form.data) it'll wipe these to WTForms defaults and
|
||||
# the per-field asserts below will catch it.
|
||||
untouched_snapshot = {
|
||||
'pager_size': 73,
|
||||
'fetch_backend': 'html_requests',
|
||||
'rss_diff_length': 9,
|
||||
'filter_failure_notification_threshold_attempts': 4,
|
||||
'global_ignore_text': ['SENTINEL-IGNORE-LINE'],
|
||||
'global_subtractive_selectors': ['nav.SENTINEL-SUB'],
|
||||
'ignore_whitespace': True,
|
||||
'render_anchor_tag_content': True,
|
||||
'shared_diff_access': True,
|
||||
'api_access_token_enabled': False,
|
||||
'scheduler_timezone_default': 'Europe/Berlin',
|
||||
}
|
||||
for k, v in untouched_snapshot.items():
|
||||
app[k] = v
|
||||
|
||||
res = client.post(
|
||||
url_for('settings.notifications_page'),
|
||||
url_for('settings.notifications.apprise'),
|
||||
data={
|
||||
'notification_urls': 'json://example.invalid/only-this',
|
||||
'notification_title': '',
|
||||
@@ -191,7 +213,15 @@ def test_notifications_page_save_does_not_clobber_other_settings(
|
||||
follow_redirects=True,
|
||||
)
|
||||
assert res.status_code == 200
|
||||
assert b'Settings updated.' in res.data, \
|
||||
"Notification save did not reach the success branch — test setup is wrong"
|
||||
|
||||
# Unrelated fields must be untouched.
|
||||
assert ds.data['settings']['application'].get('pager_size') == 42
|
||||
assert ds.data['settings']['application'].get('fetch_backend') == 'html_requests'
|
||||
# Every planted field must have survived the notifications save bit-for-bit.
|
||||
for k, expected in untouched_snapshot.items():
|
||||
actual = ds.data['settings']['application'].get(k)
|
||||
assert actual == expected, \
|
||||
f"Notification save clobbered unrelated setting {k!r}: expected {expected!r}, got {actual!r}"
|
||||
|
||||
# And the notification field we DID submit was actually written.
|
||||
assert ds.data['settings']['application'].get('notification_urls') == \
|
||||
['json://example.invalid/only-this']
|
||||
|
||||
Reference in New Issue
Block a user