Skip to content

Commit 8076384

Browse files
authored
exception TimeExceeded added (#185)
* exception TimeExceeded added * exception GatewayTimeout added * exception GatewayTimeOut added
1 parent 9316baa commit 8076384

5 files changed

Lines changed: 27 additions & 3 deletions

File tree

arcus/client.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55

66
from .api_keys import ApiKey
77
from .auth import compute_auth_header, compute_date_header, compute_md5_header
8-
from .exc import Forbidden, InvalidAuth, NotFound, UnprocessableEntity
8+
from .exc import (
9+
Forbidden,
10+
GatewayTimeOut,
11+
InvalidAuth,
12+
NotFound,
13+
UnprocessableEntity,
14+
)
915
from .resources import (
1016
Account,
1117
Bill,
@@ -142,6 +148,8 @@ def _build_headers(
142148
def _check_response(response):
143149
if response.ok:
144150
return
151+
if response.status_code == 504:
152+
raise GatewayTimeOut
145153
data = response.json()
146154
if response.status_code == 401:
147155
raise InvalidAuth

arcus/exc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class InvalidAuth(ArcusException):
1111
"""Invalid API authentication credentials"""
1212

1313

14+
class GatewayTimeOut(ArcusException):
15+
"""The server didn't respond in time"""
16+
17+
1418
class InvalidBiller(ArcusException):
1519
def __init__(self, biller_id: Union[int, str], **kwargs):
1620
self.message = f'{biller_id} is an invalid biller_id'

arcus/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.2.10' # pragma: no cover
1+
__version__ = '1.2.11' # pragma: no cover

requirements-test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pytest==6.2.*
22
pytest-vcr==1.0.*
33
pytest-cov==3.0.*
4-
black==22.1.0
4+
black==22.3.0
55
isort==5.10.*
66
flake8==4.0.*
77
mypy==0.790

tests/resources/test_bills.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
from unittest.mock import Mock, patch
2+
13
import pytest
4+
from requests.models import Response
25

36
from arcus import exc
47
from arcus.resources import Bill
@@ -20,6 +23,15 @@ def test_invalid_biller_id(client):
2023
client.bills.create(invalid_biller_id, '1234')
2124

2225

26+
def test_gateway_time_out(client):
27+
with patch('requests.Session.request') as mock_request:
28+
res = Response()
29+
res.status_code = 504
30+
mock_request.side_effect = Mock(return_value=res)
31+
with pytest.raises(exc.GatewayTimeOut):
32+
client.bills.create(40, '501000000007')
33+
34+
2335
@pytest.mark.vcr
2436
def test_invalid_account_number(client):
2537
biller_id = 40

0 commit comments

Comments
 (0)