Skip to content

Commit

Permalink
Added support for complete match on retract fact
Browse files Browse the repository at this point in the history
When retracting a fact we should be able to specify either
partial or complete facts. The default is partial since events
can be huge and it might not be practical to specify the whole
fact. But in some cases when the event is small they might want
to do a complete match, but exclude any system added keys like meta.
  • Loading branch information
mkanoor committed May 18, 2023
1 parent b4504cb commit e9e3ef6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "drools_jpy"
version = "0.3.1"
version = "0.3.2"
authors = [
{ name="Madhu Kanoor", email="author@example.com" },
]
Expand Down
Binary file not shown.
27 changes: 27 additions & 0 deletions tests/test_ruleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,33 @@ def test_retract_matching_facts():
assert len(response) == 0


def test_retract_matching_facts_complete():
test_data = load_ast("asts/retract_matching_facts.yml")

my_callback1 = mock.Mock()
my_callback2 = mock.Mock()
result = Matches(data={"m": {"meta": {"uuid": "934"}, "i": 67, "n": 239}})

ruleset_data = test_data[0]["RuleSet"]
rs = Ruleset(
name=ruleset_data["name"], serialized_ruleset=json.dumps(ruleset_data)
)
rs.add_rule(Rule("r1", my_callback1))
rs.add_rule(Rule("r2", my_callback2))

rs.assert_fact(json.dumps(dict(i=67, n=239, meta=dict(uuid="934"))))
rs.assert_fact(json.dumps(dict(j=42)))
assert not my_callback1.called

assert (len(rs.get_facts())) == 1
rs.retract_matching_facts(json.dumps(dict(i=67, n=239)), True, ["meta"])

my_callback2.assert_called_with(result)
response = rs.get_facts()
rs.end_session()
assert len(response) == 0


def test_get_facts():
test_data = load_ast("asts/assert_fact.yml")

Expand Down

0 comments on commit e9e3ef6

Please sign in to comment.