dns_dnspod_test.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """Tests for certbot_dns_dnspod.dns_dnspod."""
  2. import os
  3. import unittest
  4. import mock
  5. from requests.exceptions import HTTPError, RequestException
  6. from certbot.plugins import dns_test_common
  7. from certbot.plugins import dns_test_common_lexicon
  8. from certbot.tests import util as test_util
  9. DOMAIN_NOT_FOUND = Exception('No domain found')
  10. GENERIC_ERROR = RequestException
  11. LOGIN_ERROR = HTTPError('400 Client Error: ...')
  12. API_ID = '123'
  13. API_TOKEN = 'bar'
  14. class AuthenticatorTest(test_util.TempDirTestCase,
  15. dns_test_common_lexicon.BaseLexiconAuthenticatorTest):
  16. def setUp(self):
  17. super(AuthenticatorTest, self).setUp()
  18. from certbot_dns_dnspod.dns_dnspod import Authenticator
  19. path = os.path.join(self.tempdir, 'file.ini')
  20. dns_test_common.write({"dnspod_api_id": API_ID, "dnspod_api_token": API_TOKEN}, path)
  21. self.config = mock.MagicMock(dnspod_credentials=path,
  22. dnspod_propagation_seconds=0) # don't wait during tests
  23. self.auth = Authenticator(self.config, "dnspod")
  24. self.mock_client = mock.MagicMock()
  25. # _get_dnspod_client | pylint: disable=protected-access
  26. self.auth._get_dnspod_client = mock.MagicMock(return_value=self.mock_client)
  27. class DNSPodLexiconClientTest(unittest.TestCase, dns_test_common_lexicon.BaseLexiconClientTest):
  28. def setUp(self):
  29. from certbot_dns_dnspod.dns_dnspod import _DNSPodLexiconClient
  30. self.client = _DNSPodLexiconClient(API_ID, API_TOKEN, 0)
  31. self.provider_mock = mock.MagicMock()
  32. self.client.provider = self.provider_mock
  33. if __name__ == "__main__":
  34. unittest.main() # pragma: no cover