2015-06-30 09:15:11 -04:00
|
|
|
"""Tests for acme.errors."""
|
|
|
|
|
import unittest
|
2021-02-05 18:51:18 -05:00
|
|
|
from unittest import mock
|
2015-06-30 09:15:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
2021-04-28 20:45:08 -04:00
|
|
|
self.assertIn("FOO", str(self.error))
|
|
|
|
|
self.assertIn("{}", str(self.error))
|
2015-06-30 09:15:11 -04:00
|
|
|
|
|
|
|
|
|
2015-11-29 04:26:03 -05:00
|
|
|
class PollErrorTest(unittest.TestCase):
|
|
|
|
|
"""Tests for acme.errors.PollError."""
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
from acme.errors import PollError
|
|
|
|
|
self.timeout = PollError(
|
2020-04-13 13:41:39 -04:00
|
|
|
exhausted={mock.sentinel.AR},
|
2015-11-29 04:26:03 -05:00
|
|
|
updated={})
|
2016-01-18 15:46:10 -05:00
|
|
|
self.invalid = PollError(exhausted=set(), updated={
|
2015-11-29 04:26:03 -05:00
|
|
|
mock.sentinel.AR: mock.sentinel.AR2})
|
|
|
|
|
|
|
|
|
|
def test_timeout(self):
|
|
|
|
|
self.assertTrue(self.timeout.timeout)
|
|
|
|
|
self.assertFalse(self.invalid.timeout)
|
|
|
|
|
|
|
|
|
|
def test_repr(self):
|
2016-01-18 16:39:25 -05:00
|
|
|
self.assertEqual('PollError(exhausted=%s, updated={sentinel.AR: '
|
|
|
|
|
'sentinel.AR2})' % repr(set()), repr(self.invalid))
|
2015-11-29 04:26:03 -05:00
|
|
|
|
|
|
|
|
|
2015-06-30 09:15:11 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main() # pragma: no cover
|