mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
Increase coverage
This commit is contained in:
@@ -84,35 +84,35 @@ class FilterSerializer(serializers.Serializer):
|
||||
"conditions": [],
|
||||
"actions": [],
|
||||
}
|
||||
for t in test["test"]["tests"]:
|
||||
if isinstance(t, commands.TrueCommand):
|
||||
item["match_type"] = "all"
|
||||
item["conditions"] += [
|
||||
{"name": "Subject", "operator": "contains", "value": ""}
|
||||
]
|
||||
break
|
||||
elif isinstance(t, commands.SizeCommand):
|
||||
item["conditions"] += [
|
||||
{
|
||||
"name": "size",
|
||||
"operator": t["comparator"][1:],
|
||||
"value": t["limit"],
|
||||
}
|
||||
]
|
||||
else:
|
||||
operator_prefix = ""
|
||||
if isinstance(t, commands.NotCommand):
|
||||
t = t["test"]
|
||||
operator_prefix = "not"
|
||||
item["conditions"] += [
|
||||
{
|
||||
"name": t["header-names"].strip('"'),
|
||||
"operator": "{}{}".format(
|
||||
operator_prefix, t["match-type"][1:]
|
||||
),
|
||||
"value": t["key-list"].strip('"'),
|
||||
}
|
||||
]
|
||||
if isinstance(test["test"], commands.TrueCommand):
|
||||
item["match_type"] = "all"
|
||||
item["conditions"] += [
|
||||
{"name": "Subject", "operator": "contains", "value": ""}
|
||||
]
|
||||
else:
|
||||
for t in test["test"]["tests"]:
|
||||
if isinstance(t, commands.SizeCommand):
|
||||
item["conditions"] += [
|
||||
{
|
||||
"name": "size",
|
||||
"operator": t["comparator"][1:],
|
||||
"value": t["limit"],
|
||||
}
|
||||
]
|
||||
else:
|
||||
operator_prefix = ""
|
||||
if isinstance(t, commands.NotCommand):
|
||||
t = t["test"]
|
||||
operator_prefix = "not"
|
||||
item["conditions"] += [
|
||||
{
|
||||
"name": t["header-names"].strip('"'),
|
||||
"operator": "{}{}".format(
|
||||
operator_prefix, t["match-type"][1:]
|
||||
),
|
||||
"value": t["key-list"].strip('"'),
|
||||
}
|
||||
]
|
||||
for c in test.children:
|
||||
action = {"name": c.name, "args": {}}
|
||||
tpl = lib.find_action_template(c.name)
|
||||
|
||||
@@ -120,7 +120,7 @@ class FilterSetViewSetTestCase(ModoAPITestCase):
|
||||
url = reverse("v2:filterset-get-filters", args=["main_script"])
|
||||
resp = self.client.get(url)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertEqual(len(resp.json()), 2)
|
||||
self.assertEqual(len(resp.json()), 5)
|
||||
|
||||
def test_add_filter(self):
|
||||
self.authenticate()
|
||||
|
||||
@@ -57,21 +57,6 @@ class SieveClient:
|
||||
self.msc.logout()
|
||||
self.msc = None
|
||||
|
||||
def refresh(self, user: str, password: str):
|
||||
if self.msc is not None:
|
||||
try:
|
||||
self.msc.capability()
|
||||
except managesieve.Error:
|
||||
pass
|
||||
else:
|
||||
return
|
||||
try:
|
||||
ret, msg = self.login(user, password)
|
||||
except (managesieve.Error, ssl.SSLError) as e:
|
||||
raise ConnectionError(e)
|
||||
if not ret:
|
||||
raise ConnectionError(msg)
|
||||
|
||||
def listscripts(self):
|
||||
return self.msc.listscripts()
|
||||
|
||||
|
||||
@@ -14,6 +14,21 @@ if anyof (header :contains "To" "test1") {
|
||||
if anyof (header :contains "To" "test2") {
|
||||
fileinto "Test2";
|
||||
}
|
||||
|
||||
# Filter: test3
|
||||
if anyof (size :over 100k) {
|
||||
fileinto "Test3";
|
||||
}
|
||||
|
||||
# Filter: test4
|
||||
if anyof (not header :contains "Sender" "toto@toto.com") {
|
||||
fileinto "Toto";
|
||||
}
|
||||
|
||||
# Filter: test5
|
||||
if true {
|
||||
fileinto "All";
|
||||
}
|
||||
"""
|
||||
|
||||
SAMPLE_SIEVE_SCRIPT2 = """require ["fileinto"];
|
||||
|
||||
Reference in New Issue
Block a user