From 90642742bdc3691a5a046a449f41c89e6297c4ea Mon Sep 17 00:00:00 2001 From: Leigh Morresi <275001+dgtlmoon@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:46:56 +0100 Subject: [PATCH] Extending tests to cover resetting the diff/unviewed status correctly --- backend/__init__.py | 10 ++++++++++ backend/tests/test_backend.py | 32 +++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/backend/__init__.py b/backend/__init__.py index 1d5b4ae2..2ec5404c 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -249,6 +249,11 @@ def changedetection_app(config=None, datastore_o=None): def diff_history_page(uuid): global messages + # More for testing, possible to return the first/only + if uuid == 'first': + uuid= list(datastore.data['watching'].keys()).pop() + + extra_stylesheets = ['/static/css/diff.css'] watch = datastore.data['watching'][uuid] @@ -259,6 +264,11 @@ def changedetection_app(config=None, datastore_o=None): dates.sort(reverse=True) dates = [str(i) for i in dates] + + if len(dates) < 2: + messages.append({'class': 'error', 'message': "Not enough saved change detection snapshots to produce a report."}) + return redirect(url_for('index')) + # Save the current newest history as the most recently viewed datastore.set_last_viewed(uuid, dates[0]) diff --git a/backend/tests/test_backend.py b/backend/tests/test_backend.py index f1fdff19..23ae20f0 100644 --- a/backend/tests/test_backend.py +++ b/backend/tests/test_backend.py @@ -58,15 +58,17 @@ def test_check_basic_change_detection_functionality(client, live_server): ) assert b"1 Imported" in res.data - client.get(url_for("api_watch_checknow"), follow_redirects=True) + # Do this a few times.. ensures we dont accidently set the status + for n in range(3): + client.get(url_for("api_watch_checknow"), follow_redirects=True) - # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + # Give the thread time to pick it up + time.sleep(sleep_time_for_fetch_thread) - # It should report nothing found (no new 'unviewed' class) - res = client.get(url_for("index")) - assert b'unviewed' not in res.data - assert b'test-endpoint' in res.data + # It should report nothing found (no new 'unviewed' class) + res = client.get(url_for("index")) + assert b'unviewed' not in res.data + assert b'test-endpoint' in res.data # Give the thread time to pick it up time.sleep(sleep_time_for_fetch_thread) @@ -91,3 +93,19 @@ def test_check_basic_change_detection_functionality(client, live_server): # Now something should be ready, indicated by having a 'unviewed' class res = client.get(url_for("index")) assert b'unviewed' in res.data + + # Following the 'diff' link, it should no longer display as 'unviewed' even after we recheck it a few times + res = client.get(url_for("diff_history_page", uuid="first") ) + assert b'Compare newest' in res.data + + # Do this a few times.. ensures we dont accidently set the status + for n in range(2): + client.get(url_for("api_watch_checknow"), follow_redirects=True) + + # Give the thread time to pick it up + time.sleep(sleep_time_for_fetch_thread) + + # It should report nothing found (no new 'unviewed' class) + res = client.get(url_for("index")) + assert b'unviewed' not in res.data + assert b'test-endpoint' in res.data