-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from tonioo/feature/unique_filtername_in_filt…
…erset Ensure name uniqueness in filter set
- Loading branch information
Showing
2 changed files
with
185 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import unittest | ||
import io | ||
|
||
from sievelib.factory import FiltersSet | ||
from sievelib.factory import FilterAlreadyExists, FiltersSet | ||
from .. import parser | ||
|
||
|
||
|
@@ -10,6 +10,119 @@ class FactoryTestCase(unittest.TestCase): | |
def setUp(self): | ||
self.fs = FiltersSet("test") | ||
|
||
def test_add_duplicate_filter(self): | ||
"""Try to add the same filter name twice, should fail.""" | ||
self.fs.addfilter( | ||
"ruleX", | ||
[ | ||
("Sender", ":is", "[email protected]"), | ||
], | ||
[ | ||
("fileinto", ":copy", "Toto"), | ||
], | ||
) | ||
with self.assertRaises(FilterAlreadyExists): | ||
self.fs.addfilter( | ||
"ruleX", | ||
[ | ||
("Sender", ":is", "[email protected]"), | ||
], | ||
[ | ||
("fileinto", ":copy", "Toto"), | ||
], | ||
) | ||
|
||
def test_updatefilter(self): | ||
self.fs.addfilter( | ||
"ruleX", | ||
[ | ||
("Sender", ":is", "[email protected]"), | ||
], | ||
[ | ||
("fileinto", ":copy", "Toto"), | ||
], | ||
) | ||
result = self.fs.updatefilter( | ||
"ruleY", | ||
"ruleX", | ||
[ | ||
("Sender", ":is", "[email protected]"), | ||
], | ||
[ | ||
("fileinto", ":copy", "Tata"), | ||
], | ||
) | ||
self.assertFalse(result) | ||
result = self.fs.updatefilter( | ||
"ruleX", | ||
"ruleY", | ||
[ | ||
("Sender", ":is", "[email protected]"), | ||
], | ||
[ | ||
("fileinto", ":copy", "Tata"), | ||
], | ||
) | ||
self.assertTrue(result) | ||
self.assertIs(self.fs.getfilter("ruleX"), None) | ||
self.assertIsNot(self.fs.getfilter("ruleY"), None) | ||
|
||
def test_updatefilter_duplicate(self): | ||
self.fs.addfilter( | ||
"ruleX", | ||
[ | ||
("Sender", ":is", "[email protected]"), | ||
], | ||
[ | ||
("fileinto", ":copy", "Toto"), | ||
], | ||
) | ||
self.fs.addfilter( | ||
"ruleY", | ||
[ | ||
("Sender", ":is", "[email protected]"), | ||
], | ||
[ | ||
("fileinto", ":copy", "Tota"), | ||
], | ||
) | ||
with self.assertRaises(FilterAlreadyExists): | ||
self.fs.updatefilter( | ||
"ruleX", | ||
"ruleY", | ||
[ | ||
("Sender", ":is", "[email protected]"), | ||
], | ||
[ | ||
("fileinto", ":copy", "Toti"), | ||
], | ||
) | ||
|
||
def test_replacefilter(self): | ||
self.fs.addfilter( | ||
"ruleX", | ||
[ | ||
("Sender", ":is", "[email protected]"), | ||
], | ||
[ | ||
("fileinto", ":copy", "Toto"), | ||
], | ||
) | ||
self.fs.addfilter( | ||
"ruleY", | ||
[ | ||
("Sender", ":is", "[email protected]"), | ||
], | ||
[ | ||
("fileinto", ":copy", "Tota"), | ||
], | ||
) | ||
content = self.fs.getfilter("ruleX") | ||
result = self.fs.replacefilter("ruleZ", content) | ||
self.assertFalse(result) | ||
result = self.fs.replacefilter("ruleY", content) | ||
self.assertTrue(result) | ||
|
||
def test_get_filter_conditions(self): | ||
"""Test get_filter_conditions method.""" | ||
orig_conditions = [("Sender", ":is", "[email protected]")] | ||
|