Skip to content

Commit 6e2d75d

Browse files
authored
Merge pull request #25 from roaldnefs/develop
Remove duplicate ApiObjects and ApiServices
2 parents 318f744 + 1e99cf4 commit 6e2d75d

10 files changed

Lines changed: 246 additions & 313 deletions

File tree

tests/services/__init__.py

Whitespace-only changes.

tests/services/test_domains.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
import responses # type: ignore
21+
import unittest
22+
import pytest
23+
24+
from typing import Type, List, Dict, Any, Union
25+
26+
from transip import TransIP
27+
from transip.v6.objects import Domain, WhoisContact, Nameserver, DnsEntry
28+
from tests.utils import load_responses_fixture
29+
30+
31+
@pytest.mark.usefixtures("minimal_client_class")
32+
class DomainsTest(unittest.TestCase):
33+
"""Test the DomainService."""
34+
35+
client: Type[TransIP]
36+
37+
def setUp(self):
38+
# Setup mocked responses for the /domains endpoint
39+
load_responses_fixture("domains.json")
40+
41+
@responses.activate
42+
def test_get(self) -> None:
43+
domain: Type[Domain] = self.client.domains.get("example.com")
44+
45+
assert domain.get_id() == "example.com" # type: ignore
46+
47+
@responses.activate
48+
def test_contacts_list(self) -> None:
49+
domain: Type[Domain] = self.client.domains.get("example.com")
50+
contacts: List[Type[Domain]] = domain.contacts.list() # type: ignore
51+
contact: Type[Domain] = contacts[0]
52+
53+
assert len(contacts) == 1
54+
assert contact.companyName == "Example B.V." # type: ignore
55+
56+
@responses.activate
57+
def test_nameservers_list(self) -> None:
58+
domain: Type[Domain] = self.client.domains.get("example.com")
59+
nameservers: List[Type[Nameserver]] = domain.nameservers.list() # type: ignore
60+
nameserver: Type[Nameserver] = nameservers[0]
61+
62+
assert len(nameservers) == 1
63+
assert nameserver.get_id() == "ns0.transip.nl" # type: ignore
64+
65+
@responses.activate
66+
def test_dns_list(self) -> None:
67+
domain: Type[Domain] = self.client.domains.get("example.com")
68+
entries: List[Type[DnsEntry]] = domain.dns.list() # type: ignore
69+
entry: Type[DnsEntry] = entries[0]
70+
71+
assert len(entries) == 1
72+
assert entry.name == "www" # type: ignore
73+
74+
@responses.activate
75+
def test_dns_create(self) -> None:
76+
dns_entry_data: Dict[str, Union[str, int]] = {
77+
"name": "www",
78+
"expire": 86400,
79+
"type": "A",
80+
"content": "127.0.0.1"
81+
}
82+
domain: Type[Domain] = self.client.domains.get("example.com")
83+
domain.dns.create(dns_entry_data) # type: ignore
84+
85+
assert len(responses.calls) == 2

tests/services/test_invoices.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 Invoice
25+
26+
27+
@responses.activate
28+
def test_invoices_list(transip_minimal_client: Type[TransIP]) -> None:
29+
responses.add(
30+
responses.GET,
31+
"https://api.transip.nl/v6/invoices",
32+
json={
33+
"invoices": [
34+
{
35+
"invoiceNumber": "F0000.1911.0000.0004",
36+
"creationDate": "2020-01-01",
37+
"payDate": "2020-01-01",
38+
"dueDate": "2020-02-01",
39+
"invoiceStatus": "waitsforpayment",
40+
"currency": "EUR",
41+
"totalAmount": 1000,
42+
"totalAmountInclVat": 1240
43+
}
44+
]
45+
},
46+
status=200,
47+
)
48+
49+
invoices: List[Type[Invoice]] = transip_minimal_client.invoices.list()
50+
invoice: Type[Invoice] = invoices[0]
51+
assert len(invoices) == 1
52+
assert invoice.get_id() == "F0000.1911.0000.0004" # type: ignore
53+
54+
55+
@responses.activate
56+
def test_invoices_get(transip_minimal_client: Type[TransIP]) -> None:
57+
responses.add(
58+
responses.GET,
59+
"https://api.transip.nl/v6/invoices/F0000.1911.0000.0004",
60+
json={
61+
"invoice": {
62+
"invoiceNumber": "F0000.1911.0000.0004",
63+
"creationDate": "2020-01-01",
64+
"payDate": "2020-01-01",
65+
"dueDate": "2020-02-01",
66+
"invoiceStatus": "waitsforpayment",
67+
"currency": "EUR",
68+
"totalAmount": 1000,
69+
"totalAmountInclVat": 1240
70+
}
71+
},
72+
status=200,
73+
)
74+
75+
invoice_id: str = "F0000.1911.0000.0004"
76+
invoice: Type[Invoice] = transip_minimal_client.invoices.get(invoice_id)
77+
assert invoice.get_id() == "F0000.1911.0000.0004" # type: ignore

tests/services/test_ssh_keys.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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, Tuple, Any, Dict
21+
import responses # type: ignore
22+
import json
23+
import pytest
24+
import unittest
25+
26+
from transip import TransIP
27+
from transip.v6.objects import SshKey
28+
from tests.utils import load_responses_fixture
29+
30+
31+
@pytest.mark.usefixtures("minimal_client_class")
32+
class SshKeysTest(unittest.TestCase):
33+
"""Test the SshKeyService."""
34+
35+
client: Type[TransIP]
36+
37+
def setUp(self):
38+
# Setup mocked responses for the /ssh-keys endpoint
39+
load_responses_fixture("ssh-keys.json")
40+
41+
@responses.activate
42+
def test_list(self) -> None:
43+
ssh_keys: List[Type[SshKey]] = self.client.ssh_keys.list()
44+
ssh_key: Type[SshKey] = ssh_keys[0]
45+
46+
assert len(ssh_keys) == 1
47+
assert ssh_key.get_id() == 123 # type: ignore
48+
49+
@responses.activate
50+
def test_get(self) -> None:
51+
ssh_key_id: int = 123
52+
ssh_key: Type[SshKey] = self.client.ssh_keys.get(ssh_key_id)
53+
54+
assert ssh_key.get_id() == 123 # type: ignore
55+
56+
@responses.activate
57+
def test_delete(self) -> None:
58+
ssh_key_id: int = 123
59+
try:
60+
self.client.ssh_keys.delete(ssh_key_id)
61+
except Exception as exc:
62+
assert False, f"'transip.TransIP.ssh_keys.delete' raised an exception {exc}"
63+
64+
@responses.activate
65+
def test_create(self) -> None:
66+
ssh_key_data: Dict[str, str] = {
67+
"sshKey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDf2pxWX/yhUBDyk2LPhvRtI0LnVO8PyR5Zt6AHrnhtLGqK+8YG9EMlWbCCWrASR+Q1hFQG example",
68+
"description": "Jim key"
69+
}
70+
self.client.ssh_keys.create(ssh_key_data)
71+
72+
assert len(responses.calls) == 1
73+
74+
@responses.activate
75+
def test_update(self) -> None:
76+
ssh_key_id: int = 123
77+
ssh_key_data: Dict[str, str] = {
78+
"description": "Jim key"
79+
}
80+
81+
try:
82+
self.client.ssh_keys.update(ssh_key_id, ssh_key_data)
83+
except Exception as exc:
84+
assert False, f"'transip.TransIP.ssh_keys.update' raised an exception {exc}"

transip/v6/services/__init__.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

transip/v6/services/availability_zone.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)