mirror of
https://github.com/certbot/certbot.git
synced 2025-08-09 15:02:48 +03:00
Fixes https://github.com/certbot/certbot/issues/7913. I only added the deprecation warning to `certbot.tests.util` because that's the only place where I think someone could be using the `mock` module through our API. * remove external mock from acme * update Certbot's mock usage * remove mock dependency in plugins * remove external mock from compatibility test * add changelog entry
53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
"""Tests for acme.errors."""
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
|
|
class BadNonceTest(unittest.TestCase):
|
|
"""Tests for acme.errors.BadNonce."""
|
|
|
|
def setUp(self):
|
|
from acme.errors import BadNonce
|
|
self.error = BadNonce(nonce="xxx", error="error")
|
|
|
|
def test_str(self):
|
|
self.assertEqual("Invalid nonce ('xxx'): error", str(self.error))
|
|
|
|
|
|
class MissingNonceTest(unittest.TestCase):
|
|
"""Tests for acme.errors.MissingNonce."""
|
|
|
|
def setUp(self):
|
|
from acme.errors import MissingNonce
|
|
self.response = mock.MagicMock(headers={})
|
|
self.response.request.method = 'FOO'
|
|
self.error = MissingNonce(self.response)
|
|
|
|
def test_str(self):
|
|
self.assertTrue("FOO" in str(self.error))
|
|
self.assertTrue("{}" in str(self.error))
|
|
|
|
|
|
class PollErrorTest(unittest.TestCase):
|
|
"""Tests for acme.errors.PollError."""
|
|
|
|
def setUp(self):
|
|
from acme.errors import PollError
|
|
self.timeout = PollError(
|
|
exhausted={mock.sentinel.AR},
|
|
updated={})
|
|
self.invalid = PollError(exhausted=set(), updated={
|
|
mock.sentinel.AR: mock.sentinel.AR2})
|
|
|
|
def test_timeout(self):
|
|
self.assertTrue(self.timeout.timeout)
|
|
self.assertFalse(self.invalid.timeout)
|
|
|
|
def test_repr(self):
|
|
self.assertEqual('PollError(exhausted=%s, updated={sentinel.AR: '
|
|
'sentinel.AR2})' % repr(set()), repr(self.invalid))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main() # pragma: no cover
|