|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright (C) 2020 Roald Nefs <info@roaldnefs.com> |
| 4 | +# |
| 5 | +# This file is part of python-transip. |
| 6 | + |
| 7 | +# python-transip is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU Lesser General Public License as published by |
| 9 | +# the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | + |
| 12 | +# python-transip is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU Lesser General Public License for more details. |
| 16 | + |
| 17 | +# You should have received a copy of the GNU Lesser General Public License |
| 18 | +# along with python-transip. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + |
| 20 | +from typing import Type, List |
| 21 | +import responses # type: ignore |
| 22 | + |
| 23 | +from transip import TransIP |
| 24 | +from transip.v6.objects import SshKey |
| 25 | + |
| 26 | + |
| 27 | +@responses.activate |
| 28 | +def test_ssh_keys_list(transip_minimal_client: Type[TransIP]) -> None: |
| 29 | + responses.add( |
| 30 | + responses.GET, |
| 31 | + "https://api.transip.nl/v6/ssh-keys", |
| 32 | + json={ |
| 33 | + "sshKeys": [{ |
| 34 | + "id": 123, |
| 35 | + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDf2pxWX/yhUBDyk2LPhvRtI0LnVO8PyR5Zt6AHrnhtLGqK+8YG9EMlWbCCWrASR+Q1hFQG example", |
| 36 | + "description": "Jim key", |
| 37 | + "creationDate": "2020-12-01 15:25:01", |
| 38 | + "fingerprint": "bb:22:43:69:2b:0d:3e:16:58:91:27:8a:62:29:97:d1" |
| 39 | + }] |
| 40 | + }, |
| 41 | + status=200, |
| 42 | + ) |
| 43 | + |
| 44 | + ssh_keys: List[Type[SshKey]] = transip_minimal_client.ssh_keys.list() |
| 45 | + ssh_key: Type[SshKey] = ssh_keys[0] |
| 46 | + assert len(ssh_keys) == 1 |
| 47 | + assert ssh_key.get_id() == 123 # type: ignore |
| 48 | + |
| 49 | + |
| 50 | +@responses.activate |
| 51 | +def test_ssh_keys_get(transip_minimal_client: Type[TransIP]) -> None: |
| 52 | + responses.add( |
| 53 | + responses.GET, |
| 54 | + "https://api.transip.nl/v6/ssh-keys/123", |
| 55 | + json={ |
| 56 | + "sshKey": { |
| 57 | + "id": 123, |
| 58 | + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDf2pxWX/yhUBDyk2LPhvRtI0LnVO8PyR5Zt6AHrnhtLGqK+8YG9EMlWbCCWrASR+Q1hFQG example", |
| 59 | + "description": "Jim key", |
| 60 | + "creationDate": "2020-12-01 15:25:01", |
| 61 | + "fingerprint": "bb:22:43:69:2b:0d:3e:16:58:91:27:8a:62:29:97:d1" |
| 62 | + } |
| 63 | + }, |
| 64 | + status=200, |
| 65 | + ) |
| 66 | + |
| 67 | + ssh_key_id: int = 123 |
| 68 | + ssh_key: Type[SshKey] = transip_minimal_client.ssh_keys.get(ssh_key_id) |
| 69 | + assert ssh_key.get_id() == 123 # type: ignore |
| 70 | + |
| 71 | + |
| 72 | +@responses.activate |
| 73 | +def test_ssh_keys_delete(transip_minimal_client: Type[TransIP]) -> None: |
| 74 | + responses.add( |
| 75 | + responses.DELETE, |
| 76 | + "https://api.transip.nl/v6/ssh-keys/123", |
| 77 | + status=204, |
| 78 | + ) |
| 79 | + |
| 80 | + ssh_key_id: int = 123 |
| 81 | + try: |
| 82 | + transip_minimal_client.ssh_keys.delete(ssh_key_id) |
| 83 | + except Exception as exc: |
| 84 | + assert False, f"'transip.TransIP.ssh_keys.delete' raised an exception {exc}" |
0 commit comments