def test_ssh_key_is_created_if_it_does_not_exist_yet(self): self.ssh_api().load.side_effect = digitalocean.DataReadError( 'The resource you were accessing could not be found.' ) self.client.post(self.url, self.get_valid_data(ssh_public_key=self.ssh_url)) self.ssh_api().load.assert_called_once() self.ssh_api().create.assert_called_once()
def test_if_token_is_readonly_alert_is_raised(self): self.droplet_api().create.side_effect = digitalocean.DataReadError( 'You do not have access for the attempted action.') data = self.get_valid_data(ssh_public_key=self.ssh_url) self.assertRaises(TokenScopeError, self.client.post, self.url, data) self.assertTrue( Alert.objects.filter( alert_type='token_is_read_only', content_type=ContentType.objects.get_for_model(self.settings), object_id=self.settings.id, closed__isnull=True).exists())
"""Tests for certbot_dns_digitalocean.dns_digitalocean.""" import os import unittest import digitalocean import mock from certbot import errors from certbot.plugins import dns_test_common from certbot.plugins.dns_test_common import DOMAIN from certbot.tests import util as test_util API_ERROR = digitalocean.DataReadError() TOKEN = 'a-token' class AuthenticatorTest(test_util.TempDirTestCase, dns_test_common.BaseAuthenticatorTest): def setUp(self): from certbot_dns_digitalocean.dns_digitalocean import Authenticator super(AuthenticatorTest, self).setUp() path = os.path.join(self.tempdir, 'file.ini') dns_test_common.write({"digitalocean_token": TOKEN}, path) self.config = mock.MagicMock( digitalocean_credentials=path, digitalocean_propagation_seconds=0) # don't wait during tests