summaryrefslogtreecommitdiff
path: root/src/mailman/handlers/tests
diff options
context:
space:
mode:
authorBarry Warsaw2014-12-15 17:29:02 -0500
committerBarry Warsaw2014-12-15 17:29:02 -0500
commit130bd8179188fbbcf488ab668baae4fe945bcfc2 (patch)
treef93e4e5f9afdc602d205650fcf3c08e0ca780359 /src/mailman/handlers/tests
parente3b97fadcf345604c9760113ddf06505a2f3b95c (diff)
downloadmailman-130bd8179188fbbcf488ab668baae4fe945bcfc2.tar.gz
mailman-130bd8179188fbbcf488ab668baae4fe945bcfc2.tar.zst
mailman-130bd8179188fbbcf488ab668baae4fe945bcfc2.zip
Better, but not perfect handler test passing.
Diffstat (limited to 'src/mailman/handlers/tests')
-rw-r--r--src/mailman/handlers/tests/test_file_recips.py76
-rw-r--r--src/mailman/handlers/tests/test_filter.py60
2 files changed, 136 insertions, 0 deletions
diff --git a/src/mailman/handlers/tests/test_file_recips.py b/src/mailman/handlers/tests/test_file_recips.py
new file mode 100644
index 000000000..9f3e0ec6e
--- /dev/null
+++ b/src/mailman/handlers/tests/test_file_recips.py
@@ -0,0 +1,76 @@
+# Copyright (C) 2014 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Test file-recips handler."""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'TestFileRecips',
+ ]
+
+
+import os
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.config import config
+from mailman.testing.helpers import specialized_message_from_string as mfs
+from mailman.testing.layers import ConfigLayer
+
+
+
+class TestFileRecips(unittest.TestCase):
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+ self._handler = config.handlers['file-recipients'].process
+ self._msg = mfs("""\
+From: aperson@example.com
+
+A message.
+""")
+
+ def test_file_is_missing(self):
+ # It is not an error for the list's the members.txt file to be
+ # missing. The missing file is just ignored.
+ msgdata = {}
+ self._handler(self._mlist, self._msg, msgdata)
+ self.assertEqual(msgdata['recipients'], set())
+
+ def test_file_exists(self):
+ # Like above, but the file exists and contains recipients.
+ path = os.path.join(self._mlist.data_path, 'members.txt')
+ with open(path, 'w', encoding='utf-8') as fp:
+ print('bperson@example.com', file=fp)
+ print('cperson@example.com', file=fp)
+ print('dperson@example.com', file=fp)
+ print('eperson@example.com', file=fp)
+ print('fperson@example.com', file=fp)
+ print('gperson@example.com', file=fp)
+ msgdata = {}
+ self._handler(self._mlist, self._msg, msgdata)
+ self.assertEqual(msgdata['recipients'], set((
+ 'bperson@example.com',
+ 'cperson@example.com',
+ 'dperson@example.com',
+ 'eperson@example.com',
+ 'fperson@example.com',
+ 'gperson@example.com',
+ )))
diff --git a/src/mailman/handlers/tests/test_filter.py b/src/mailman/handlers/tests/test_filter.py
new file mode 100644
index 000000000..292e646cd
--- /dev/null
+++ b/src/mailman/handlers/tests/test_filter.py
@@ -0,0 +1,60 @@
+# Copyright (C) 2014 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Test the filter handler."""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'TestFilters',
+ ]
+
+
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.config import config
+from mailman.core.errors import DiscardMessage
+from mailman.interfaces.mime import FilterAction
+from mailman.testing.helpers import specialized_message_from_string as mfs
+from mailman.testing.layers import ConfigLayer
+
+
+
+class TestFilters(unittest.TestCase):
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+
+ def test_discard_when_outer_type_matches(self):
+ # When the outer MIME type of the message matches a filter type, the
+ # entire message is discarded.
+ self._mlist.filter_content = True
+ self._mlist.filter_types = ['image/jpeg']
+ self._mlist.filter_action = FilterAction.discard
+ msg = mfs("""\
+From: aperson@example.com
+Content-Type: image/jpeg
+MIME-Version: 1.0
+
+xxxxx
+""")
+ self.assertRaises(DiscardMessage,
+ config.handlers['mime-delete'].process,
+ self._mlist, msg, {})