def test_construct_api_key_env(self, m_getenv): """ Test Civo Constructor """ m_getenv.return_value = 'FOO' civo = Civo() self.assertEqual(civo.token, 'FOO') m_getenv.assert_has_calls([call('CIVO_TOKEN', False)])
def test_construct_api_key_env_and_argv(self, m_getenv): """ Test Civo Constructor """ m_getenv.return_value = 'FOO' civo = Civo(civo_token='BAR') self.assertEqual(civo.token, 'BAR') self.assertTrue(('CIVO_TOKEN', False) not in m_getenv.call_args_list)
def test_create_cluster_region_in_base_and_create(self, m_post): """ Test Create Cluster """ resp, data, status = self.get_response('create_clusters.json') m_post.return_value = resp self.add_auth() self.add_defaults() civo = Civo(civo_token=self.api_key, region="XYZ") _out = civo.kubernetes.create(name="SomeCluster", region="NYC1") m_post.assert_called_once_with(self.url + "?region=NYC1", headers=self.headers, params=self.params) self.assertEqual(_out, data)
def test_create_cluster_default_region(self, m_post, m_get): """ Test Create Cluster """ resp, data, status = self.get_response('create_clusters.json') m_post.return_value = resp net_resp, net_data, net_status = self.get_response('get_network.json') m_get.return_value = net_resp self.add_auth() self.add_defaults() civo = Civo(civo_token=self.api_key) _out = civo.kubernetes.create(name="SomeCluster") self.assertIsNone(civo.region) m_post.assert_called_once_with(self.url, headers=self.headers, params=self.params) self.assertDictEqual(_out, loads(data))
def test_construct_no_api_key(self): """ Test Civo Constructor """ with self.assertRaises(Exception): civo = Civo()
def setUp(self) -> None: self.civo = Civo()
import unittest from civo import Civo civo = Civo(civo_token='dDq7uUCrk30jVBwX2f41FeWAvyM0Y8iS5OaNzIgJGlHcEPs9mR') class TestSsh(unittest.TestCase): def test_ssh_create(self): """ Test if can create ssh key """ result = civo.ssh.create(name='test_ssh', public_key='test_public_key') self.assertEqual(result['result'], 'success') def test_ssh_list(self): """ Test to list all ssh key """ result = civo.ssh.lists(filter='name:test_ssh') self.assertEqual(result[0]['name'], 'test_ssh') def test_ssh_retrieving(self): """ Test to retrieving ssh key """ id = civo.ssh.search(filter='name:test_ssh')[0]['id'] result = civo.ssh.retrieving(id=id)
import time from fabric import Connection from civo import Civo hostname_default = 'gitops-civo.example.com' civo = Civo() size_id = civo.size.search(filter='name:g2.xsmall')[0]['name'] template = civo.templates.search(filter='code:debian-stretch')[0]['id'] search_hostname = civo.instances.search( filter='hostname:{}'.format(hostname_default)) ssh_id = civo.ssh.search(filter='name:alejandrojnm')[0]['id'] if not search_hostname: instance = civo.instances.create(hostname=hostname_default, size=size_id, region='lon1', template_id=template, public_ip='true', ssh_key_id=ssh_id) status = instance['status'] while status != 'ACTIVE': status = civo.instances.search( filter='hostname:{}'.format(hostname_default))[0]['status'] time.sleep(10) # add this because the instance is not ready to handle ssh connection so fast time.sleep(20) ip_server = civo.instances.search(