class TestPrivateNetwork(unittest.TestCase):
    def setUp(self):
        self.client = OneAndOneService('USER-API-KEY')

    # 'GET' Methods
    @responses.activate
    def test_list_ssh_keys(self):

        with open('mock-api/list-ssh-keys.json') as f:
            data = json.load(f)

        test_id = data[0]['id']

        responses.add(responses.GET,
                      'https://cloudpanel-api.1and1.com/v1/ssh_keys',
                      body=json.dumps(data),
                      status=200,
                      content_type="application/json")

        r = self.client.list_ssh_keys()

        self.assertEqual(r[0]['id'], test_id)

    @responses.activate
    def test_get_ssh_key(self):

        with open('mock-api/get-ssh-key.json') as f:
            data = json.load(f)

        ssh_key_id = data['id']

        responses.add(responses.GET,
                      'https://cloudpanel-api.1and1.com/v1/ssh_keys/%s' %
                      ssh_key_id,
                      body=json.dumps(data),
                      status=200,
                      content_type="application/json")

        r = self.client.get_ssh_key(ssh_key_id=ssh_key_id)

        self.assertEqual(r['id'], ssh_key_id)

    # 'PUT' Methods
    @responses.activate
    def test_modify_ssh_key(self):

        with open('mock-api/modify-ssh-key.json') as f:
            data = json.load(f)

        ssh_key_id = data['id']
        name = data['name']
        description = data['description']

        responses.add(responses.PUT,
                      'https://cloudpanel-api.1and1.com/v1/ssh_keys/%s' %
                      ssh_key_id,
                      body=json.dumps(data),
                      status=200,
                      content_type="application/json")

        r = self.client.modify_ssh_key(ssh_key_id=ssh_key_id,
                                       name=name,
                                       description=description)

        self.assertEqual(r['name'], name)
        self.assertEqual(r['description'], description)

    # 'POST' Methods
    @responses.activate
    def test_create_ssh_key(self):

        with open('mock-api/create-ssh-key.json') as f:
            data = json.load(f)

        ssh1 = SshKey(name=data['name'],
                      description=data['description'],
                      public_key=data['public_key'])

        responses.add(responses.POST,
                      'https://cloudpanel-api.1and1.com/v1/ssh_keys',
                      body=json.dumps(data),
                      status=202,
                      content_type="application/json")

        r = self.client.create_ssh_key(ssh_key=ssh1)

        self.assertEqual(r['name'], ssh1.name)

    @responses.activate
    def test_delete_ssh_key(self):

        with open('mock-api/delete-ssh-key.json') as f:
            data = json.load(f)

        ssh_key_id = data['id']

        responses.add(
            responses.DELETE,
            'https://cloudpanel-api.1and1.com/v1/private_networks/%s' %
            ssh_key_id,
            body=json.dumps(data),
            status=202,
            content_type="application/json")

        r = self.client.delete_private_network(ssh_key_id=ssh_key_id)

        self.assertEqual(r['state'], 'DELETING')
# Create an ssh key
from oneandone.client import OneAndOneService, SshKey

client = OneAndOneService('<API-TOKEN>')

ssh_key = SshKey(
    name='Test SSH Key',
    description='Test Description',
    public_key=
    'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC6U+LbJPFNDkORkrVUSg78IJjNDSBY1NgDzhr0S9rLvRVInHDT+3DsojZDqXglCpaLwNcdIQM1saGlIKlmxJro8Qw2kJRKqhP/DZLmvcz+niUKZ/0ho1a5HAlTJl6ct8DFto/z+hhDIHTRL4i7n+M/n9SNGjQ28EQy6SztsqwV8yheiUIgNO2lOXDi1Pjs7znBLFE305AHpf6pv4jlUE7r280+WAuloZJaNtu2YL4XXKsemBliDet54OJaW/4e+/5TexX0wZwkibdhuCSFJvhCJ6jbJZbdUwCyqlz6tiu75bSUTV7WGlxWtUjZCY0KBO9BPwbTDhxmIAeigDxnSRhekC/5b7cYUVys0JgvxBKiBVg6Bc32c7fjeOrNpUixzVxtm6UQtZDYyOa+1OvPKPpHg1Ugy28aUtqV4yRYQbltkLB8JSKaZvCqzm9d6qXhkCKV2GmMs5glBE0MyZMiwgoc+Ar0HuN3RnYNzIWIZc1CYTfKB+otHEwmb8V4hS6/k50obPa4J81RJekLU/8yY0WDRWVven6hyriBhNJXpI3V84XqSB4cl1HNcFgeat+EbM5e5QuLUn3Uwdt15kugQt5t9LqVK1jyqWQ4CrJ+Yg7/uU7l7fPHH0rvk9LvSv4BXlHETbScUDOnaZnr8m+4HJyucVq1tXdPCCDSyGGNO/IFBw== [email protected]'
)

response = client.create_ssh_key(ssh_key)

# List all ssh keys
from oneandone.client import OneAndOneService

client = OneAndOneService('<API-TOKEN>')

response = client.list_ssh_keys()

# Retrieve a single ssh key
from oneandone.client import OneAndOneService

client = OneAndOneService('<API-TOKEN>')

response = client.get_ssh_key(ssh_key_id='')

# Modify an ssh key
from oneandone.client import OneAndOneService