From 74f5c851782cf40b938f4e6389596d6c994d2f57 Mon Sep 17 00:00:00 2001 From: Amjad Mashaal Date: Wed, 25 May 2016 23:13:26 +0200 Subject: [PATCH] Moving tests for conflicting args to cli_test.py --- certbot/tests/cli_test.py | 4 ++++ certbot/tests/main_test.py | 39 +++----------------------------------- 2 files changed, 7 insertions(+), 36 deletions(-) diff --git a/certbot/tests/cli_test.py b/certbot/tests/cli_test.py index afaa53570..20d891324 100644 --- a/certbot/tests/cli_test.py +++ b/certbot/tests/cli_test.py @@ -908,6 +908,10 @@ class CLITest(unittest.TestCase): # pylint: disable=too-many-public-methods self._call(['-c', test_util.vector_path('cli.ini')]) self.assertTrue(mocked_run.called) + def test_conflicting_args(self): + args = ['renew', '--dialog', '--text'] + self.assertRaises(errors.Error, self._call, args) + class DetermineAccountTest(unittest.TestCase): """Tests for certbot.cli._determine_account.""" diff --git a/certbot/tests/main_test.py b/certbot/tests/main_test.py index e3f8b860d..66cba64a3 100644 --- a/certbot/tests/main_test.py +++ b/certbot/tests/main_test.py @@ -1,49 +1,15 @@ """Tests for certbot.main.""" -import os -import shutil -import tempfile import unittest + import mock -import six + from certbot import cli from certbot import configuration -from certbot import errors -from certbot import main from certbot.plugins import disco as plugins_disco -class MainTest(unittest.TestCase): - """Tests for certbot.main""" - - def setUp(self): - self.tmp_dir = tempfile.mkdtemp() - self.config_dir = os.path.join(self.tmp_dir, 'config') - self.work_dir = os.path.join(self.tmp_dir, 'work') - self.logs_dir = os.path.join(self.tmp_dir, 'logs') - self.standard_args = ['--config-dir', self.config_dir, - '--work-dir', self.work_dir, - '--logs-dir', self.logs_dir, '--text'] - - def tearDown(self): - shutil.rmtree(self.tmp_dir) - - def _call(self, args, stdout=None): - "Run the client with output streams mocked out" - args = self.standard_args + args - - toy_stdout = stdout if stdout else six.StringIO() - with mock.patch('certbot.main.sys.stdout', new=toy_stdout): - with mock.patch('certbot.main.sys.stderr') as stderr: - ret = main.main(args[:]) # NOTE: parser can alter its args! - return ret, toy_stdout, stderr - - def test_args_conflict(self): - args = ['renew', '--dialog', '--text'] - self.assertRaises(errors.Error, self._call, args) - - class ObtainCertTest(unittest.TestCase): """Tests for certbot.main.obtain_cert.""" @@ -60,6 +26,7 @@ class ObtainCertTest(unittest.TestCase): config = configuration.NamespaceConfig( cli.prepare_and_parse_args(plugins, args)) + from certbot import main with mock.patch('certbot.main._init_le_client') as mock_init: main.obtain_cert(config, plugins)