From 4e66085b7cae00ce5213e110cf6d34ee102087eb Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Mon, 19 Sep 2022 12:20:59 +0200 Subject: [PATCH] More coverage --- changedetectionio/run_all_tests.sh | 19 ++++++++++++-- .../tests/proxy_list/test_multiple_proxy.py | 26 ++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/changedetectionio/run_all_tests.sh b/changedetectionio/run_all_tests.sh index 2b0d2dde4..e4ea3bac5 100755 --- a/changedetectionio/run_all_tests.sh +++ b/changedetectionio/run_all_tests.sh @@ -70,10 +70,25 @@ unset HTTPS_PROXY # 2nd test actually choose the preferred proxy from proxies.json -#cp tests/proxy_list/proxies.json-example ./test-datastore/proxies.json -#pytest tests/proxy_list/test_multiple_proxy.py +cp tests/proxy_list/proxies.json-example ./test-datastore/proxies.json +# Makes a watch use a preferred proxy +pytest tests/proxy_list/test_multiple_proxy.py +# Should be a request in the default "first" squid +docker logs $$-squid-one 2>/dev/null|grep chosen.changedetection.io +if [ $? -ne 0 ] +then + echo "Did not see a request to chosen.changedetection.io in the squid logs (while checking preferred proxy)" +fi +# And one in the 'second' squid (user selects this as preferred) +docker logs $$-squid-two 2>/dev/null|grep chosen.changedetection.io +if [ $? -ne 0 ] +then + echo "Did not see a request to chosen.changedetection.io in the squid logs (while checking preferred proxy)" +fi + +# @todo - test system override proxy selection and watch defaults, setup a 3rd squid? docker kill $$-squid-one docker kill $$-squid-two diff --git a/changedetectionio/tests/proxy_list/test_multiple_proxy.py b/changedetectionio/tests/proxy_list/test_multiple_proxy.py index 7e01b808d..208327567 100644 --- a/changedetectionio/tests/proxy_list/test_multiple_proxy.py +++ b/changedetectionio/tests/proxy_list/test_multiple_proxy.py @@ -2,19 +2,37 @@ import time from flask import url_for -from ..util import live_server_setup, wait_for_all_checks, extract_UUID_from_client +from ..util import live_server_setup -def test_check_basic_change_detection_functionality(client, live_server): +def test_preferred_proxy(client, live_server): time.sleep(1) live_server_setup(live_server) time.sleep(1) + url = "http://chosen.changedetection.io" + res = client.post( url_for("import_page"), # Because a URL wont show in squid/proxy logs due it being SSLed # Use plain HTTP or a specific domain-name here - data={"urls": "http://one.changedetection.io"}, + data={"urls": url}, follow_redirects=True ) - assert b"1 Imported" in res.data + assert b"2 Imported" in res.data + time.sleep(2) + res = client.post( + url_for("edit_page", uuid="first"), + data={ + "css_filter": "", + "fetch_backend": "html_requests", + "headers": "", + "proxy": "proxy-two", + "tag": "", + "url": url, + }, + follow_redirects=True + ) + assert b"Updated watch." in res.data + time.sleep(2) + # Now the request should appear in the second-squid logs