Skip to content

Commit

Permalink
Merge pull request #94 from koterpillar/jsonpath
Browse files Browse the repository at this point in the history
Use jsonpath_ng.ext for filters
  • Loading branch information
koterpillar committed Nov 16, 2023
2 parents ed6c058 + 9e696c3 commit ccc1898
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mybox/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import requests
from bs4 import BeautifulSoup
from jsonpath_ng import JSONPath as JSONPathT # type: ignore
from jsonpath_ng import parse as jsonpath_parse # type: ignore
from jsonpath_ng.ext import parse as jsonpath_parse # type: ignore
from pydantic import BaseModel, validator

from .filters import Filters, choose
Expand Down
19 changes: 19 additions & 0 deletions tests/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ async def test_jsonpath():
assert (await value.compute()) == "aaaa"


@pytest.mark.trio
async def test_jsonpath_filter():
value = Value.parse(
{
"base": json.dumps(
{
"foo": [
{"bar": "aaaa", "result": "one"},
{"bar": "bbbb", "result": "two"},
]
}
),
"jsonpath": "$.foo[?(@.bar=='aaaa')].result",
}
)

assert (await value.compute()) == "one"


@pytest.mark.trio
async def test_url():
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
Expand Down

0 comments on commit ccc1898

Please sign in to comment.