summaryrefslogtreecommitdiff
path: root/src/mailman/commands/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/commands/tests')
-rw-r--r--src/mailman/commands/tests/test_conf.py (renamed from src/mailman/commands/tests/test_mailmanconf.py)55
1 files changed, 40 insertions, 15 deletions
diff --git a/src/mailman/commands/tests/test_mailmanconf.py b/src/mailman/commands/tests/test_conf.py
index 4a3b5df9e..bca7fe72f 100644
--- a/src/mailman/commands/tests/test_mailmanconf.py
+++ b/src/mailman/commands/tests/test_conf.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2011-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2013 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
@@ -15,19 +15,25 @@
# 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 the mailmanconf subcommand."""
+"""Test the conf subcommand."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
+ 'TestConf',
]
+
+import os
import sys
+import mock
+import tempfile
import unittest
-from mailman.commands.cli_mailmanconf import Mailmanconf
-from mailman.config import config
+from mailman.commands.cli_conf import Conf
+from mailman.testing.layers import ConfigLayer
+
class FakeArgs:
@@ -46,31 +52,50 @@ class FakeParser:
-class TestMailmanconf(unittest.TestCase):
- """Test the mailmanconf subcommand."""
+class TestConf(unittest.TestCase):
+ """Test the conf subcommand."""
+
+ layer = ConfigLayer
def setUp(self):
- self.command = Mailmanconf()
+ self.command = Conf()
self.command.parser = FakeParser()
self.args = FakeArgs()
def test_cannot_access_nonexistent_section(self):
self.args.section = 'thissectiondoesnotexist'
self.args.key = None
- try:
+ with self.assertRaises(SystemExit):
self.command.process(self.args)
- except SystemExit:
- pass
self.assertEqual(self.command.parser.message,
'No such section: thissectiondoesnotexist')
def test_cannot_access_nonexistent_key(self):
self.args.section = "mailman"
self.args.key = 'thiskeydoesnotexist'
- try:
+ with self.assertRaises(SystemExit):
self.command.process(self.args)
- except SystemExit:
- pass
self.assertEqual(self.command.parser.message,
'Section mailman: No such key: thiskeydoesnotexist')
- \ No newline at end of file
+
+ def test_output_to_explicit_stdout(self):
+ self.args.output = '-'
+ self.args.section = 'shell'
+ self.args.key = 'use_ipython'
+ with mock.patch('sys.stdout') as mock_object:
+ self.command.process(self.args)
+ mock_object.write.assert_has_calls(
+ [mock.call('no'), mock.call('\n')])
+
+ def test_output_to_file(self):
+ self.args.section = 'shell'
+ self.args.key = 'use_ipython'
+ fd, filename = tempfile.mkstemp()
+ try:
+ self.args.output = filename
+ self.command.process(self.args)
+ with open(filename, 'r') as fp:
+ contents = fp.read()
+ finally:
+ os.remove(filename)
+ self.assertEqual(contents, 'no\n')