1
0
mirror of https://github.com/certbot/certbot.git synced 2026-01-26 07:41:33 +03:00

coverage++

This commit is contained in:
Peter Eckersley
2016-02-03 13:51:01 -08:00
parent 3dd97ccb6a
commit 78fd28a486

View File

@@ -530,35 +530,38 @@ class CLITest(unittest.TestCase): # pylint: disable=too-many-public-methods
self.assertRaises(errors.Error,
self._certonly_new_request_common, mock_client)
@mock.patch('letsencrypt.cli._find_duplicative_certs')
def _test_renewal_common(self, due_for_renewal, extra_args, outstring, mock_fdc):
def _test_renewal_common(self, due_for_renewal, extra_args, outstring, renew=True):
cert_path = 'letsencrypt/tests/testdata/cert.pem'
chain_path = '/etc/letsencrypt/live/foo.bar/fullchain.pem'
mock_lineage = mock.MagicMock(cert=cert_path, fullchain=chain_path)
mock_lineage.should_autorenew.return_value = due_for_renewal
mock_certr = mock.MagicMock()
mock_key = mock.MagicMock(pem='pem_key')
mock_fdc.return_value = (mock_lineage, None)
mock_client = mock.MagicMock()
mock_client.obtain_certificate.return_value = (mock_certr, 'chain',
mock_key, 'csr')
with mock.patch('letsencrypt.cli._init_le_client') as mock_init:
mock_init.return_value = mock_client
get_utility_path = 'letsencrypt.cli.zope.component.getUtility'
with mock.patch(get_utility_path) as mock_get_utility:
with mock.patch('letsencrypt.cli.OpenSSL'):
with mock.patch('letsencrypt.cli.crypto_util'):
args = ['-d', 'foo.bar', '-a',
'standalone', 'certonly']
if extra_args:
args += extra_args
self._call(args)
with mock.patch('letsencrypt.cli._find_duplicative_certs') as mock_fdc:
mock_fdc.return_value = (mock_lineage, None)
with mock.patch('letsencrypt.cli._init_le_client') as mock_init:
mock_init.return_value = mock_client
get_utility_path = 'letsencrypt.cli.zope.component.getUtility'
with mock.patch(get_utility_path) as mock_get_utility:
with mock.patch('letsencrypt.cli.OpenSSL'):
with mock.patch('letsencrypt.cli.crypto_util'):
args = ['-d', 'foo.bar', '-a',
'standalone', 'certonly']
if extra_args:
args += extra_args
self._call(args)
if outstring:
with open(os.path.join(self.logs_dir, "letsencrypt.log")) as lf:
self.assertTrue(outstring in lf.read())
mock_client.obtain_certificate.assert_called_once_with(['foo.bar'])
if renew:
mock_client.obtain_certificate.assert_called_once_with(['foo.bar'])
else:
self.assertEqual(mock_client.obtain_certificate.call_count, 0)
return mock_lineage, mock_get_utility
@@ -573,7 +576,8 @@ class CLITest(unittest.TestCase): # pylint: disable=too-many-public-methods
def test_certonly_renewal_triggers(self):
# --dry-run should force renewal
_, get_utility = self._test_renewal_common(False, ['--dry-run'], "simulating renewal")
_, get_utility = self._test_renewal_common(False, ['--dry-run', '--keep'],
"simulating renewal")
self.assertEqual(get_utility().add_message.call_count, 1)
self.assertTrue('dry run' in get_utility().add_message.call_args[0][0])
@@ -581,6 +585,9 @@ class CLITest(unittest.TestCase): # pylint: disable=too-many-public-methods
"Auto-renewal forced")
self.assertEqual(get_utility().add_message.call_count, 1)
_, _ = self._test_renewal_common(False, ['-tvv', '--debug', '--keep'],
"not yet due", renew=False)
@mock.patch('letsencrypt.cli.zope.component.getUtility')
@mock.patch('letsencrypt.cli._treat_as_renewal')