|
17 | 17 | # You should have received a copy of the GNU Lesser General Public License |
18 | 18 | # along with python-transip. If not, see <https://www.gnu.org/licenses/>. |
19 | 19 |
|
20 | | -from typing import Type, List |
21 | 20 | import responses # type: ignore |
| 21 | +import unittest |
| 22 | +import pytest |
| 23 | + |
| 24 | +from typing import Type, List, Dict, Any, Union |
22 | 25 |
|
23 | 26 | from transip import TransIP |
24 | 27 | from transip.v6.services.domain import ( |
25 | 28 | Domain, WhoisContact, Nameserver, DnsEntry |
26 | 29 | ) |
27 | | - |
28 | | - |
29 | | -@responses.activate |
30 | | -def test_domains_get(transip_minimal_client: Type[TransIP]) -> None: |
31 | | - responses.add( |
32 | | - responses.GET, |
33 | | - "https://api.transip.nl/v6/domains/example.com", |
34 | | - json={ |
35 | | - "domain": { |
36 | | - "name": "example.com", |
37 | | - "authCode": "kJqfuOXNOYQKqh/jO4bYSn54YDqgAt1ksCe+ZG4Ud4nfpzw8qBsfR2JqAj7Ce12SxKcGD09v+yXd6lrm", |
38 | | - "isTransferLocked": False, |
39 | | - "registrationDate": "2016-01-01", |
40 | | - "renewalDate": "2020-01-01", |
41 | | - "isWhitelabel": False, |
42 | | - "cancellationDate": "2020-01-01 12:00:00", |
43 | | - "cancellationStatus": "signed", |
44 | | - "isDnsOnly": False, |
45 | | - "tags": [ |
46 | | - "customTag", |
47 | | - "anotherTag" |
48 | | - ] |
49 | | - } |
50 | | - }, |
51 | | - status=200, |
52 | | - ) |
53 | | - |
54 | | - domain: Type[Domain] = transip_minimal_client.domains.get("example.com") |
55 | | - assert domain.get_id() == "example.com" # type: ignore |
56 | | - |
57 | | -@responses.activate |
58 | | -def test_domains_contacts_list(transip_minimal_client: Type[TransIP]) -> None: |
59 | | - responses.add( |
60 | | - responses.GET, |
61 | | - "https://api.transip.nl/v6/domains/example.com", |
62 | | - json={ |
63 | | - "domain": { |
64 | | - "name": "example.com", |
65 | | - "authCode": "kJqfuOXNOYQKqh/jO4bYSn54YDqgAt1ksCe+ZG4Ud4nfpzw8qBsfR2JqAj7Ce12SxKcGD09v+yXd6lrm", |
66 | | - "isTransferLocked": False, |
67 | | - "registrationDate": "2016-01-01", |
68 | | - "renewalDate": "2020-01-01", |
69 | | - "isWhitelabel": False, |
70 | | - "cancellationDate": "2020-01-01 12:00:00", |
71 | | - "cancellationStatus": "signed", |
72 | | - "isDnsOnly": False, |
73 | | - "tags": [ |
74 | | - "customTag", |
75 | | - "anotherTag" |
76 | | - ] |
77 | | - } |
78 | | - }, |
79 | | - status=200, |
80 | | - ) |
81 | | - responses.add( |
82 | | - responses.GET, |
83 | | - "https://api.transip.nl/v6/domains/example.com/contacts", |
84 | | - json={ |
85 | | - "contacts": [ |
86 | | - { |
87 | | - "type": "registrant", |
88 | | - "firstName": "John", |
89 | | - "lastName": "Doe", |
90 | | - "companyName": "Example B.V.", |
91 | | - "companyKvk": "83057825", |
92 | | - "companyType": "BV", |
93 | | - "street": "Easy street", |
94 | | - "number": "12", |
95 | | - "postalCode": "1337 XD", |
96 | | - "city": "Leiden", |
97 | | - "phoneNumber": "+31 715241919", |
98 | | - "faxNumber": "+31 715241919", |
99 | | - "email": "example@example.com", |
100 | | - "country": "nl" |
101 | | - } |
102 | | - ] |
103 | | - }, |
104 | | - status=200, |
105 | | - ) |
106 | | - |
107 | | - domain: Type[Domain] = transip_minimal_client.domains.get("example.com") |
108 | | - contacts: List[Type[Domain]] = domain.contacts.list() # type: ignore |
109 | | - contact: Type[Domain] = contacts[0] |
110 | | - assert len(contacts) == 1 |
111 | | - assert contact.companyName == "Example B.V." # type: ignore |
112 | | - |
113 | | - |
114 | | -@responses.activate |
115 | | -def test_domains_nameservers_list(transip_minimal_client: Type[TransIP]) -> None: |
116 | | - responses.add( |
117 | | - responses.GET, |
118 | | - "https://api.transip.nl/v6/domains/example.com", |
119 | | - json={ |
120 | | - "domain": { |
121 | | - "name": "example.com", |
122 | | - "authCode": "kJqfuOXNOYQKqh/jO4bYSn54YDqgAt1ksCe+ZG4Ud4nfpzw8qBsfR2JqAj7Ce12SxKcGD09v+yXd6lrm", |
123 | | - "isTransferLocked": False, |
124 | | - "registrationDate": "2016-01-01", |
125 | | - "renewalDate": "2020-01-01", |
126 | | - "isWhitelabel": False, |
127 | | - "cancellationDate": "2020-01-01 12:00:00", |
128 | | - "cancellationStatus": "signed", |
129 | | - "isDnsOnly": False, |
130 | | - "tags": [ |
131 | | - "customTag", |
132 | | - "anotherTag" |
133 | | - ] |
134 | | - } |
135 | | - }, |
136 | | - status=200, |
137 | | - ) |
138 | | - responses.add( |
139 | | - responses.GET, |
140 | | - "https://api.transip.nl/v6/domains/example.com/nameservers", |
141 | | - json={ |
142 | | - "nameservers": [ |
143 | | - { |
144 | | - "hostname": "ns0.transip.nl", |
145 | | - "ipv4": "", |
146 | | - "ipv6": "" |
147 | | - } |
148 | | - ] |
149 | | - }, |
150 | | - status=200, |
151 | | - ) |
152 | | - |
153 | | - domain: Type[Domain] = transip_minimal_client.domains.get("example.com") |
154 | | - nameservers: List[Type[Nameserver]] = domain.nameservers.list() # type: ignore |
155 | | - nameserver: Type[Nameserver] = nameservers[0] |
156 | | - assert len(nameservers) == 1 |
157 | | - assert nameserver.get_id() == "ns0.transip.nl" # type: ignore |
158 | | - |
159 | | - |
160 | | -@responses.activate |
161 | | -def test_domains_dns_list(transip_minimal_client: Type[TransIP]) -> None: |
162 | | - responses.add( |
163 | | - responses.GET, |
164 | | - "https://api.transip.nl/v6/domains/example.com", |
165 | | - json={ |
166 | | - "domain": { |
167 | | - "name": "example.com", |
168 | | - "authCode": "kJqfuOXNOYQKqh/jO4bYSn54YDqgAt1ksCe+ZG4Ud4nfpzw8qBsfR2JqAj7Ce12SxKcGD09v+yXd6lrm", |
169 | | - "isTransferLocked": False, |
170 | | - "registrationDate": "2016-01-01", |
171 | | - "renewalDate": "2020-01-01", |
172 | | - "isWhitelabel": False, |
173 | | - "cancellationDate": "2020-01-01 12:00:00", |
174 | | - "cancellationStatus": "signed", |
175 | | - "isDnsOnly": False, |
176 | | - "tags": [ |
177 | | - "customTag", |
178 | | - "anotherTag" |
179 | | - ] |
180 | | - } |
181 | | - }, |
182 | | - status=200, |
183 | | - ) |
184 | | - responses.add( |
185 | | - responses.GET, |
186 | | - "https://api.transip.nl/v6/domains/example.com/dns", |
187 | | - json={ |
188 | | - "dnsEntries": [ |
189 | | - { |
190 | | - "name": "www", |
191 | | - "expire": 86400, |
192 | | - "type": "A", |
193 | | - "content": "127.0.0.1" |
194 | | - } |
| 30 | +from tests.utils import load_fixture |
| 31 | + |
| 32 | + |
| 33 | +@pytest.mark.usefixtures("minimal_client_class") |
| 34 | +class DomainsTest(unittest.TestCase): |
| 35 | + """Test the DomainService.""" |
| 36 | + |
| 37 | + client: Type[TransIP] |
| 38 | + |
| 39 | + def setUp(self): |
| 40 | + # Setup mocked responses for the /domains endpoint |
| 41 | + responses.add( |
| 42 | + responses.GET, "https://api.transip.nl/v6/domains/example.com", |
| 43 | + json=load_fixture("domains_get.json"), status=200, |
| 44 | + content_type='application/json', |
| 45 | + ) |
| 46 | + responses.add( |
| 47 | + responses.GET, |
| 48 | + "https://api.transip.nl/v6/domains/example.com/contacts", |
| 49 | + json=load_fixture("contacts_list.json"), status=200, |
| 50 | + content_type='application/json', |
| 51 | + ) |
| 52 | + responses.add( |
| 53 | + responses.GET, |
| 54 | + "https://api.transip.nl/v6/domains/example.com/nameservers", |
| 55 | + json=load_fixture("nameservers_list.json"), status=200, |
| 56 | + content_type='application/json', |
| 57 | + ) |
| 58 | + responses.add( |
| 59 | + responses.GET, "https://api.transip.nl/v6/domains/example.com/dns", |
| 60 | + json=load_fixture("dns_list.json"), status=200, |
| 61 | + content_type='application/json', |
| 62 | + ) |
| 63 | + responses.add( |
| 64 | + responses.POST, "https://api.transip.nl/v6/domains/example.com/dns", |
| 65 | + status=201, content_type='application/json', |
| 66 | + match=[ |
| 67 | + responses.json_params_matcher(load_fixture("dns_create.json")), |
195 | 68 | ] |
196 | | - }, |
197 | | - status=200, |
198 | 69 | ) |
199 | 70 |
|
200 | | - domain: Type[Domain] = transip_minimal_client.domains.get("example.com") |
201 | | - entries: List[Type[DnsEntry]] = domain.dns.list() # type: ignore |
202 | | - entry: Type[DnsEntry] = entries[0] |
203 | | - assert len(entries) == 1 |
204 | | - assert entry.name == "www" # type: ignore |
| 71 | + @responses.activate |
| 72 | + def test_get(self) -> None: |
| 73 | + domain: Type[Domain] = self.client.domains.get("example.com") |
| 74 | + |
| 75 | + assert domain.get_id() == "example.com" # type: ignore |
| 76 | + |
| 77 | + @responses.activate |
| 78 | + def test_contacts_list(self) -> None: |
| 79 | + domain: Type[Domain] = self.client.domains.get("example.com") |
| 80 | + contacts: List[Type[Domain]] = domain.contacts.list() # type: ignore |
| 81 | + contact: Type[Domain] = contacts[0] |
| 82 | + |
| 83 | + assert len(contacts) == 1 |
| 84 | + assert contact.companyName == "Example B.V." # type: ignore |
| 85 | + |
| 86 | + @responses.activate |
| 87 | + def test_nameservers_list(self) -> None: |
| 88 | + domain: Type[Domain] = self.client.domains.get("example.com") |
| 89 | + nameservers: List[Type[Nameserver]] = domain.nameservers.list() # type: ignore |
| 90 | + nameserver: Type[Nameserver] = nameservers[0] |
| 91 | + |
| 92 | + assert len(nameservers) == 1 |
| 93 | + assert nameserver.get_id() == "ns0.transip.nl" # type: ignore |
| 94 | + |
| 95 | + @responses.activate |
| 96 | + def test_dns_list(self) -> None: |
| 97 | + domain: Type[Domain] = self.client.domains.get("example.com") |
| 98 | + entries: List[Type[DnsEntry]] = domain.dns.list() # type: ignore |
| 99 | + entry: Type[DnsEntry] = entries[0] |
| 100 | + |
| 101 | + assert len(entries) == 1 |
| 102 | + assert entry.name == "www" # type: ignore |
| 103 | + |
| 104 | + @responses.activate |
| 105 | + def test_dns_create(self) -> None: |
| 106 | + dns_entry_data: Dict[str, Union[str, int]] = { |
| 107 | + "name": "www", |
| 108 | + "expire": 86400, |
| 109 | + "type": "A", |
| 110 | + "content": "127.0.0.1" |
| 111 | + } |
| 112 | + domain: Type[Domain] = self.client.domains.get("example.com") |
| 113 | + domain.dns.create(dns_entry_data) # type: ignore |
| 114 | + |
| 115 | + assert len(responses.calls) == 2 |
0 commit comments