~varun/mailman/mailman

« back to all changes in this revision

Viewing changes to src/mailman/model/tests/test_mailinglist.py

  • Committer: Barry Warsaw
  • Date: 2013-11-27 20:13:10 UTC
  • mfrom: (7226.1.5 joanna)
  • Revision ID: barry@list.org-20131127201310-0wtguu3t140yedbr
Merge branch contributed by Joanna Skrzeszewska.

 * Mailing lists can now individually enable or disable any archiver available
   site-wide.  Contributed by Joanna Skrzeszewska.  (LP: #1158040)

Also:

 - IArchivers (i.e. system-wide archivers) now have an is_enabled attribute.
 - config.archivers now returns *all* archivers, including those that are
   disabled site-wide.  This way, iterating over the list-specific archivers
   returns everything.
 - In the ini-file schema, make the default archiver class empty, otherwise
   the Prototype archiver is always enabled.
 - Added a `listarchiver` table to support list-specific archivers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2013 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 MailingLists and related model objects.."""
 
19
 
 
20
from __future__ import absolute_import, print_function, unicode_literals
 
21
 
 
22
__metaclass__ = type
 
23
__all__ = [
 
24
    'TestListArchiver',
 
25
    'TestDisabledListArchiver',
 
26
    ]
 
27
 
 
28
 
 
29
import unittest
 
30
 
 
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
 
36
 
 
37
 
 
38
 
 
39
class TestListArchiver(unittest.TestCase):
 
40
    layer = ConfigLayer
 
41
 
 
42
    def setUp(self):
 
43
        self._mlist = create_list('ant@example.com')
 
44
        self._set = IListArchiverSet(self._mlist)
 
45
 
 
46
    def test_list_archivers(self):
 
47
        # Find the set of archivers registered for this mailing list.
 
48
        self.assertEqual(
 
49
            ['mail-archive', 'mhonarc', 'prototype'],
 
50
            sorted(archiver.name for archiver in self._set.archivers))
 
51
 
 
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')
 
59
 
 
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'))
 
63
 
 
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', """\
 
74
        [archiver.prototype]
 
75
        enable: no
 
76
        """)
 
77
        self.assertFalse(archiver.is_enabled)
 
78
        config.pop('enable prototype')
 
79
 
 
80
 
 
81
 
 
82
class TestDisabledListArchiver(unittest.TestCase):
 
83
    layer = ConfigLayer
 
84
 
 
85
    def setUp(self):
 
86
        self._mlist = create_list('ant@example.com')
 
87
 
 
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', """\
 
100
        [archiver.prototype]
 
101
        enable: yes
 
102
        """)
 
103
        # Get the IListArchiver again.
 
104
        archiver = archiver_set.get('prototype')
 
105
        self.assertTrue(archiver.is_enabled)
 
106
        config.pop('enable prototype')