test: cover build_filter (participant should-clause, date ranges, combination)
This commit is contained in:
1 parent
e32806aab9
commit
b9e22766c0
1 file changed
+53
@@ -8,6 +8,7 @@ from server import (
|
|||||||
normalize_email_address,
|
normalize_email_address,
|
||||||
payload_matches_participant,
|
payload_matches_participant,
|
||||||
format_search_result,
|
format_search_result,
|
||||||
|
build_filter,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -108,3 +109,55 @@ class TestFormatSearchResult:
|
|||||||
assert result["receiver"] is None
|
assert result["receiver"] is None
|
||||||
assert result["subject"] is None
|
assert result["subject"] is None
|
||||||
assert result["attachments"] == []
|
assert result["attachments"] == []
|
||||||
|
|
||||||
|
|
||||||
|
class TestBuildFilter:
|
||||||
|
def test_no_filters_returns_none(self):
|
||||||
|
assert build_filter(None, None, None) is None
|
||||||
|
|
||||||
|
def test_empty_strings_return_none(self):
|
||||||
|
assert build_filter("", "", "") is None
|
||||||
|
|
||||||
|
def test_participant_filter_is_should_clause_on_sender_and_receiver(self):
|
||||||
|
f = build_filter("alice@example.com", None, None)
|
||||||
|
assert f is not None
|
||||||
|
# The date conditions list must be absent and only the participant filter present
|
||||||
|
assert len(f.must) == 1
|
||||||
|
participant = f.must[0]
|
||||||
|
keys = [c.key for c in participant.should]
|
||||||
|
assert keys == ["sender", "receiver"]
|
||||||
|
assert all(c.match.value == "alice@example.com" for c in participant.should)
|
||||||
|
|
||||||
|
def test_participant_normalized_before_match(self):
|
||||||
|
f = build_filter("Alice <Alice@Example.COM>", None, None)
|
||||||
|
should = f.must[0].should
|
||||||
|
assert all(c.match.value == "alice@example.com" for c in should)
|
||||||
|
|
||||||
|
def test_date_range_only(self):
|
||||||
|
f = build_filter(None, "2026-01-01", "2026-06-30")
|
||||||
|
assert len(f.must) == 1
|
||||||
|
cond = f.must[0]
|
||||||
|
assert cond.key == "date"
|
||||||
|
assert cond.range.gte is not None
|
||||||
|
assert cond.range.lte is not None
|
||||||
|
|
||||||
|
def test_start_date_only(self):
|
||||||
|
f = build_filter(None, "2026-03-15", None)
|
||||||
|
cond = f.must[0]
|
||||||
|
assert cond.range.gte is not None
|
||||||
|
assert cond.range.lte is None
|
||||||
|
|
||||||
|
def test_end_date_only(self):
|
||||||
|
f = build_filter(None, None, "2026-03-15")
|
||||||
|
cond = f.must[0]
|
||||||
|
assert cond.range.gte is None
|
||||||
|
assert cond.range.lte is not None
|
||||||
|
|
||||||
|
def test_combined_participant_and_date(self):
|
||||||
|
f = build_filter("bob@example.org", "2026-01-01", "2026-12-31")
|
||||||
|
assert len(f.must) == 2
|
||||||
|
# One is the participant should-filter, the other the date range
|
||||||
|
kinds = sorted(
|
||||||
|
"participant" if getattr(c, "should", None) else "date" for c in f.must
|
||||||
|
)
|
||||||
|
assert kinds == ["date", "participant"]
|
||||||
Reference in new issue
Block a user