From dd8a66f435933c49b5c7755981c7b95002d35fe5 Mon Sep 17 00:00:00 2001 From: Berend Kapelle Date: Tue, 27 Feb 2018 11:15:57 +0100 Subject: [PATCH] fix: task_start is not called with response.json() anymore test scope reduced, task_start deprecated --- ChangeLog | 2 ++ figo/credentials.py | 2 +- figo/figo.py | 30 ++++++++++++++++++++---------- tests/conftest.py | 2 -- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 87ae0c7..f10e220 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/figo/credentials.py b/figo/credentials.py index f59d5b6..5a5efc2 100644 --- a/figo/credentials.py +++ b/figo/credentials.py @@ -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'), diff --git a/figo/figo.py b/figo/figo.py index 606a453..55c74aa 100644 --- a/figo/figo.py +++ b/figo/figo.py @@ -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 == '': @@ -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) @@ -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. @@ -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, @@ -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): diff --git a/tests/conftest.py b/tests/conftest.py index 16d0234..affd412 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) @@ -39,7 +38,6 @@ def figo_session(figo_connection, new_user_id): 'accounts=rw', 'transactions=rw', 'user=rw', - 'categorization=rw', 'create_user', ]