Re #143 - Remove old notification test code, fix form handler (#145)

* Re #143 - global notification settings box fix - Remove old notification test code, fix form handler, add test
pull/150/head
dgtlmoon 3 years ago committed by GitHub
parent 32a798128c
commit fe4963ec04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -486,29 +486,10 @@ def changedetection_app(config=None, datastore_o=None):
datastore.data['settings']['application']['notification_title'] = form.notification_title.data datastore.data['settings']['application']['notification_title'] = form.notification_title.data
datastore.data['settings']['application']['notification_body'] = form.notification_body.data datastore.data['settings']['application']['notification_body'] = form.notification_body.data
if len(form.notification_urls.data):
import apprise
apobj = apprise.Apprise()
apobj.debug = True
# Add each notification
for n in datastore.data['settings']['application']['notification_urls']:
apobj.add(n)
outcome = apobj.notify(
body='Hello from the worlds best and simplest web page change detection and monitoring service!',
title='Changedetection.io Notification Test',
)
if outcome:
flash("{} Notification URLs reached.".format(len(form.notification_urls.data)), "notice")
else:
flash("One or more Notification URLs failed", 'error')
datastore.data['settings']['application']['notification_urls'] = form.notification_urls.data datastore.data['settings']['application']['notification_urls'] = form.notification_urls.data
datastore.needs_write = True datastore.needs_write = True
if form.trigger_check.data: if form.trigger_check.data and len(form.notification_urls.data):
n_object = {'watch_url': "Test from changedetection.io!", n_object = {'watch_url': "Test from changedetection.io!",
'notification_urls': form.notification_urls.data} 'notification_urls': form.notification_urls.data}
notification_q.put(n_object) notification_q.put(n_object)

@ -86,11 +86,9 @@ SMTPS - mailtos://user:pass@mail.domain.com?to=receivingAddress@example.com") }}
</span> </span>
</div> </div>
</div> </div>
<div class="pure-control-group">
<span class="pure-form-message-inline"><label for="trigger-test-notification" class="pure-checkbox"> {{ render_field(form.trigger_check) }}
<input type="checkbox" id="trigger-test-notification" name="trigger-test-notification"> Send test notification on save.</label> </div>
</span>
</div> </div>
<div class="pure-control-group"> <div class="pure-control-group">
<button type="submit" class="pure-button pure-button-primary">Save</button> <button type="submit" class="pure-button pure-button-primary">Save</button>

@ -94,10 +94,13 @@ def test_check_notification(client, live_server):
url_for("settings_page"), url_for("settings_page"),
data={"notification_title": "New ChangeDetection.io Notification - {watch_url}", data={"notification_title": "New ChangeDetection.io Notification - {watch_url}",
"notification_body": "{base_url}\n{watch_url}\n{preview_url}\n{diff_url}\n{current_snapshot}\n:-)", "notification_body": "{base_url}\n{watch_url}\n{preview_url}\n{diff_url}\n{current_snapshot}\n:-)",
"notification_urls": "json://foobar.com", #Re #143 should not see that it sent without [test checkbox]
"minutes_between_check": 180}, "minutes_between_check": 180},
follow_redirects=True follow_redirects=True
) )
assert b"Settings updated." in res.data assert b"Settings updated." in res.data
# Re #143 - should not see this if we didnt hit the test box
assert b"Notifications queued" not in res.data
# Trigger a check # Trigger a check
client.get(url_for("api_watch_checknow"), follow_redirects=True) client.get(url_for("api_watch_checknow"), follow_redirects=True)

Loading…
Cancel
Save