Skip to content

Commit 7771f01

Browse files
committed
Use unittest.TestCase for all tests
Signed-off-by: Roald Nefs <info@roaldnefs.com>
1 parent b263eec commit 7771f01

6 files changed

Lines changed: 105 additions & 141 deletions

File tree

tests/conftest.py

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

tests/services/test_domains.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,75 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2020 Roald Nefs <info@roaldnefs.com>
3+
# Copyright (C) 2020, 2012 Roald Nefs <info@roaldnefs.com>
44
#
55
# This file is part of python-transip.
6-
6+
#
77
# python-transip is free software: you can redistribute it and/or modify
88
# it under the terms of the GNU Lesser General Public License as published by
99
# the Free Software Foundation, either version 3 of the License, or
1010
# (at your option) any later version.
11-
11+
#
1212
# python-transip is distributed in the hope that it will be useful,
1313
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
# GNU Lesser General Public License for more details.
16-
16+
#
1717
# You should have received a copy of the GNU Lesser General Public License
1818
# along with python-transip. If not, see <https://www.gnu.org/licenses/>.
1919

2020
import responses # type: ignore
2121
import unittest
22-
import pytest
2322

24-
from typing import Type, List, Dict, Any, Union
23+
from typing import List, Dict, Any, Union
2524

2625
from transip import TransIP
2726
from transip.v6.objects import Domain, WhoisContact, Nameserver, DnsEntry
28-
from tests.utils import load_responses_fixture
27+
from tests.utils import load_responses_fixtures
2928

3029

31-
@pytest.mark.usefixtures("minimal_client_class")
3230
class DomainsTest(unittest.TestCase):
3331
"""Test the DomainService."""
3432

35-
client: Type[TransIP]
33+
client: TransIP
34+
35+
@classmethod
36+
def setUpClass(cls) -> None:
37+
"""Set up a minimal TransIP client for using the domain services."""
38+
cls.client = TransIP(access_token='ACCESS_TOKEN')
3639

37-
def setUp(self):
38-
# Setup mocked responses for the /domains endpoint
39-
load_responses_fixture("domains.json")
40+
def setUp(self) -> None:
41+
"""Setup mocked responses for the '/domains' endpoint."""
42+
load_responses_fixtures("domains.json")
4043

4144
@responses.activate
4245
def test_get(self) -> None:
43-
domain: Type[Domain] = self.client.domains.get("example.com")
46+
domain: Domain = self.client.domains.get("example.com")
4447

4548
assert domain.get_id() == "example.com" # type: ignore
4649

4750
@responses.activate
4851
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+
domain: Domain = self.client.domains.get("example.com")
53+
contacts: List[Domain] = domain.contacts.list() # type: ignore
54+
contact: Domain = contacts[0]
5255

5356
assert len(contacts) == 1
5457
assert contact.companyName == "Example B.V." # type: ignore
5558

5659
@responses.activate
5760
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+
domain: Domain = self.client.domains.get("example.com")
62+
nameservers: List[Nameserver] = domain.nameservers.list() # type: ignore
63+
nameserver: Nameserver = nameservers[0]
6164

6265
assert len(nameservers) == 1
6366
assert nameserver.get_id() == "ns0.transip.nl" # type: ignore
6467

6568
@responses.activate
6669
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+
domain: Domain = self.client.domains.get("example.com")
71+
entries: List[DnsEntry] = domain.dns.list() # type: ignore
72+
entry: DnsEntry = entries[0]
7073

7174
assert len(entries) == 1
7275
assert entry.name == "www" # type: ignore
@@ -79,7 +82,7 @@ def test_dns_create(self) -> None:
7982
"type": "A",
8083
"content": "127.0.0.1"
8184
}
82-
domain: Type[Domain] = self.client.domains.get("example.com")
85+
domain: Domain = self.client.domains.get("example.com")
8386
domain.dns.create(dns_entry_data) # type: ignore
8487

8588
assert len(responses.calls) == 2

tests/services/test_invoices.py

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,55 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2020 Roald Nefs <info@roaldnefs.com>
3+
# Copyright (C) 2020, 2021 Roald Nefs <info@roaldnefs.com>
44
#
55
# This file is part of python-transip.
6-
6+
#
77
# python-transip is free software: you can redistribute it and/or modify
88
# it under the terms of the GNU Lesser General Public License as published by
99
# the Free Software Foundation, either version 3 of the License, or
1010
# (at your option) any later version.
11-
11+
#
1212
# python-transip is distributed in the hope that it will be useful,
1313
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
# GNU Lesser General Public License for more details.
16-
16+
#
1717
# You should have received a copy of the GNU Lesser General Public License
1818
# along with python-transip. If not, see <https://www.gnu.org/licenses/>.
1919

20-
from typing import Type, List
20+
from typing import List, Tuple, Any, Dict
2121
import responses # type: ignore
22+
import unittest
2223

2324
from transip import TransIP
2425
from transip.v6.objects import Invoice
26+
from tests.utils import load_responses_fixtures
2527

28+
class InvoicesTest(unittest.TestCase):
29+
"""Test the InvoiceService."""
2630

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
31+
client: TransIP
32+
33+
@classmethod
34+
def setUpClass(cls) -> None:
35+
"""Set up a minimal TransIP client for using the invoice services."""
36+
cls.client = TransIP(access_token='ACCESS_TOKEN')
5337

38+
def setUp(self) -> None:
39+
"""Setup mocked responses for the '/invoices' endpoint."""
40+
load_responses_fixtures("account.json")
5441

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-
)
42+
@responses.activate
43+
def test_list(self) -> None:
44+
invoices: List[Invoice] = self.client.invoices.list()
45+
invoice: Invoice = invoices[0]
7446

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
47+
assert len(invoices) == 1
48+
assert invoice.get_id() == "F0000.1911.0000.0004" # type: ignore
49+
50+
@responses.activate
51+
def test_get(self) -> None:
52+
invoice_id: str = "F0000.1911.0000.0004"
53+
invoice: Invoice = self.client.invoices.get(invoice_id)
54+
55+
assert invoice.get_id() == "F0000.1911.0000.0004" # type: ignore

tests/services/test_ssh_keys.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,57 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2020 Roald Nefs <info@roaldnefs.com>
3+
# Copyright (C) 2020, 2021 Roald Nefs <info@roaldnefs.com>
44
#
55
# This file is part of python-transip.
6-
6+
#
77
# python-transip is free software: you can redistribute it and/or modify
88
# it under the terms of the GNU Lesser General Public License as published by
99
# the Free Software Foundation, either version 3 of the License, or
1010
# (at your option) any later version.
11-
11+
#
1212
# python-transip is distributed in the hope that it will be useful,
1313
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
# GNU Lesser General Public License for more details.
16-
16+
#
1717
# You should have received a copy of the GNU Lesser General Public License
1818
# along with python-transip. If not, see <https://www.gnu.org/licenses/>.
1919

20-
from typing import Type, List, Tuple, Any, Dict
20+
from typing import List, Tuple, Any, Dict
2121
import responses # type: ignore
22-
import json
23-
import pytest
2422
import unittest
2523

2624
from transip import TransIP
2725
from transip.v6.objects import SshKey
28-
from tests.utils import load_responses_fixture
26+
from tests.utils import load_responses_fixtures
2927

3028

31-
@pytest.mark.usefixtures("minimal_client_class")
3229
class SshKeysTest(unittest.TestCase):
3330
"""Test the SshKeyService."""
3431

35-
client: Type[TransIP]
32+
client: TransIP
33+
34+
@classmethod
35+
def setUpClass(cls) -> None:
36+
"""Set up a minimal TransIP client for using the ssh-key services."""
37+
cls.client = TransIP(access_token='ACCESS_TOKEN')
3638

37-
def setUp(self):
38-
# Setup mocked responses for the /ssh-keys endpoint
39-
load_responses_fixture("account.json")
39+
def setUp(self) -> None:
40+
"""Setup mocked responses for the '/ssh-keys' endpoint."""
41+
load_responses_fixtures("account.json")
4042

4143
@responses.activate
4244
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+
ssh_keys: List[SshKey] = self.client.ssh_keys.list()
46+
ssh_key: SshKey = ssh_keys[0]
4547

4648
assert len(ssh_keys) == 1
4749
assert ssh_key.get_id() == 123 # type: ignore
4850

4951
@responses.activate
5052
def test_get(self) -> None:
5153
ssh_key_id: int = 123
52-
ssh_key: Type[SshKey] = self.client.ssh_keys.get(ssh_key_id)
54+
ssh_key: SshKey = self.client.ssh_keys.get(ssh_key_id)
5355

5456
assert ssh_key.get_id() == 123 # type: ignore
5557

@@ -64,7 +66,7 @@ def test_delete(self) -> None:
6466
@responses.activate
6567
def test_delete_object(self) -> None:
6668
ssh_key_id: int = 123
67-
ssh_key: Type[SshKey] = self.client.ssh_keys.get(ssh_key_id)
69+
ssh_key: SshKey = self.client.ssh_keys.get(ssh_key_id)
6870

6971
try:
7072
ssh_key.delete() # type: ignore

tests/test_transip.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2020 Roald Nefs <info@roaldnefs.com>
3+
# Copyright (C) 2020, 2021 Roald Nefs <info@roaldnefs.com>
44
#
55
# This file is part of python-transip.
6-
6+
#
77
# python-transip is free software: you can redistribute it and/or modify
88
# it under the terms of the GNU Lesser General Public License as published by
99
# the Free Software Foundation, either version 3 of the License, or
1010
# (at your option) any later version.
11-
11+
#
1212
# python-transip is distributed in the hope that it will be useful,
1313
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
# GNU Lesser General Public License for more details.
16-
16+
#
1717
# You should have received a copy of the GNU Lesser General Public License
1818
# along with python-transip. If not, see <https://www.gnu.org/licenses/>.
1919

20-
from typing import Type
20+
import unittest
2121

2222
from transip import TransIP
2323

2424

25-
def test_transip_url(transip_minimal_client: Type[TransIP]) -> None:
26-
assert transip_minimal_client.url == "https://api.transip.nl/v6"
25+
class TransIPTest(unittest.TestCase):
26+
"""Test the TransIP client class."""
27+
28+
client: TransIP
29+
30+
@classmethod
31+
def setUpClass(self) -> None:
32+
"""Set up a minimal TransIP client."""
33+
self.client = TransIP(access_token='ACCESS_TOKEN')
34+
35+
def test_base_url(self) -> None:
36+
"""Test the base URL of the API."""
37+
url: str = self.client.url
38+
39+
assert url == "https://api.transip.nl/v6"
40+
41+
def test_authorization_header(self) -> None:
42+
"""Test if the Authorization header is set correctly."""
43+
auth_header: str = self.client.headers["Authorization"]
44+
45+
assert auth_header == "Bearer ACCESS_TOKEN"

0 commit comments

Comments
 (0)