Skip to content

Commit 68ec9f9

Browse files
authored
Merge pull request #17 from roaldnefs/15-add-create-mixin
2 parents 85b5c73 + fbc3fd4 commit 68ec9f9

13 files changed

Lines changed: 320 additions & 185 deletions

File tree

docs/user/quickstart.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ single :class:`Domain <transip.v6.services.domain.Domain>` object by its name::
114114
<class 'transip.v6.services.domain.DnsEntry'> => {'name': 'www', 'expire': 86400, 'type': 'CNAME', 'content': '@'}
115115
<class 'transip.v6.services.domain.DnsEntry'> => {'name': '_dmarc', 'expire': 86400, 'type': 'TXT', 'content': 'v=DMARC1; p=none;'}
116116

117+
118+
It's also possible to create a new DNS entry for a single
119+
:class:`Domain <transip.v6.services.domain.Domain>`::
120+
121+
>>> domain = client.domains.get('transipdemonstratie.nl')
122+
>>> dns_entry_data = {
123+
... "name": "www",
124+
... "expire": 86400,
125+
... "type": "A",
126+
... "content": "127.0.0.1"
127+
... }
128+
>>> domain.dns.create(dns_entry_data)
129+
130+
117131
Domain Contacts
118132
***************
119133

tests/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
from transip import TransIP
2525

2626

27+
@pytest.fixture(scope="class")
28+
def minimal_client_class(request):
29+
request.cls.client = TransIP(
30+
access_token="access_token"
31+
)
32+
33+
2734
@pytest.fixture
2835
def transip_minimal_client() -> TransIP:
2936
return TransIP(

tests/fixtures/contacts_list.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"contacts": [
3+
{
4+
"type": "registrant",
5+
"firstName": "John",
6+
"lastName": "Doe",
7+
"companyName": "Example B.V.",
8+
"companyKvk": "83057825",
9+
"companyType": "BV",
10+
"street": "Easy street",
11+
"number": "12",
12+
"postalCode": "1337 XD",
13+
"city": "Leiden",
14+
"phoneNumber": "+31 715241919",
15+
"faxNumber": "+31 715241919",
16+
"email": "example@example.com",
17+
"country": "nl"
18+
}
19+
]
20+
}

tests/fixtures/dns_create.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"dnsEntry": {
3+
"name": "www",
4+
"expire": 86400,
5+
"type": "A",
6+
"content": "127.0.0.1"
7+
}
8+
}

tests/fixtures/dns_list.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"dnsEntries": [
3+
{
4+
"name": "www",
5+
"expire": 86400,
6+
"type": "A",
7+
"content": "127.0.0.1"
8+
}
9+
]
10+
}

tests/fixtures/domains_get.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"domain": {
3+
"name": "example.com",
4+
"authCode": "kJqfuOXNOYQKqh/jO4bYSn54YDqgAt1ksCe+ZG4Ud4nfpzw8qBsfR2JqAj7Ce12SxKcGD09v+yXd6lrm",
5+
"isTransferLocked": false,
6+
"registrationDate": "2016-01-01",
7+
"renewalDate": "2020-01-01",
8+
"isWhitelabel": false,
9+
"cancellationDate": "2020-01-01 12:00:00",
10+
"cancellationStatus": "signed",
11+
"isDnsOnly": false,
12+
"tags": [
13+
"customTag",
14+
"anotherTag"
15+
]
16+
}
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"nameservers": [
3+
{
4+
"hostname": "ns0.transip.nl",
5+
"ipv4": "",
6+
"ipv6": ""
7+
}
8+
]
9+
}

tests/services/test_domains.py

Lines changed: 87 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -17,188 +17,99 @@
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
2120
import responses # type: ignore
21+
import unittest
22+
import pytest
23+
24+
from typing import Type, List, Dict, Any, Union
2225

2326
from transip import TransIP
2427
from transip.v6.services.domain import (
2528
Domain, WhoisContact, Nameserver, DnsEntry
2629
)
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")),
19568
]
196-
},
197-
status=200,
19869
)
19970

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

Comments
 (0)