mail4one/tests/test_config.py

79 lines
1.6 KiB
Python
Raw Normal View History

2023-06-11 19:49:41 -04:00
import unittest
2023-06-13 21:12:46 -04:00
from mail4one import config
2023-06-11 19:49:41 -04:00
TEST_CONFIG = """
{
"mails_path": "/var/tmp/mails",
"matches": [
{
"name": "mydomain",
"addr_rexs": [
".*@mydomain.com",
".*@m.mydomain.com"
]
},
{
"name": "personal",
"addrs": [
"first.last@mydomain.com",
"secret.name@mydomain.com"
]
}
],
"boxes": [
{
"name": "spam",
"rules": [
{
"match_name": "mydomain",
"negate": true,
"stop_check": true
}
]
},
{
"name": "important",
"rules": [
{
"match_name": "personal"
}
]
},
{
"name": "all",
"rules": [
{
"match_name": "default_match_all"
}
]
}
]
}
"""
class TestConfig(unittest.TestCase):
def test_config(self) -> None:
cfg = config.Config(TEST_CONFIG)
self.assertEqual(cfg.mails_path, "/var/tmp/mails")
def test_parse_rules(self) -> None:
cfg = config.Config(TEST_CONFIG)
2023-06-11 20:14:50 -04:00
op = config.parse_checkers(cfg)
2023-06-11 19:49:41 -04:00
self.assertEqual(len(op), 3)
def test_get_mboxes(self) -> None:
cfg = config.Config(TEST_CONFIG)
2023-06-11 20:14:50 -04:00
rules = config.parse_checkers(cfg)
2024-04-01 11:14:20 -04:00
self.assertEqual(config.get_mboxes("foo@bar.com", rules), ["spam"])
self.assertEqual(config.get_mboxes("foo@mydomain.com", rules), ["all"])
self.assertEqual(
config.get_mboxes("first.last@mydomain.com", rules), ["important", "all"]
)
2023-06-11 19:49:41 -04:00
if __name__ == "__main__":
unittest.main()