test - only test for jq if jq installed, install jq and retest

pull/1009/head
dgtlmoon 2 years ago
parent 900cff87a7
commit 93f3bebe0f

@ -25,9 +25,9 @@ pytest tests/test_notification.py
## JQ + JSON: filter test ## JQ + JSON: filter test
# jq is not available on windows and we should just test it when the package is installed # 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 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 # Now for the selenium and playwright/browserless fetchers

@ -5,7 +5,12 @@ import time
from flask import url_for, escape from flask import url_for, escape
from . util import live_server_setup from . util import live_server_setup
import pytest import pytest
jq_support = True
try:
import jq
except ModuleNotFoundError:
jq_support = False
def test_setup(live_server): def test_setup(live_server):
live_server_setup(live_server) live_server_setup(live_server)
@ -40,13 +45,14 @@ and it can also be repeated
assert text == "23.5" assert text == "23.5"
# also check for jq # also check for jq
if jq_support:
text = html_tools.extract_json_as_string(content, "jq:.offers.price") text = html_tools.extract_json_as_string(content, "jq:.offers.price")
assert text == "23.5" assert text == "23.5"
text = html_tools.extract_json_as_string('{"id":5}', "json:$.id") text = html_tools.extract_json_as_string('{"id":5}', "jq:.id")
assert text == "5" 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" assert text == "5"
# When nothing at all is found, it should throw JSONNOTFound # When nothing at all is found, it should throw JSONNOTFound
@ -54,6 +60,7 @@ and it can also be repeated
with pytest.raises(html_tools.JSONNotFound) as e_info: with pytest.raises(html_tools.JSONNotFound) as e_info:
html_tools.extract_json_as_string('COMPLETE GIBBERISH, NO JSON!', "json:$.id") html_tools.extract_json_as_string('COMPLETE GIBBERISH, NO JSON!', "json:$.id")
if jq_support:
with pytest.raises(html_tools.JSONNotFound) as e_info: with pytest.raises(html_tools.JSONNotFound) as e_info:
html_tools.extract_json_as_string('COMPLETE GIBBERISH, NO JSON!', "jq:.id") html_tools.extract_json_as_string('COMPLETE GIBBERISH, NO JSON!', "jq:.id")
@ -271,6 +278,7 @@ def test_check_jsonpath_filter(client, live_server):
check_json_filter('json:boss.name', client, live_server) check_json_filter('json:boss.name', client, live_server)
def test_check_jq_filter(client, live_server): def test_check_jq_filter(client, live_server):
if jq_support:
check_json_filter('jq:.boss.name', client, live_server) check_json_filter('jq:.boss.name', client, live_server)
def check_json_filter_bool_val(json_filter, client, live_server): def check_json_filter_bool_val(json_filter, client, live_server):
@ -329,6 +337,7 @@ def test_check_jsonpath_filter_bool_val(client, live_server):
check_json_filter_bool_val("json:$['available']", client, live_server) check_json_filter_bool_val("json:$['available']", client, live_server)
def test_check_jq_filter_bool_val(client, live_server): def test_check_jq_filter_bool_val(client, live_server):
if jq_support:
check_json_filter_bool_val("jq:.available", client, live_server) check_json_filter_bool_val("jq:.available", client, live_server)
# Re #265 - Extended JSON selector test # Re #265 - Extended JSON selector test
@ -408,4 +417,5 @@ def test_check_jsonpath_ext_filter(client, live_server):
check_json_ext_filter('json:$[?(@.status==Sold)]', client, live_server) check_json_ext_filter('json:$[?(@.status==Sold)]', client, live_server)
def test_check_jq_ext_filter(client, live_server): def test_check_jq_ext_filter(client, live_server):
if jq_support:
check_json_ext_filter('jq:.[] | select(.status | contains("Sold"))', client, live_server) check_json_ext_filter('jq:.[] | select(.status | contains("Sold"))', client, live_server)
Loading…
Cancel
Save