1
# Copyright (C) 2014 by the Free Software Foundation, Inc.
3
# This file is part of GNU Mailman.
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)
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
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/>.
18
"""Test the base chain stuff."""
20
from __future__ import absolute_import, print_function, unicode_literals
30
from mailman.chains.accept import AcceptChain
31
from mailman.chains.base import Chain, Link
32
from mailman.interfaces.chain import LinkAction
33
from mailman.rules.any import Any
37
class TestMiscellaneous(unittest.TestCase):
38
"""Reach additional code coverage."""
40
def test_link_repr(self):
42
repr(Link(Any)), '<Link "if any then LinkAction.defer">')
44
def test_link_repr_function(self):
48
repr(Link(Any, function=function)),
49
'<Link "if any then LinkAction.defer" function()>')
51
def test_link_repr_chain(self):
53
repr(Link(Any, chain=AcceptChain)),
54
'<Link "if any then LinkAction.defer" accept>')
56
def test_link_repr_chain_and_function(self):
60
repr(Link(Any, chain=AcceptChain, function=function)),
61
'<Link "if any then LinkAction.defer" accept function()>')
63
def test_link_repr_chain_all(self):
67
repr(Link(Any, LinkAction.stop, AcceptChain, function)),
68
'<Link "if any then LinkAction.stop" accept function()>')
71
# Test that we can flush the links of a chain.
72
chain = Chain('test', 'just a testing chain')
73
chain.append_link(Link(Any))
74
# Iterate over the links of the chain to prove there are some.
75
count = sum(1 for link in chain.get_iterator())
76
self.assertEqual(count, 1)
77
# Flush the chain; then there will be no links.
79
count = sum(1 for link in chain.get_iterator())
80
self.assertEqual(count, 0)