Skip to content

Commit 6eeb701

Browse files
author
Moritz Pein
committed
Merge branch 'bugfix/fix-error-object-marshalling'
2 parents 7f19882 + f41d4c9 commit 6eeb701

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

figo/figo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ def from_dict(cls, dictionary):
207207
"""
208208
Helper function creating an exception instance from the dictionary returned by the server.
209209
"""
210-
return cls(dictionary['error']['message'],
211-
dictionary['error']['description'],
210+
return cls(dictionary['error'].get('message'),
211+
dictionary['error'].get('description'),
212212
dictionary['error'].get('code'))
213213

214214

tests/test_models.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import pytest
2+
3+
from figo import FigoException
14
from figo.models import Account
25
from figo.models import AccountBalance
36
from figo.models import BankContact
@@ -19,6 +22,10 @@
1922
from figo.models import Transaction
2023
from figo.models import User
2124

25+
from tests.test_writing_methods import CLIENT_ERROR
26+
27+
HTTP_NOT_ACCEPTABLE = 406
28+
2229

2330
def test_create_account_from_dict(demo_session):
2431
data = {"account_id": "A1.1",
@@ -399,3 +406,34 @@ def test_create_security_from_dict(demo_session):
399406
}
400407
security = Security.from_dict(demo_session, data)
401408
assert isinstance(security, Security)
409+
410+
OLD_ERROR_FORMAT = {
411+
'error': {
412+
'code': None,
413+
'data': {},
414+
'description': None,
415+
'group': 'unknown',
416+
'message': 'Unsupported language',
417+
'name': 'Not Acceptable'
418+
},
419+
'status': HTTP_NOT_ACCEPTABLE
420+
}
421+
NEW_ERROR_FORMAT = {
422+
'error': {
423+
'code': CLIENT_ERROR,
424+
'data': {},
425+
'description': 'Unsupported language',
426+
'group': 'client'
427+
},
428+
'status': HTTP_NOT_ACCEPTABLE
429+
}
430+
431+
432+
@pytest.mark.parametrize('payload', [
433+
OLD_ERROR_FORMAT,
434+
NEW_ERROR_FORMAT,
435+
])
436+
def test_create_figo_exception_from_dict(payload):
437+
exc = FigoException.from_dict(payload)
438+
assert isinstance(exc, FigoException)
439+

tests/test_writing_methods.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
CREDENTIALS = ["figo", "figo"]
1717
BANK_CODE = "90090042"
18+
CLIENT_ERROR = 1000
1819

1920

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

4243

4344
def test_get_supported_payment_services(figo_session):

0 commit comments

Comments
 (0)