From 93f3bebe0fcbd1b0ffc1ce7b518b8f1ef5c330a8 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Wed, 12 Oct 2022 09:34:41 +0200 Subject: [PATCH] test - only test for jq if jq installed, install jq and retest --- changedetectionio/run_all_tests.sh | 4 +-- ...lector.py => test_jsonpath_jq_selector.py} | 30 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) rename changedetectionio/tests/{DISABLED_test_jsonpath_jq_selector.py => test_jsonpath_jq_selector.py} (94%) diff --git a/changedetectionio/run_all_tests.sh b/changedetectionio/run_all_tests.sh index 4fb2e334..28dd85c6 100755 --- a/changedetectionio/run_all_tests.sh +++ b/changedetectionio/run_all_tests.sh @@ -25,9 +25,9 @@ pytest tests/test_notification.py ## JQ + JSON: filter test # jq is not available on windows and we should just test it when the package is installed -# This will test the json and jq filters +# this will re-test with jq support pip3 install jq~=1.3 -pytest tests/DISABLED_test_jsonpath_jq_selector.py +pytest tests/test_jsonpath_jq_selector.py # Now for the selenium and playwright/browserless fetchers diff --git a/changedetectionio/tests/DISABLED_test_jsonpath_jq_selector.py b/changedetectionio/tests/test_jsonpath_jq_selector.py similarity index 94% rename from changedetectionio/tests/DISABLED_test_jsonpath_jq_selector.py rename to changedetectionio/tests/test_jsonpath_jq_selector.py index d0082122..f6da84db 100644 --- a/changedetectionio/tests/DISABLED_test_jsonpath_jq_selector.py +++ b/changedetectionio/tests/test_jsonpath_jq_selector.py @@ -5,7 +5,12 @@ import time from flask import url_for, escape from . util import live_server_setup import pytest +jq_support = True +try: + import jq +except ModuleNotFoundError: + jq_support = False def test_setup(live_server): live_server_setup(live_server) @@ -40,13 +45,14 @@ and it can also be repeated assert text == "23.5" # also check for jq - text = html_tools.extract_json_as_string(content, "jq:.offers.price") - assert text == "23.5" + if jq_support: + text = html_tools.extract_json_as_string(content, "jq:.offers.price") + assert text == "23.5" - text = html_tools.extract_json_as_string('{"id":5}', "json:$.id") - assert text == "5" + text = html_tools.extract_json_as_string('{"id":5}', "jq:.id") + assert text == "5" - text = html_tools.extract_json_as_string('{"id":5}', "jq:.id") + text = html_tools.extract_json_as_string('{"id":5}', "json:$.id") assert text == "5" # When nothing at all is found, it should throw JSONNOTFound @@ -54,8 +60,9 @@ and it can also be repeated with pytest.raises(html_tools.JSONNotFound) as e_info: html_tools.extract_json_as_string('COMPLETE GIBBERISH, NO JSON!', "json:$.id") - with pytest.raises(html_tools.JSONNotFound) as e_info: - html_tools.extract_json_as_string('COMPLETE GIBBERISH, NO JSON!', "jq:.id") + if jq_support: + with pytest.raises(html_tools.JSONNotFound) as e_info: + html_tools.extract_json_as_string('COMPLETE GIBBERISH, NO JSON!', "jq:.id") def set_original_ext_response(): data = """ @@ -271,7 +278,8 @@ def test_check_jsonpath_filter(client, live_server): check_json_filter('json:boss.name', client, live_server) def test_check_jq_filter(client, live_server): - check_json_filter('jq:.boss.name', client, live_server) + if jq_support: + check_json_filter('jq:.boss.name', client, live_server) def check_json_filter_bool_val(json_filter, client, live_server): set_original_response() @@ -329,7 +337,8 @@ def test_check_jsonpath_filter_bool_val(client, live_server): check_json_filter_bool_val("json:$['available']", client, live_server) def test_check_jq_filter_bool_val(client, live_server): - check_json_filter_bool_val("jq:.available", client, live_server) + if jq_support: + check_json_filter_bool_val("jq:.available", client, live_server) # Re #265 - Extended JSON selector test # Stuff to consider here @@ -408,4 +417,5 @@ def test_check_jsonpath_ext_filter(client, live_server): check_json_ext_filter('json:$[?(@.status==Sold)]', client, live_server) def test_check_jq_ext_filter(client, live_server): - check_json_ext_filter('jq:.[] | select(.status | contains("Sold"))', client, live_server) \ No newline at end of file + if jq_support: + check_json_ext_filter('jq:.[] | select(.status | contains("Sold"))', client, live_server) \ No newline at end of file