Skip to content

Commit

Permalink
Merge pull request #28 from roaldnefs/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
roaldnefs authored Jan 10, 2021
2 parents 8409252 + 25821fb commit 116ba6d
Show file tree
Hide file tree
Showing 21 changed files with 653 additions and 239 deletions.
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include COPYING COPYING.LESSER README.md
include tox.ini
recursive-include requirements *
recursive-include docs *.py *.rst user/*rst Makefile make.bat
recursive-include docs *.py *.rst user/*rst Makefile make.bat
recursive-include tests/fixtures *.json
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/python-transip?color=187dc1&logo=python&logoColor=white&style=for-the-badge)](https://pypi.org/project/python-transip/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/python-transip?color=187dc1&logo=python&logoColor=white&style=for-the-badge)](https://pypi.org/project/python-transip/)
[![PyPI - Format](https://img.shields.io/pypi/format/python-transip?color=187dc1&logo=python&logoColor=white&style=for-the-badge)](https://pypi.org/project/python-transip/)
[![License](https://img.shields.io/github/license/roaldnefs/python-transip?color=187dc1&style=for-the-badge)](https://raw.githubusercontent.com/roaldnefs/python-transip/main/COPYING)
[![License](https://img.shields.io/github/license/roaldnefs/python-transip?color=187dc1&style=for-the-badge)](https://raw.githubusercontent.com/roaldnefs/python-transip/main/COPYING.LESSER)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/roaldnefs/python-transip/tests?color=187dc1&label=CI&logo=github&style=for-the-badge)](https://github.com/roaldnefs/python-transip/actions)
[![GitHub contributors](https://img.shields.io/github/contributors/roaldnefs/python-transip?color=187dc1&logo=github&style=for-the-badge)](https://github.com/roaldnefs/python-transip/graphs/contributors)

Expand All @@ -12,7 +12,10 @@
```python
>>> import transip
# Initialize a TransIP API client
>>> client = transip.TransIP(access_token="TOKEN")
>>> client = transip.TransIP(
... login="demouser",
... private_key_file="/path/to/private.key"
... )
# Retrieve a list of VPSs
>>> for vps in client.vpss.list():
... print(vps)
Expand Down
5 changes: 4 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ Release v\ |version|. (:ref:`Installation <install>`)

>>> import transip
# Initialize a TransIP API client
>>> client = transip.TransIP(access_token="TOKEN")
>>> client = transip.TransIP(
... login="demouser",
... private_key_file="/path/to/private.key"
... )
# Retrieve a list of VPSs
>>> for vps in client.vpss.list():
... print(vps)
Expand Down
19 changes: 18 additions & 1 deletion docs/user/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ First, make sure that:

* python-transip is :ref:`installed <install>`

Then you should be able to import the module::

>>> import transip

Below you'll find some simple example to get started.

Authentication
Expand All @@ -17,7 +21,20 @@ Authentication
In order to make requests to the TransIP API we need to authenticate yourself
using an access token. To get an access token, you should first login to the
TransIP control panel. You can then generate a new token which will only be
valid for limited time.
valid for limited time or generate a private key to allow python-transip to
request a access token on initialization.

Example of authentication using a private key::

>>> PRIVATE_KEY = """-----BEGIN RSA PRIVATE KEY-----
... ...
... -----END RSA PRIVATE KEY-----"""
>>> client = transip.TransIP(login="demouser", private_key=PRIVATE_KEY)
>>> client = transip.TransIP(login="demouser", private_key_file='/path/to/private.key')

Example authentication using an access token::

>>> client = transip.TransIP(access_token="eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImN3MiFSbDU2eDNoUnkjelM4YmdOIn0.eyJpc3MiOiJhcGkudHJhbnNpcC5ubCIsImF1ZCI6ImFwaS50cmFuc2lwLm5sIiwianRpIjoiY3cyIVJsNTZ4M2hSeSN6UzhiZ04iLCJpYXQiOjE1ODIyMDE1NTAsIm5iZiI6MTU4MjIwMTU1MCwiZXhwIjoyMTE4NzQ1NTUwLCJjaWQiOiI2MDQ0OSIsInJvIjpmYWxzZSwiZ2siOmZhbHNlLCJrdiI6dHJ1ZX0.fYBWV4O5WPXxGuWG-vcrFWqmRHBm9yp0PHiYh_oAWxWxCaZX2Rf6WJfc13AxEeZ67-lY0TA2kSaOCp0PggBb_MGj73t4cH8gdwDJzANVxkiPL1Saqiw2NgZ3IHASJnisUWNnZp8HnrhLLe5ficvb1D9WOUOItmFC2ZgfGObNhlL2y-AMNLT4X7oNgrNTGm-mespo0jD_qH9dK5_evSzS3K8o03gu6p19jxfsnIh8TIVRvNdluYC2wo4qDl5EW5BEZ8OSuJ121ncOT1oRpzXB0cVZ9e5_UVAEr9X3f26_Eomg52-PjrgcRJ_jPIUYbrlo06KjjX2h0fzMr21ZE023Gw")

TransIP also provide a **demo token** to authenticate yourself as the TransIP
demo user in test mode::
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def get_long_description() -> str:
license="LGPLv3",
url="https://github.com/roaldnefs/python-transip",
packages=find_packages(),
install_requires=["requests>=2.25.1"],
include_package_data=True,
install_requires=["cryptography>=3.3.1", "requests>=2.25.1"],
python_requires=">=3.6.12",
entry_points={},
classifiers=[
Expand All @@ -44,4 +45,4 @@ def get_long_description() -> str:
"Programming Language :: Python :: 3.9",
],
extras_require={},
)
)
38 changes: 0 additions & 38 deletions tests/conftest.py

This file was deleted.

4 changes: 2 additions & 2 deletions tests/fixtures/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"url": "https://api.transip.nl/v6/ssh-keys",
"status": 201,
"content_type": "application/json",
"match_json": {
"match_json_params": {
"sshKey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDf2pxWX/yhUBDyk2LPhvRtI0LnVO8PyR5Zt6AHrnhtLGqK+8YG9EMlWbCCWrASR+Q1hFQG example",
"description": "Jim key"
}
Expand All @@ -120,7 +120,7 @@
"url": "https://api.transip.nl/v6/ssh-keys/123",
"status": 204,
"content_type": "application/json",
"match_json": {
"match_json_params": {
"description": "Jim key"
}
},
Expand Down
11 changes: 11 additions & 0 deletions tests/fixtures/auth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"method": "POST",
"url": "https://api.transip.nl/v6/auth",
"json": {
"token": "ACCESS_TOKEN"
},
"status": 200,
"content_type": "application/json"
}
]
6 changes: 3 additions & 3 deletions tests/fixtures/colocations.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"url": "https://api.transip.nl/v6/colocations/example2/ip-addresses",
"status": 201,
"content_type": "application/json",
"match_json": {
"match_json_params": {
"ipAddress": "2a01:7c8:3:1337::6",
"reverseDns": "example.com"
}
Expand All @@ -78,7 +78,7 @@
"url": "https://api.transip.nl/v6/colocations/example2/ip-addresses/37.97.254.6",
"status": 204,
"content_type": "application/json",
"match_json": {
"match_json_params": {
"ipAddress": {
"address": "37.97.254.6",
"subnetMask": "255.255.255.0",
Expand All @@ -102,7 +102,7 @@
"url": "https://api.transip.nl/v6/colocations/example2/remote-hands",
"status": 201,
"content_type": "application/json",
"match_json": {
"match_json_params": {
"remoteHands": {
"coloName": "example2",
"contactName": "Herman Kaakdorst",
Expand Down
16 changes: 8 additions & 8 deletions tests/fixtures/domains.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"url": "https://api.transip.nl/v6/domains",
"status": 201,
"content_type": "application/json",
"match_json": {
"match_json_params": {
"domainName": "example.com",
"contacts": [
{
Expand Down Expand Up @@ -94,7 +94,7 @@
"url": "https://api.transip.nl/v6/domains",
"status": 201,
"content_type": "application/json",
"match_json": {
"match_json_params": {
"domainName": "example.com",
"authCode": "CYPMaVH+9MRjXGBc3InzHs7vNSUBPOjwpZm3GO+iDLHnFLtiP7sOKqW5JD1WeUpevZM6q1qS5YH9dGSp",
"contacts": [
Expand Down Expand Up @@ -137,7 +137,7 @@
"url": "https://api.transip.nl/v6/domains/example.com",
"status": 204,
"content_type": "application/json",
"match_json": {
"match_json_params": {
"domain": {
"name": "example.com",
"authCode": "kJqfuOXNOYQKqh/jO4bYSn54YDqgAt1ksCe+ZG4Ud4nfpzw8qBsfR2JqAj7Ce12SxKcGD09v+yXd6lrm",
Expand All @@ -160,7 +160,7 @@
"url": "https://api.transip.nl/v6/domains/example.com",
"status": 204,
"content_type": "application/json",
"match_json": {
"match_json_params": {
"endTime": "end"
}
},
Expand All @@ -186,7 +186,7 @@
"url": "https://api.transip.nl/v6/domains/example.com/branding",
"status": 204,
"content_type": "application/json",
"match_json": {
"match_json_params": {
"branding": {
"companyName": "Example B.V.",
"supportEmail": "[email protected]",
Expand Down Expand Up @@ -229,7 +229,7 @@
"url": "https://api.transip.nl/v6/domains/example.com/contacts",
"status": 204,
"content_type": "application/json",
"match_json": {
"match_json_params": {
"contacts": [
{
"type": "registrant",
Expand Down Expand Up @@ -271,7 +271,7 @@
"url": "https://api.transip.nl/v6/domains/example.com/dns",
"status": 201,
"content_type": "application/json",
"match_json": {
"match_json_params": {
"dnsEntry": {
"name": "www",
"expire": 86400,
Expand Down Expand Up @@ -300,7 +300,7 @@
"url": "https://api.transip.nl/v6/domains/example.com/nameservers",
"status": 204,
"content_type": "application/json",
"match_json": {
"match_json_params": {
"nameservers": [
{
"hostname": "ns0.transip.nl",
Expand Down
49 changes: 26 additions & 23 deletions tests/services/test_domains.py
Original file line number Diff line number Diff line change
@@ -1,72 +1,75 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020 Roald Nefs <[email protected]>
# Copyright (C) 2020, 2012 Roald Nefs <[email protected]>
#
# This file is part of python-transip.

#
# python-transip is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

#
# python-transip is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.

#
# You should have received a copy of the GNU Lesser General Public License
# along with python-transip. If not, see <https://www.gnu.org/licenses/>.

import responses # type: ignore
import unittest
import pytest

from typing import Type, List, Dict, Any, Union
from typing import List, Dict, Any, Union

from transip import TransIP
from transip.v6.objects import Domain, WhoisContact, Nameserver, DnsEntry
from tests.utils import load_responses_fixture
from tests.utils import load_responses_fixtures


@pytest.mark.usefixtures("minimal_client_class")
class DomainsTest(unittest.TestCase):
"""Test the DomainService."""

client: Type[TransIP]
client: TransIP

@classmethod
def setUpClass(cls) -> None:
"""Set up a minimal TransIP client for using the domain services."""
cls.client = TransIP(access_token='ACCESS_TOKEN')

def setUp(self):
# Setup mocked responses for the /domains endpoint
load_responses_fixture("domains.json")
def setUp(self) -> None:
"""Setup mocked responses for the '/domains' endpoint."""
load_responses_fixtures("domains.json")

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

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

@responses.activate
def test_contacts_list(self) -> None:
domain: Type[Domain] = self.client.domains.get("example.com")
contacts: List[Type[Domain]] = domain.contacts.list() # type: ignore
contact: Type[Domain] = contacts[0]
domain: Domain = self.client.domains.get("example.com")
contacts: List[Domain] = domain.contacts.list() # type: ignore
contact: Domain = contacts[0]

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

@responses.activate
def test_nameservers_list(self) -> None:
domain: Type[Domain] = self.client.domains.get("example.com")
nameservers: List[Type[Nameserver]] = domain.nameservers.list() # type: ignore
nameserver: Type[Nameserver] = nameservers[0]
domain: Domain = self.client.domains.get("example.com")
nameservers: List[Nameserver] = domain.nameservers.list() # type: ignore
nameserver: Nameserver = nameservers[0]

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

@responses.activate
def test_dns_list(self) -> None:
domain: Type[Domain] = self.client.domains.get("example.com")
entries: List[Type[DnsEntry]] = domain.dns.list() # type: ignore
entry: Type[DnsEntry] = entries[0]
domain: Domain = self.client.domains.get("example.com")
entries: List[DnsEntry] = domain.dns.list() # type: ignore
entry: DnsEntry = entries[0]

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

assert len(responses.calls) == 2
Loading

0 comments on commit 116ba6d

Please sign in to comment.