Increase coverage

This commit is contained in:
Antoine Nguyen
2024-07-17 09:20:08 +02:00
parent 6c0efd35bc
commit 33c99f1c98
4 changed files with 45 additions and 45 deletions
+29 -29
View File
@@ -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)
+1 -1
View File
@@ -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()
-15
View File
@@ -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()
+15
View File
@@ -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"];