■ ■ ■ ■ ■ ■
changedetectionio/tests/test_notification.py
| skipped 70 lines |
71 | 71 | | "url": test_url, |
72 | 72 | | "tag": "my tag", |
73 | 73 | | "title": "my title", |
| 74 | + | # No 'notification_use_default' here, so it's effectively False/off |
74 | 75 | | "headers": "", |
75 | 76 | | "fetch_backend": "html_requests"}) |
76 | 77 | | |
| skipped 139 lines |
216 | 217 | | follow_redirects=True |
217 | 218 | | ) |
218 | 219 | | |
| 220 | + | # Check that the default VS watch specific notification is hit |
| 221 | + | def test_check_notification_use_default(client, live_server): |
| 222 | + | set_original_response() |
| 223 | + | notification_url = url_for('test_notification_endpoint', _external=True).replace('http', 'json') |
| 224 | + | test_url = url_for('test_endpoint', _external=True) |
| 225 | + | |
| 226 | + | res = client.post( |
| 227 | + | url_for("form_quick_watch_add"), |
| 228 | + | data={"url": test_url, "tag": ''}, |
| 229 | + | follow_redirects=True |
| 230 | + | ) |
| 231 | + | assert b"Watch added" in res.data |
| 232 | + | |
| 233 | + | ## Setup the local one and enable it |
| 234 | + | res = client.post( |
| 235 | + | url_for("edit_page", uuid="first"), |
| 236 | + | data={"notification_urls": notification_url, |
| 237 | + | "notification_title": "watch-notification", |
| 238 | + | "notification_body": "watch-body", |
| 239 | + | 'notification_use_default': "True", |
| 240 | + | "notification_format": "Text", |
| 241 | + | "url": test_url, |
| 242 | + | "tag": "my tag", |
| 243 | + | "title": "my title", |
| 244 | + | "headers": "", |
| 245 | + | "fetch_backend": "html_requests"}, |
| 246 | + | follow_redirects=True |
| 247 | + | ) |
| 248 | + | |
| 249 | + | res = client.post( |
| 250 | + | url_for("settings_page"), |
| 251 | + | data={"application-notification_title": "global-notifications-title", |
| 252 | + | "application-notification_body": "global-notifications-body\n", |
| 253 | + | "application-notification_format": "Text", |
| 254 | + | "application-notification_urls": notification_url, |
| 255 | + | "requests-time_between_check-minutes": 180, |
| 256 | + | "fetch_backend": "html_requests" |
| 257 | + | }, |
| 258 | + | follow_redirects=True |
| 259 | + | ) |
| 260 | + | |
| 261 | + | # A change should by default trigger a notification of the global-notifications |
| 262 | + | time.sleep(1) |
| 263 | + | set_modified_response() |
| 264 | + | client.get(url_for("form_watch_checknow"), follow_redirects=True) |
| 265 | + | time.sleep(2) |
| 266 | + | with open("test-datastore/notification.txt", "r") as f: |
| 267 | + | assert 'global-notifications-title' in f.read() |
| 268 | + | |
| 269 | + | ## Setup the local one and enable it |
| 270 | + | res = client.post( |
| 271 | + | url_for("edit_page", uuid="first"), |
| 272 | + | data={"notification_urls": notification_url, |
| 273 | + | "notification_title": "watch-notification", |
| 274 | + | "notification_body": "watch-body", |
| 275 | + | # No 'notification_use_default' here, so it's effectively False/off = "dont use default, use this one" |
| 276 | + | "notification_format": "Text", |
| 277 | + | "url": test_url, |
| 278 | + | "tag": "my tag", |
| 279 | + | "title": "my title", |
| 280 | + | "headers": "", |
| 281 | + | "fetch_backend": "html_requests"}, |
| 282 | + | follow_redirects=True |
| 283 | + | ) |
| 284 | + | set_original_response() |
| 285 | + | |
| 286 | + | client.get(url_for("form_watch_checknow"), follow_redirects=True) |
| 287 | + | time.sleep(2) |
| 288 | + | assert os.path.isfile("test-datastore/notification.txt") |
| 289 | + | with open("test-datastore/notification.txt", "r") as f: |
| 290 | + | assert 'watch-notification' in f.read() |
| 291 | + | |
| 292 | + | |
| 293 | + | # cleanup for the next |
| 294 | + | client.get( |
| 295 | + | url_for("form_delete", uuid="all"), |
| 296 | + | follow_redirects=True |
| 297 | + | ) |