diff --git a/certbot-apache/tests/autohsts_test.py b/certbot-apache/tests/autohsts_test.py index db1c46b52..f09e02fc7 100644 --- a/certbot-apache/tests/autohsts_test.py +++ b/certbot-apache/tests/autohsts_test.py @@ -146,7 +146,7 @@ class AutoHSTSTest(util.ApacheTest): @mock.patch("certbot_apache._internal.display_ops.select_vhost") def test_autohsts_no_ssl_vhost(self, mock_select): mock_select.return_value = self.vh_truth[0] - with mock.patch("certbot_apache._internal.configurator.logger.warning") as mock_log: + with mock.patch("certbot_apache._internal.configurator.logger.error") as mock_log: self.assertRaises(errors.PluginError, self.config.enable_autohsts, mock.MagicMock(), "invalid.example.com") @@ -179,7 +179,7 @@ class AutoHSTSTest(util.ApacheTest): self.config._autohsts_fetch_state() self.config._autohsts["orphan_id"] = {"laststep": 999, "timestamp": 0} self.config._autohsts_save_state() - with mock.patch("certbot_apache._internal.configurator.logger.warning") as mock_log: + with mock.patch("certbot_apache._internal.configurator.logger.error") as mock_log: self.config.deploy_autohsts(mock.MagicMock()) self.assertTrue(mock_log.called) self.assertTrue( diff --git a/certbot-apache/tests/configurator_test.py b/certbot-apache/tests/configurator_test.py index 302bf0023..ccf26a8b2 100644 --- a/certbot-apache/tests/configurator_test.py +++ b/certbot-apache/tests/configurator_test.py @@ -892,7 +892,7 @@ class MultipleVhostsTest(util.ApacheTest): self.config.enhance, "certbot.demo", "unknown_enhancement") def test_enhance_no_ssl_vhost(self): - with mock.patch("certbot_apache._internal.configurator.logger.warning") as mock_log: + with mock.patch("certbot_apache._internal.configurator.logger.error") as mock_log: self.assertRaises(errors.PluginError, self.config.enhance, "certbot.demo", "redirect") # Check that correct logger.warning was printed diff --git a/certbot-dns-cloudflare/tests/dns_cloudflare_test.py b/certbot-dns-cloudflare/tests/dns_cloudflare_test.py index e9adf4ed9..6aaebde3b 100644 --- a/certbot-dns-cloudflare/tests/dns_cloudflare_test.py +++ b/certbot-dns-cloudflare/tests/dns_cloudflare_test.py @@ -41,7 +41,8 @@ class AuthenticatorTest(test_util.TempDirTestCase, dns_test_common.BaseAuthentic # _get_cloudflare_client | pylint: disable=protected-access self.auth._get_cloudflare_client = mock.MagicMock(return_value=self.mock_client) - def test_perform(self): + @test_util.patch_get_utility() + def test_perform(self, unused_mock_get_utility): self.auth.perform([self.achall]) expected = [mock.call.add_txt_record(DOMAIN, '_acme-challenge.'+DOMAIN, mock.ANY, mock.ANY)] @@ -55,7 +56,8 @@ class AuthenticatorTest(test_util.TempDirTestCase, dns_test_common.BaseAuthentic expected = [mock.call.del_txt_record(DOMAIN, '_acme-challenge.'+DOMAIN, mock.ANY)] self.assertEqual(expected, self.mock_client.mock_calls) - def test_api_token(self): + @test_util.patch_get_utility() + def test_api_token(self, unused_mock_get_utility): dns_test_common.write({"cloudflare_api_token": API_TOKEN}, self.config.cloudflare_credentials) self.auth.perform([self.achall]) diff --git a/certbot-dns-digitalocean/tests/dns_digitalocean_test.py b/certbot-dns-digitalocean/tests/dns_digitalocean_test.py index 84bb35b1f..0dfa2fd59 100644 --- a/certbot-dns-digitalocean/tests/dns_digitalocean_test.py +++ b/certbot-dns-digitalocean/tests/dns_digitalocean_test.py @@ -37,7 +37,8 @@ class AuthenticatorTest(test_util.TempDirTestCase, dns_test_common.BaseAuthentic # _get_digitalocean_client | pylint: disable=protected-access self.auth._get_digitalocean_client = mock.MagicMock(return_value=self.mock_client) - def test_perform(self): + @test_util.patch_get_utility() + def test_perform(self, unused_mock_get_utility): self.auth.perform([self.achall]) expected = [mock.call.add_txt_record(DOMAIN, '_acme-challenge.'+DOMAIN, mock.ANY, 30)] diff --git a/certbot-dns-google/tests/dns_google_test.py b/certbot-dns-google/tests/dns_google_test.py index 7de5f1d67..4f71db551 100644 --- a/certbot-dns-google/tests/dns_google_test.py +++ b/certbot-dns-google/tests/dns_google_test.py @@ -43,7 +43,8 @@ class AuthenticatorTest(test_util.TempDirTestCase, dns_test_common.BaseAuthentic # _get_google_client | pylint: disable=protected-access self.auth._get_google_client = mock.MagicMock(return_value=self.mock_client) - def test_perform(self): + @test_util.patch_get_utility() + def test_perform(self, unused_mock_get_utility): self.auth.perform([self.achall]) expected = [mock.call.add_txt_record(DOMAIN, '_acme-challenge.'+DOMAIN, mock.ANY, mock.ANY)] @@ -58,7 +59,8 @@ class AuthenticatorTest(test_util.TempDirTestCase, dns_test_common.BaseAuthentic self.assertEqual(expected, self.mock_client.mock_calls) @mock.patch('httplib2.Http.request', side_effect=ServerNotFoundError) - def test_without_auth(self, unused_mock): + @test_util.patch_get_utility() + def test_without_auth(self, unused_mock_get_utility, unused_mock): self.config.google_credentials = None self.assertRaises(PluginError, self.auth.perform, [self.achall]) diff --git a/certbot-dns-rfc2136/tests/dns_rfc2136_test.py b/certbot-dns-rfc2136/tests/dns_rfc2136_test.py index dc4a73a04..bb1799a45 100644 --- a/certbot-dns-rfc2136/tests/dns_rfc2136_test.py +++ b/certbot-dns-rfc2136/tests/dns_rfc2136_test.py @@ -42,7 +42,8 @@ class AuthenticatorTest(test_util.TempDirTestCase, dns_test_common.BaseAuthentic # _get_rfc2136_client | pylint: disable=protected-access self.auth._get_rfc2136_client = mock.MagicMock(return_value=self.mock_client) - def test_perform(self): + @test_util.patch_get_utility() + def test_perform(self, unused_mock_get_utility): self.auth.perform([self.achall]) expected = [mock.call.add_txt_record('_acme-challenge.'+DOMAIN, mock.ANY, mock.ANY)] @@ -65,7 +66,8 @@ class AuthenticatorTest(test_util.TempDirTestCase, dns_test_common.BaseAuthentic self.auth.perform, [self.achall]) - def test_valid_algorithm_passes(self): + @test_util.patch_get_utility() + def test_valid_algorithm_passes(self, unused_mock_get_utility): config = VALID_CONFIG.copy() config["rfc2136_algorithm"] = "HMAC-sha512" dns_test_common.write(config, self.config.rfc2136_credentials) diff --git a/certbot/certbot/plugins/dns_common.py b/certbot/certbot/plugins/dns_common.py index 334b9665d..3b51700f7 100644 --- a/certbot/certbot/plugins/dns_common.py +++ b/certbot/certbot/plugins/dns_common.py @@ -63,7 +63,7 @@ class DNSAuthenticator(common.Plugin): # DNS updates take time to propagate and checking to see if the update has occurred is not # reliable (the machine this code is running on might be able to see an update before # the ACME server). So: we sleep for a short amount of time we believe to be long enough. - display_util.notify("Waiting %d seconds for DNS changes to propagate", + display_util.notify("Waiting %d seconds for DNS changes to propagate" % self.conf('propagation-seconds')) sleep(self.conf('propagation-seconds')) diff --git a/certbot/certbot/plugins/dns_test_common_lexicon.py b/certbot/certbot/plugins/dns_test_common_lexicon.py index 48261d395..f9c09e821 100644 --- a/certbot/certbot/plugins/dns_test_common_lexicon.py +++ b/certbot/certbot/plugins/dns_test_common_lexicon.py @@ -67,7 +67,8 @@ class _LexiconAwareTestCase(Protocol): class BaseLexiconAuthenticatorTest(dns_test_common.BaseAuthenticatorTest): - def test_perform(self: _AuthenticatorCallableLexiconTestCase): + @test_util.patch_get_utility() + def test_perform(self: _AuthenticatorCallableLexiconTestCase, unused_mock_get_utility): self.auth.perform([self.achall]) expected = [mock.call.add_txt_record(DOMAIN, '_acme-challenge.'+DOMAIN, mock.ANY)] diff --git a/certbot/tests/client_test.py b/certbot/tests/client_test.py index f058cb658..34fbe8bdf 100644 --- a/certbot/tests/client_test.py +++ b/certbot/tests/client_test.py @@ -100,7 +100,8 @@ class RegisterTest(test_util.ConfigTestCase): self._call() self.assertTrue(mock_prepare.called) - def test_it(self): + @test_util.patch_get_utility() + def test_it(self, unused_mock_get_utility): with mock.patch("certbot._internal.client.acme_client.BackwardsCompatibleClientV2") as mock_client: mock_client().external_account_required.side_effect = self._false_mock with mock.patch("certbot._internal.eff.handle_subscription"): @@ -160,7 +161,8 @@ class RegisterTest(test_util.ConfigTestCase): # check Certbot created an account with no email. Contact should return empty self.assertFalse(mock_client().new_account_and_tos.call_args[0][0].contact) - def test_with_eab_arguments(self): + @test_util.patch_get_utility() + def test_with_eab_arguments(self, unused_mock_get_utility): with mock.patch("certbot._internal.client.acme_client.BackwardsCompatibleClientV2") as mock_client: mock_client().client.directory.__getitem__ = mock.Mock( side_effect=self._new_acct_dir_mock @@ -175,7 +177,8 @@ class RegisterTest(test_util.ConfigTestCase): self.assertTrue(mock_eab_from_data.called) - def test_without_eab_arguments(self): + @test_util.patch_get_utility() + def test_without_eab_arguments(self, unused_mock_get_utility): with mock.patch("certbot._internal.client.acme_client.BackwardsCompatibleClientV2") as mock_client: mock_client().external_account_required.side_effect = self._false_mock with mock.patch("certbot._internal.eff.handle_subscription"): @@ -316,7 +319,7 @@ class ClientTest(ClientTestCommon): errors.Error, self.client.obtain_certificate_from_csr, test_csr) - mock_logger.warning.assert_called_once_with(mock.ANY) + mock_logger.error.assert_called_once_with(mock.ANY) @mock.patch("certbot._internal.client.crypto_util") def test_obtain_certificate(self, mock_crypto_util): @@ -602,7 +605,7 @@ class EnhanceConfigTest(ClientTestCommon): self.config.hsts = True with mock.patch("certbot._internal.client.logger") as mock_logger: self.client.enhance_config([self.domain], None) - self.assertEqual(mock_logger.warning.call_count, 1) + self.assertEqual(mock_logger.error.call_count, 1) self.client.installer.enhance.assert_not_called() @mock.patch("certbot._internal.client.logger") diff --git a/certbot/tests/crypto_util_test.py b/certbot/tests/crypto_util_test.py index 3b9c973f7..9829c5f91 100644 --- a/certbot/tests/crypto_util_test.py +++ b/certbot/tests/crypto_util_test.py @@ -493,13 +493,13 @@ class FindChainWithIssuerTest(unittest.TestCase): self.assertEqual(matched, fullchains[0]) mock_info.assert_not_called() - @mock.patch('certbot.crypto_util.logger.info') - def test_warning_on_no_match(self, mock_info): + @mock.patch('certbot.crypto_util.logger.warning') + def test_warning_on_no_match(self, mock_warning): fullchains = self._all_fullchains() matched = self._call(fullchains, "non-existent issuer", warn_on_no_match=True) self.assertEqual(matched, fullchains[0]) - mock_info.assert_called_once_with("Certbot has been configured to prefer " + mock_warning.assert_called_once_with("Certbot has been configured to prefer " "certificate chains with issuer '%s', but no chain from the CA matched " "this issuer. Using the default certificate chain instead.", "non-existent issuer") diff --git a/certbot/tests/hook_test.py b/certbot/tests/hook_test.py index b0522bd52..4133405c9 100644 --- a/certbot/tests/hook_test.py +++ b/certbot/tests/hook_test.py @@ -345,7 +345,7 @@ class DeployHookTest(RenewalHookTest): mock_execute = self._call_with_mock_execute( self.config, ["example.org"], "/foo/bar") self.assertFalse(mock_execute.called) - self.assertTrue(mock_logger.warning.called) + self.assertTrue(mock_logger.info.called) @mock.patch("certbot._internal.hooks.logger") def test_no_hook(self, mock_logger): @@ -393,7 +393,7 @@ class RenewHookTest(RenewalHookTest): mock_execute = self._call_with_mock_execute( self.config, ["example.org"], "/foo/bar") self.assertFalse(mock_execute.called) - self.assertEqual(mock_logger.warning.call_count, 2) + self.assertEqual(mock_logger.info.call_count, 2) def test_no_hooks(self): self.config.renew_hook = None diff --git a/certbot/tests/plugins/dns_common_test.py b/certbot/tests/plugins/dns_common_test.py index 31761e986..f887a79dc 100644 --- a/certbot/tests/plugins/dns_common_test.py +++ b/certbot/tests/plugins/dns_common_test.py @@ -42,7 +42,8 @@ class DNSAuthenticatorTest(test_util.TempDirTestCase, dns_test_common.BaseAuthen self.auth = DNSAuthenticatorTest._FakeDNSAuthenticator(self.config, "fake") - def test_perform(self): + @test_util.patch_get_utility() + def test_perform(self, unused_mock_get_utility): self.auth.perform([self.achall]) self.auth._perform.assert_called_once_with(dns_test_common.DOMAIN, mock.ANY, mock.ANY) diff --git a/certbot/tests/storage_test.py b/certbot/tests/storage_test.py index 1e3a1ffd8..5557db76a 100644 --- a/certbot/tests/storage_test.py +++ b/certbot/tests/storage_test.py @@ -716,7 +716,7 @@ class RenewableCertTests(BaseRenewableCertTest): # Test with error mock_checker.side_effect = ValueError - with mock.patch("certbot._internal.storage.logger.warning") as logger: + with mock.patch("certbot._internal.storage.logger.error") as logger: self.assertFalse(self.test_rc.ocsp_revoked(version)) self.assertEqual(mock_checker.call_args[0][0], expected_cert_path) self.assertEqual(mock_checker.call_args[0][1], expected_chain_path) diff --git a/certbot/tests/util_test.py b/certbot/tests/util_test.py index 18947c342..abde665a5 100644 --- a/certbot/tests/util_test.py +++ b/certbot/tests/util_test.py @@ -346,19 +346,19 @@ class AddDeprecatedArgumentTest(unittest.TestCase): def test_warning_no_arg(self): self._call("--old-option", 0) - with mock.patch("certbot.util.logger.warning") as mock_warn: + with mock.patch("warnings.warn") as mock_warn: self.parser.parse_args(["--old-option"]) self.assertEqual(mock_warn.call_count, 1) self.assertTrue("is deprecated" in mock_warn.call_args[0][0]) - self.assertEqual("--old-option", mock_warn.call_args[0][1]) + self.assertTrue("--old-option" in mock_warn.call_args[0][0]) def test_warning_with_arg(self): self._call("--old-option", 1) - with mock.patch("certbot.util.logger.warning") as mock_warn: + with mock.patch("warnings.warn") as mock_warn: self.parser.parse_args(["--old-option", "42"]) self.assertEqual(mock_warn.call_count, 1) self.assertTrue("is deprecated" in mock_warn.call_args[0][0]) - self.assertEqual("--old-option", mock_warn.call_args[0][1]) + self.assertTrue("--old-option" in mock_warn.call_args[0][0]) def test_help(self): self._call("--old-option", 2)