This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
The following commit(s) were added to refs/heads/master by this push:
new b32654c Add a few basic search tests
b32654c is described below
commit b32654c06856b090828c3bbfb637f0ab5eb55464
Author: Sebb <[email protected]>
AuthorDate: Mon Dec 27 16:46:41 2021 +0000
Add a few basic search tests
---
test/test_defuzzer.py | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/test/test_defuzzer.py b/test/test_defuzzer.py
index 734a86d..6cf4d65 100644
--- a/test/test_defuzzer.py
+++ b/test/test_defuzzer.py
@@ -34,3 +34,40 @@ def test_defuzzer_1():
with pytest.raises(ValueError) as excinfo:
defuzz({'list': '@', 'domain': 'invalid'})
assert 'cannot contain @' in str(excinfo.value)
+
+def test_defuzzer_2():
+ df = defuzz({'list': 'dev', 'domain': 'ponymail.apache.org', 'q': ''})
+ assert 1 == len(df)
+ assert 'must' in df
+ dfm = df['must']
+ assert 2 == len(dfm)
+ assert "{'term': {'list_raw': '<dev.ponymail.apache.org>'}}" == str(dfm[0])
+ assert "{'range': {'date': {'gt': 'now-30d', 'lt': 'now+1d'}}}" ==
str(dfm[1])
+
+def test_defuzzer_3():
+ df = defuzz({'list': 'dev', 'domain': 'ponymail.apache.org', 'q': 'a -b
--c'})
+ assert 2 == len(df)
+ assert 'must' in df
+ assert 'must_not' in df
+
+ dfm = df['must']
+ assert 3 == len(dfm)
+ assert "{'term': {'list_raw': '<dev.ponymail.apache.org>'}}" == str(dfm[0])
+ assert "{'range': {'date': {'gt': 'now-30d', 'lt': 'now+1d'}}}" ==
str(dfm[1])
+
+ dfb = dfm[2]
+
+ assert 1 == len(dfb)
+ assert 'bool' in dfb
+ dfbb = dfb['bool']
+ assert 2 == dfbb['minimum_should_match'] # two shoulds
+
+ dfbs = dfbb['should']
+ assert 2 == len(dfbs)
+
+ assert "{'bool': {'should': [{'multi_match': {'fields': ['from', 'body',
'subject'], 'query': 'a', 'type': 'phrase'}}]}}" == str(dfbs[0])
+ assert "{'bool': {'should': [{'multi_match': {'fields': ['from', 'body',
'subject'], 'query': '-c', 'type': 'phrase'}}]}}" == str(dfbs[1])
+
+ dfn = df['must_not']
+
+ assert "[{'match': {'subject': 'b'}}, {'match': {'from': 'b'}}, {'match':
{'body': 'b'}}]" == str(dfn)
\ No newline at end of file