summaryrefslogtreecommitdiff
path: root/src/mailman/tests/test_hook_deprecations.py
blob: 1e15e0d3ace5933106828117f936bc0769036055 (plain)
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
# Copyright (C) 2017 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 some plugin behavior."""

import unittest

from contextlib import ExitStack
from mailman.testing.documentation import run_mailman
from mailman.testing.layers import ConfigLayer
from tempfile import NamedTemporaryFile


class TestExternalHooks(unittest.TestCase):
    layer = ConfigLayer
    maxDiff = None

    def setUp(self):
        self.resources = ExitStack()
        self.addCleanup(self.resources.close)
        self.config_file = self.resources.enter_context(NamedTemporaryFile())

    def test_pre_hook_deprecated(self):
        with open(self.config_file.name, 'w', encoding='utf-8') as fp:
            print("""\
[mailman]
pre_hook: sys.exit

[logging.plugins]
propagate: yes
""", file=fp)
        proc = run_mailman(['-C', self.config_file.name, 'info'])
        # We only care about the log warning printed to stdout.
        warning = proc.stdout.splitlines()[0]
        self.assertEqual(
            warning[-111:],
            'The [mailman]pre_hook configuration value has been replaced '
            "by the plugins infrastructure, and won't be called.")

    def test_post_hook_deprecated(self):
        with open(self.config_file.name, 'w', encoding='utf-8') as fp:
            print("""\
[mailman]
post_hook: sys.exit

[logging.plugins]
propagate: yes
""", file=fp)
        proc = run_mailman(['-C', self.config_file.name, 'info'])
        # We only care about the log warning printed to stdout.
        warning = proc.stdout.splitlines()[0]
        self.assertEqual(
            warning[-112:],
            'The [mailman]post_hook configuration value has been replaced '
            "by the plugins infrastructure, and won't be called.")