Skip to content

Commit

Permalink
fix: task_start is not called with response.json() anymore
Browse files Browse the repository at this point in the history
test scope reduced,
task_start deprecated
  • Loading branch information
Berend Kapelle committed Feb 27, 2018
1 parent e6e4897 commit dd8a66f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
CHANGES
=======

* most of pep8
* clean up of conftest
* added a test for get\_bank
* clean conftest, moved all catalog and header tests to own file
* making tests green
Expand Down
2 changes: 1 addition & 1 deletion figo/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DEMO_CREDENTIALS = {
'client_id': 'C-9rtYgOP3mjHhw0qu6Tx9fgk9JfZGmbMqn-rnDZnZwI',
'client_secret': 'Sv9-vNfocFiTe_NoMRkvNLe_jRRFeESHo8A0Uhyp7e28',
'api_endpoint': 'https://api.figo.me/v3',
'api_endpoint': 'https://api.figo.me',
# string containing comma-separated list of SSL fingerprints
'ssl_fingerprints': ('79:B2:A2:93:00:85:3B:06:92:B1:B5:F2:24:79:48:58:'
'3A:A5:22:0F:C5:CD:E9:49:9A:C8:45:1E:DB:E0:DA:50'),
Expand Down
30 changes: 20 additions & 10 deletions figo/figo.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,18 @@ def _request_api(self, path, data=None, method="GET"):
session.headers.update(self.headers)

for fingerprint in self.fingerprints:
session.mount(self.api_endpoint, FingerprintAdapter(fingerprint))
session.mount(self.api_endpoint, FingerprintAdapter(fingerprint.lower()))
try:
response = session.request(method, complete_path, json=data)
except SSLError as fingerprint_error:
except SSLError:
logging.warn('Fingerprint "%s" was invalid', fingerprint)
else:
break
finally:
session.close()
else:
raise fingerprint_error
raise SSLError


if 200 <= response.status_code < 300 or self._has_error(response.json()):
if response.text == '':
Expand Down Expand Up @@ -388,9 +389,12 @@ def convert_refresh_token(self, refresh_token):
if refresh_token[0] != "R":
raise Exception("Invalid refresh token")

response = self._request_api("/auth/token", data={

data = {
'refresh_token': refresh_token, 'redirect_uri': self.redirect_uri,
'grant_type': 'refresh_token'}, method="POST")
'grant_type': 'refresh_token'}
response = self._request_api("/auth/token", data=data, method="POST")

if 'error' in response:
raise FigoException.from_dict(response)

Expand Down Expand Up @@ -913,12 +917,18 @@ def get_payment_proposals(self):
def start_task(self, task_token_obj):
"""Start the given task.
note:: Deprecated in 3.0.0
`start_task` will be removed in 3.1.0, it is no longer necessary. Task will start
immediately on creation if creation is not deferred. For 3.0.0 start_task will call
task progress once to simulate old behavior for older API versions.
Args:
task_token_obj: TaskToken object of the task to start
"""
return self._request_with_exception("/task/start?id=%s" % task_token_obj.task_token)
self.get_task_state(task_token_obj)

def get_task_state(self, task_token, pin=None, continue_=None, save_pin=None, response=None):
def get_task_state(self, task_token_obj, pin=None, continue_=None, save_pin=None,
response=None):
"""Return the progress of the given task. The kwargs are used to submit additional
content for the task.
Expand All @@ -935,10 +945,10 @@ def get_task_state(self, task_token, pin=None, continue_=None, save_pin=None, re
Returns:
TaskState: Object that indicates the current status of the queried task
"""
logger.debug('Geting task state for: %s', task_token)
logger.debug('Getting task state for: %s', task_token_obj)

data = {
"id": task_token.task_token,
"id": task_token_obj.task_token,
"pin": pin,
"continue": continue_,
"save_pin": save_pin,
Expand All @@ -948,7 +958,7 @@ def get_task_state(self, task_token, pin=None, continue_=None, save_pin=None, re
data = dict((k, v) for k, v in data.items() if v is not None) # noqa, py26 compatibility

return self._query_api_object(TaskState,
"/task/progress?id=%s" % task_token.task_token,
"/task/progress?id=%s" % task_token_obj.task_token,
data, "POST")

def cancel_task(self, task_token_obj):
Expand Down
2 changes: 0 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def figo_connection():

@pytest.fixture(scope='module')
def figo_session(figo_connection, new_user_id):
new_user_id
figo_connection.add_user("Test", new_user_id, PASSWORD)
response = figo_connection.credential_login(new_user_id, PASSWORD)

Expand All @@ -39,7 +38,6 @@ def figo_session(figo_connection, new_user_id):
'accounts=rw',
'transactions=rw',
'user=rw',
'categorization=rw',
'create_user',
]

Expand Down

0 comments on commit dd8a66f

Please sign in to comment.