~sumanah/mailman/mailman

« back to all changes in this revision

Viewing changes to src/mailman/handlers/tests/test_filter.py

  • Committer: Sumana Harihareswara
  • Date: 2015-01-08 21:35:58 UTC
  • mfrom: (7273.2.15 3.0)
  • Revision ID: sumanah@panix.com-20150108213558-65ym6553zj256z8p
mergeĀ fromĀ master

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2014-2015 by the Free Software Foundation, Inc.
 
2
#
 
3
# This file is part of GNU Mailman.
 
4
#
 
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
 
6
# the terms of the GNU General Public License as published by the Free
 
7
# Software Foundation, either version 3 of the License, or (at your option)
 
8
# any later version.
 
9
#
 
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
 
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
13
# more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License along with
 
16
# GNU Mailman.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
"""Test the filter handler."""
 
19
 
 
20
__all__ = [
 
21
    'TestFilters',
 
22
    ]
 
23
 
 
24
 
 
25
import unittest
 
26
 
 
27
from mailman.app.lifecycle import create_list
 
28
from mailman.config import config
 
29
from mailman.core.errors import DiscardMessage
 
30
from mailman.interfaces.mime import FilterAction
 
31
from mailman.testing.helpers import specialized_message_from_string as mfs
 
32
from mailman.testing.layers import ConfigLayer
 
33
 
 
34
 
 
35
 
 
36
class TestFilters(unittest.TestCase):
 
37
    layer = ConfigLayer
 
38
 
 
39
    def setUp(self):
 
40
        self._mlist = create_list('test@example.com')
 
41
 
 
42
    def test_discard_when_outer_type_matches(self):
 
43
        # When the outer MIME type of the message matches a filter type, the
 
44
        # entire message is discarded.
 
45
        self._mlist.filter_content = True
 
46
        self._mlist.filter_types = ['image/jpeg']
 
47
        self._mlist.filter_action = FilterAction.discard
 
48
        msg = mfs("""\
 
49
From: aperson@example.com
 
50
Content-Type: image/jpeg
 
51
MIME-Version: 1.0
 
52
 
 
53
xxxxx
 
54
""")
 
55
        self.assertRaises(DiscardMessage,
 
56
                          config.handlers['mime-delete'].process,
 
57
                          self._mlist, msg, {})