Skip to content

Commit

Permalink
Add "all" model
Browse files Browse the repository at this point in the history
  • Loading branch information
4c0n committed Aug 29, 2024
1 parent 9c7bf81 commit 2a67dc9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pydantic_jsonlogic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,12 @@ class Reduce(BaseJSONLogicOperation):
# The initial accumulator value
Any,
]


class All(BaseJSONLogicOperation):
all: tuple[
# An array or an operation that produces an array
list[Any] | Var | Missing | MissingSome | If | Merge | Filter | Map,
# Something that produces a truthy or falsy result
bool | BaseJSONLogicOperation,
]
18 changes: 18 additions & 0 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from pydantic_jsonlogic import (
Add,
All,
And,
Cat,
Divide,
Expand Down Expand Up @@ -531,3 +532,20 @@ def test_map(json: str) -> None:
)
def test_reduce(json: str) -> None:
Reduce.model_validate_json(json)


@pytest.mark.parametrize(
"json",
[
'{"all":[{"var":"integers"}, {">=":[{"var":""}, 1]}]}',
'{"all":[{"var":"integers"}, {"==":[{"var":""}, 1]}]}',
'{"all":[{"var":"integers"}, {"<":[{"var":""}, 1]}]}',
'{"all":[ {"var":"items"}, {">=":[{"var":"qty"}, 1]}]}',
'{"all":[ {"var":"items"}, {">":[{"var":"qty"}, 1]}]}',
'{"all":[ {"var":"items"}, {"<":[{"var":"qty"}, 1]}]}',
'{"all":[ {"var":"items"}, {">=":[{"var":"qty"}, 1]}]}',
'{"all":[[0,1,3], true]}',
],
)
def test_all(json: str) -> None:
All.model_validate_json(json)

0 comments on commit 2a67dc9

Please sign in to comment.