Skip to content

Commit ae6b4d4

Browse files
authored
Rename hcloudAPIException to APIException (#22)
Because it looks a little bit funny to have a `hcloud.hcloud.HcloudAPIException` raised
1 parent f4097f6 commit ae6b4d4

6 files changed

Lines changed: 13 additions & 13 deletions

File tree

hcloud/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
22

3-
from .hcloud import HcloudClient, HcloudAPIException # noqa
3+
from .hcloud import HcloudClient, APIException # noqa

hcloud/floating_ips/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def update(self, floating_ip, description=None, labels=None):
155155
def delete(self, floating_ip):
156156
# type: (FloatingIP) -> bool
157157
self._client.request(url="/floating_ips/{floating_ip_id}".format(floating_ip_id=floating_ip.id), method="DELETE")
158-
# Return allays true, because the API does not return an action for it. When an error occurs a HcloudAPIException will be raised
158+
# Return allays true, because the API does not return an action for it. When an error occurs a APIException will be raised
159159
return True
160160

161161
def change_protection(self, floating_ip, delete=None):

hcloud/hcloud.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .version import VERSION, USER_AGENT_PREFIX
1919

2020

21-
class HcloudAPIException(Exception):
21+
class APIException(Exception):
2222
def __init__(self, code, message, details):
2323
self.code = code
2424
self.message = message
@@ -69,7 +69,7 @@ def _get_headers(self):
6969
return headers
7070

7171
def _raise_exception_from_response(self, response):
72-
raise HcloudAPIException(
72+
raise APIException(
7373
code=response.status_code,
7474
message=response.reason,
7575
details={
@@ -78,7 +78,7 @@ def _raise_exception_from_response(self, response):
7878
)
7979

8080
def _raise_exception_from_json_content(self, json_content):
81-
raise HcloudAPIException(
81+
raise APIException(
8282
code=json_content['error']['code'],
8383
message=json_content['error']['message'],
8484
details=json_content['error']['details']

hcloud/images/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def update(self, image, description=None, type=None, labels=None):
130130
def delete(self, image):
131131
# type: (Image) -> bool
132132
self._client.request(url="/images/{image_id}".format(image_id=image.id), method="DELETE")
133-
# Return allays true, because the API does not return an action for it. When an error occurs a HcloudAPIException will be raised
133+
# Return allays true, because the API does not return an action for it. When an error occurs a APIException will be raised
134134
return True
135135

136136
def change_protection(self, image, delete=None):

hcloud/ssh_keys/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ def update(self, ssh_key, name=None, labels=None):
7777
def delete(self, ssh_key):
7878
# type: (SSHKey) -> bool
7979
self._client.request(url="/ssh_keys/{ssh_key_id}".format(ssh_key_id=ssh_key.id), method="DELETE")
80-
# Return allays true, because the API does not return an action for it. When an error occurs a HcloudAPIException will be raised
80+
# Return allays true, because the API does not return an action for it. When an error occurs a APIException will be raised
8181
return True

tests/unit/test_hcloud.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import requests
55
import pytest
6-
from hcloud import HcloudClient, HcloudAPIException
6+
from hcloud import HcloudClient, APIException
77

88

99
class TestHetznerClient(object):
@@ -87,7 +87,7 @@ def test_request_ok(self, mocked_requests, client, response):
8787

8888
def test_request_fails(self, mocked_requests, client, fail_response):
8989
mocked_requests.request.return_value = fail_response
90-
with pytest.raises(HcloudAPIException) as exception_info:
90+
with pytest.raises(APIException) as exception_info:
9191
client.request("POST", "http://url.com", params={"argument": "value"}, timeout=2)
9292
error = exception_info.value
9393
assert error.code == "invalid_input"
@@ -99,7 +99,7 @@ def test_request_500(self, mocked_requests, client, fail_response):
9999
fail_response.reason = "Internal Server Error"
100100
fail_response._content = "Internal Server Error"
101101
mocked_requests.request.return_value = fail_response
102-
with pytest.raises(HcloudAPIException) as exception_info:
102+
with pytest.raises(APIException) as exception_info:
103103
client.request("POST", "http://url.com", params={"argument": "value"}, timeout=2)
104104
error = exception_info.value
105105
assert error.code == 500
@@ -111,7 +111,7 @@ def test_request_broken_json_200(self, mocked_requests, client, response):
111111
response.reason = "OK"
112112
response._content = content
113113
mocked_requests.request.return_value = response
114-
with pytest.raises(HcloudAPIException) as exception_info:
114+
with pytest.raises(APIException) as exception_info:
115115
client.request("POST", "http://url.com", params={"argument": "value"}, timeout=2)
116116
error = exception_info.value
117117
assert error.code == 200
@@ -131,7 +131,7 @@ def test_request_500_empty_content(self, mocked_requests, client, fail_response)
131131
fail_response.reason = "Internal Server Error"
132132
fail_response._content = ""
133133
mocked_requests.request.return_value = fail_response
134-
with pytest.raises(HcloudAPIException) as exception_info:
134+
with pytest.raises(APIException) as exception_info:
135135
client.request("POST", "http://url.com", params={"argument": "value"}, timeout=2)
136136
error = exception_info.value
137137
assert error.code == 500
@@ -141,7 +141,7 @@ def test_request_500_empty_content(self, mocked_requests, client, fail_response)
141141
def test_request_limit(self, mocked_requests, client, rate_limit_response):
142142
client.retry_wait_time = 0
143143
mocked_requests.request.return_value = rate_limit_response
144-
with pytest.raises(HcloudAPIException) as exception_info:
144+
with pytest.raises(APIException) as exception_info:
145145
client.request("POST", "http://url.com", params={"argument": "value"}, timeout=2)
146146
error = exception_info.value
147147
assert mocked_requests.request.call_count == 5

0 commit comments

Comments
 (0)