~abompard/mailman/fix-import-from-mm2

« back to all changes in this revision

Viewing changes to src/mailman/commands/tests/test_lists.py

  • Committer: Barry Warsaw
  • Date: 2015-03-14 01:16:51 UTC
  • mfrom: (7210.2.1 mailman)
  • Revision ID: barry@list.org-20150314011651-pkb1kij8xp4l2eks
 * ``mailman lists --domain`` was not properly handling its arguments.  Given
   by Manish Gill.  (LP: #1166911)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 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
"""Additional tests for the `lists` command line subcommand."""
 
19
 
 
20
__all__ = [
 
21
    'TestLists',
 
22
    ]
 
23
 
 
24
 
 
25
import unittest
 
26
 
 
27
from io import StringIO
 
28
from mailman.app.lifecycle import create_list
 
29
from mailman.commands.cli_lists import Lists
 
30
from mailman.interfaces.domain import IDomainManager
 
31
from mailman.testing.layers import ConfigLayer
 
32
from unittest.mock import patch
 
33
from zope.component import getUtility
 
34
 
 
35
 
 
36
class FakeArgs:
 
37
    advertised = False
 
38
    names = False
 
39
    descriptions = False
 
40
    quiet = False
 
41
    domain = []
 
42
 
 
43
 
 
44
class TestLists(unittest.TestCase):
 
45
    layer = ConfigLayer
 
46
 
 
47
    def test_lists_with_domain_option(self):
 
48
        # LP: #1166911 - non-matching lists were returned.
 
49
        getUtility(IDomainManager).add(
 
50
            'example.net', 'An example domain.',
 
51
            'http://lists.example.net', 'postmaster@example.net')
 
52
        create_list('test1@example.com')
 
53
        create_list('test2@example.com')
 
54
        # Only this one should show up.
 
55
        create_list('test3@example.net')
 
56
        create_list('test4@example.com')
 
57
        command = Lists()
 
58
        args = FakeArgs()
 
59
        args.domain.append('example.net')
 
60
        output = StringIO()
 
61
        with patch('sys.stdout', output):
 
62
            command.process(args)
 
63
        lines = output.getvalue().splitlines()
 
64
        # The first line is the heading, so skip that.
 
65
        lines.pop(0)
 
66
        self.assertEqual(len(lines), 1, lines)
 
67
        self.assertEqual(lines[0], 'test3@example.net')