Skip to content

Commit

Permalink
Merge branch 'bugfix/fix-error-object-marshalling'
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Pein committed Oct 23, 2017
2 parents 7f19882 + f41d4c9 commit 6eeb701
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
4 changes: 2 additions & 2 deletions figo/figo.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ def from_dict(cls, dictionary):
"""
Helper function creating an exception instance from the dictionary returned by the server.
"""
return cls(dictionary['error']['message'],
dictionary['error']['description'],
return cls(dictionary['error'].get('message'),
dictionary['error'].get('description'),
dictionary['error'].get('code'))


Expand Down
38 changes: 38 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pytest

from figo import FigoException
from figo.models import Account
from figo.models import AccountBalance
from figo.models import BankContact
Expand All @@ -19,6 +22,10 @@
from figo.models import Transaction
from figo.models import User

from tests.test_writing_methods import CLIENT_ERROR

HTTP_NOT_ACCEPTABLE = 406


def test_create_account_from_dict(demo_session):
data = {"account_id": "A1.1",
Expand Down Expand Up @@ -399,3 +406,34 @@ def test_create_security_from_dict(demo_session):
}
security = Security.from_dict(demo_session, data)
assert isinstance(security, Security)

OLD_ERROR_FORMAT = {
'error': {
'code': None,
'data': {},
'description': None,
'group': 'unknown',
'message': 'Unsupported language',
'name': 'Not Acceptable'
},
'status': HTTP_NOT_ACCEPTABLE
}
NEW_ERROR_FORMAT = {
'error': {
'code': CLIENT_ERROR,
'data': {},
'description': 'Unsupported language',
'group': 'client'
},
'status': HTTP_NOT_ACCEPTABLE
}


@pytest.mark.parametrize('payload', [
OLD_ERROR_FORMAT,
NEW_ERROR_FORMAT,
])
def test_create_figo_exception_from_dict(payload):
exc = FigoException.from_dict(payload)
assert isinstance(exc, FigoException)

3 changes: 2 additions & 1 deletion tests/test_writing_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

CREDENTIALS = ["figo", "figo"]
BANK_CODE = "90090042"
CLIENT_ERROR = 1000


# XXX(Valentin): Catalog needs `accounts=rw`, so it doesn't work with the demo session.
Expand All @@ -37,7 +38,7 @@ def test_get_catalog_invalid_language(figo_session):
figo_session.language = 'xy'
with pytest.raises(FigoException) as e:
figo_session.get_catalog()
assert e.value.code is None
assert e.value.code == CLIENT_ERROR


def test_get_supported_payment_services(figo_session):
Expand Down

0 comments on commit 6eeb701

Please sign in to comment.