Skip to content

Commit

Permalink
exception TimeExceeded added (#185)
Browse files Browse the repository at this point in the history
* exception TimeExceeded added

* exception GatewayTimeout added

* exception GatewayTimeOut added
  • Loading branch information
alanalmonasi authored Oct 24, 2022
1 parent 9316baa commit 8076384
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
10 changes: 9 additions & 1 deletion arcus/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@

from .api_keys import ApiKey
from .auth import compute_auth_header, compute_date_header, compute_md5_header
from .exc import Forbidden, InvalidAuth, NotFound, UnprocessableEntity
from .exc import (
Forbidden,
GatewayTimeOut,
InvalidAuth,
NotFound,
UnprocessableEntity,
)
from .resources import (
Account,
Bill,
Expand Down Expand Up @@ -142,6 +148,8 @@ def _build_headers(
def _check_response(response):
if response.ok:
return
if response.status_code == 504:
raise GatewayTimeOut
data = response.json()
if response.status_code == 401:
raise InvalidAuth
Expand Down
4 changes: 4 additions & 0 deletions arcus/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class InvalidAuth(ArcusException):
"""Invalid API authentication credentials"""


class GatewayTimeOut(ArcusException):
"""The server didn't respond in time"""


class InvalidBiller(ArcusException):
def __init__(self, biller_id: Union[int, str], **kwargs):
self.message = f'{biller_id} is an invalid biller_id'
Expand Down
2 changes: 1 addition & 1 deletion arcus/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.2.10' # pragma: no cover
__version__ = '1.2.11' # pragma: no cover
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pytest==6.2.*
pytest-vcr==1.0.*
pytest-cov==3.0.*
black==22.1.0
black==22.3.0
isort==5.10.*
flake8==4.0.*
mypy==0.790
Expand Down
12 changes: 12 additions & 0 deletions tests/resources/test_bills.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from unittest.mock import Mock, patch

import pytest
from requests.models import Response

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


def test_gateway_time_out(client):
with patch('requests.Session.request') as mock_request:
res = Response()
res.status_code = 504
mock_request.side_effect = Mock(return_value=res)
with pytest.raises(exc.GatewayTimeOut):
client.bills.create(40, '501000000007')


@pytest.mark.vcr
def test_invalid_account_number(client):
biller_id = 40
Expand Down

0 comments on commit 8076384

Please sign in to comment.