mirror of
https://github.com/certbot/certbot.git
synced 2026-08-02 03:11:55 +02:00
Adding args conflict test to main_test.py
This commit is contained in:
@@ -1,15 +1,49 @@
|
|||||||
"""Tests for certbot.main."""
|
"""Tests for certbot.main."""
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
import six
|
||||||
|
|
||||||
from certbot import cli
|
from certbot import cli
|
||||||
from certbot import configuration
|
from certbot import configuration
|
||||||
|
from certbot import errors
|
||||||
|
from certbot import main
|
||||||
from certbot.plugins import disco as plugins_disco
|
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):
|
class ObtainCertTest(unittest.TestCase):
|
||||||
"""Tests for certbot.main.obtain_cert."""
|
"""Tests for certbot.main.obtain_cert."""
|
||||||
|
|
||||||
@@ -26,7 +60,6 @@ class ObtainCertTest(unittest.TestCase):
|
|||||||
config = configuration.NamespaceConfig(
|
config = configuration.NamespaceConfig(
|
||||||
cli.prepare_and_parse_args(plugins, args))
|
cli.prepare_and_parse_args(plugins, args))
|
||||||
|
|
||||||
from certbot import main
|
|
||||||
with mock.patch('certbot.main._init_le_client') as mock_init:
|
with mock.patch('certbot.main._init_le_client') as mock_init:
|
||||||
main.obtain_cert(config, plugins)
|
main.obtain_cert(config, plugins)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user