/usr/lib/python3/dist-packages/sievelib/tests/test_factory.py is in python3-sievelib 1.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | # coding: utf-8
from __future__ import unicode_literals
import unittest
import six
from sievelib.factory import FiltersSet
class FactoryTestCase(unittest.TestCase):
def setUp(self):
self.fs = FiltersSet("test")
def test_add_header_filter(self):
output = six.StringIO()
self.fs.addfilter(
"rule1",
[('Sender', ":is", 'toto@toto.com'), ],
[("fileinto", ":copy", "Toto"), ])
self.assertIsNot(self.fs.getfilter("rule1"), None)
self.fs.tosieve(output)
self.assertEqual(output.getvalue(), """require ["fileinto", "copy"];
# Filter: rule1
if anyof (header :is "Sender" "toto@toto.com") {
fileinto :copy "Toto";
}
""")
output.close()
def test_use_action_with_tag(self):
output = six.StringIO()
self.fs.addfilter(
"rule1",
[('Sender', ":is", 'toto@toto.com'), ],
[("redirect", ":copy", "toto@titi.com"), ])
self.assertIsNot(self.fs.getfilter("rule1"), None)
self.fs.tosieve(output)
self.assertEqual(output.getvalue(), """require ["copy"];
# Filter: rule1
if anyof (header :is "Sender" "toto@toto.com") {
redirect :copy "toto@titi.com";
}
""")
output.close()
def test_add_header_filter_with_not(self):
output = six.StringIO()
self.fs.addfilter(
"rule1",
[('Sender', ":notcontains", 'toto@toto.com')],
[("fileinto", 'Toto')])
self.assertIsNot(self.fs.getfilter("rule1"), None)
self.fs.tosieve(output)
self.assertEqual(output.getvalue(), """require ["fileinto"];
# Filter: rule1
if anyof (not header :contains "Sender" "toto@toto.com") {
fileinto "Toto";
}
""")
def test_add_exists_filter(self):
output = six.StringIO()
self.fs.addfilter(
"rule1",
[('exists', "list-help", "list-unsubscribe",
"list-subscribe", "list-owner")],
[("fileinto", 'Toto')]
)
self.assertIsNot(self.fs.getfilter("rule1"), None)
self.fs.tosieve(output)
self.assertEqual(output.getvalue(), """require ["fileinto"];
# Filter: rule1
if anyof (exists ["list-help","list-unsubscribe","list-subscribe","list-owner"]) {
fileinto "Toto";
}
""")
def test_add_exists_filter_with_not(self):
output = six.StringIO()
self.fs.addfilter(
"rule1",
[('notexists', "list-help", "list-unsubscribe",
"list-subscribe", "list-owner")],
[("fileinto", 'Toto')]
)
self.assertIsNot(self.fs.getfilter("rule1"), None)
self.fs.tosieve(output)
self.assertEqual(output.getvalue(), """require ["fileinto"];
# Filter: rule1
if anyof (not exists ["list-help","list-unsubscribe","list-subscribe","list-owner"]) {
fileinto "Toto";
}
""")
def test_add_size_filter(self):
output = six.StringIO()
self.fs.addfilter(
"rule1",
[('size', ":over", "100k")],
[("fileinto", 'Totoéé')]
)
self.assertIsNot(self.fs.getfilter("rule1"), None)
self.fs.tosieve(output)
self.assertEqual(output.getvalue(), """require ["fileinto"];
# Filter: rule1
if anyof (size :over 100k) {
fileinto "Totoéé";
}
""")
def test_remove_filter(self):
self.fs.addfilter("rule1",
[('Sender', ":is", 'toto@toto.com')],
[("fileinto", 'Toto')])
self.assertIsNot(self.fs.getfilter("rule1"), None)
self.assertEqual(self.fs.removefilter("rule1"), True)
self.assertIs(self.fs.getfilter("rule1"), None)
def test_disablefilter(self):
"""
FIXME: Extra spaces are written between if and anyof, why?!
"""
self.fs.addfilter("rule1",
[('Sender', ":is", 'toto@toto.com')],
[("fileinto", 'Toto')])
self.assertIsNot(self.fs.getfilter("rule1"), None)
self.assertEqual(self.fs.disablefilter("rule1"), True)
output = six.StringIO()
self.fs.tosieve(output)
self.assertEqual(output.getvalue(), """require ["fileinto"];
# Filter: rule1
if false {
if anyof (header :is "Sender" "toto@toto.com") {
fileinto "Toto";
}
}
""")
output.close()
self.assertEqual(self.fs.is_filter_disabled("rule1"), True)
def test_add_filter_unicode(self):
"""Add a filter containing unicode data."""
name = u"Test\xe9".encode("utf-8")
self.fs.addfilter(
name,
[('Sender', ":is", 'toto@toto.com'), ],
[("fileinto", 'Toto'), ])
self.assertIsNot(self.fs.getfilter("Testé"), None)
self.assertEqual("{}".format(self.fs), """require ["fileinto"];
# Filter: Testé
if anyof (header :is "Sender" "toto@toto.com") {
fileinto "Toto";
}
""")
if __name__ == "__main__":
unittest.main()
|