1
# Copyright (C) 2013 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 MailingLists and related model objects.."""
20
from __future__ import absolute_import, print_function, unicode_literals
25
'TestDisabledListArchiver',
31
from mailman.app.lifecycle import create_list
32
from mailman.config import config
33
from mailman.interfaces.mailinglist import IListArchiverSet
34
from mailman.testing.helpers import configuration
35
from mailman.testing.layers import ConfigLayer
39
class TestListArchiver(unittest.TestCase):
43
self._mlist = create_list('ant@example.com')
44
self._set = IListArchiverSet(self._mlist)
46
def test_list_archivers(self):
47
# Find the set of archivers registered for this mailing list.
49
['mail-archive', 'mhonarc', 'prototype'],
50
sorted(archiver.name for archiver in self._set.archivers))
52
def test_get_archiver(self):
53
# Use .get() to see if a mailing list has an archiver.
54
archiver = self._set.get('prototype')
55
self.assertEqual(archiver.name, 'prototype')
56
self.assertTrue(archiver.is_enabled)
57
self.assertEqual(archiver.mailing_list, self._mlist)
58
self.assertEqual(archiver.system_archiver.name, 'prototype')
60
def test_get_archiver_no_such(self):
61
# Using .get() on a non-existing name returns None.
62
self.assertIsNone(self._set.get('no-such-archiver'))
64
def test_site_disabled(self):
65
# Here the system configuration enables all the archivers in time for
66
# the archive set to be created with all list archivers enabled. But
67
# then the site-wide archiver gets disabled, so the list specific
68
# archiver will also be disabled.
69
archiver_set = IListArchiverSet(self._mlist)
70
archiver = archiver_set.get('prototype')
71
self.assertTrue(archiver.is_enabled)
72
# Disable the site-wide archiver.
73
config.push('enable prototype', """\
77
self.assertFalse(archiver.is_enabled)
78
config.pop('enable prototype')
82
class TestDisabledListArchiver(unittest.TestCase):
86
self._mlist = create_list('ant@example.com')
88
@configuration('archiver.prototype', enable='no')
89
def test_enable_list_archiver(self):
90
# When the system configuration file disables an archiver site-wide,
91
# the list-specific mailing list will get initialized as not enabled.
92
# Create the archiver set on the fly so that it doesn't get
93
# initialized with a configuration that enables the prototype archiver.
94
archiver_set = IListArchiverSet(self._mlist)
95
archiver = archiver_set.get('prototype')
96
self.assertFalse(archiver.is_enabled)
97
# Enable both the list archiver and the system archiver.
98
archiver.is_enabled = True
99
config.push('enable prototype', """\
103
# Get the IListArchiver again.
104
archiver = archiver_set.get('prototype')
105
self.assertTrue(archiver.is_enabled)
106
config.pop('enable prototype')