Skip to content

Commit e301d9e

Browse files
authored
Merge branch 'develop' into fix_supperfouls_fields_error_bunq/sdk_python#77
2 parents 6ddb9ef + f751550 commit e301d9e

File tree

5 files changed

+58
-12
lines changed

5 files changed

+58
-12
lines changed

bunq/sdk/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ def _request(self, method, uri_relative, request_bytes, params,
112112
uri_relative_with_params = self._append_params_to_uri(uri_relative,
113113
params)
114114
if uri_relative not in self._URIS_NOT_REQUIRING_ACTIVE_SESSION:
115-
self._api_context.ensure_session_active()
115+
if self._api_context.ensure_session_active():
116+
from bunq.sdk.context import BunqContext
117+
118+
BunqContext.update_api_context(self._api_context)
116119

117120
all_headers = self._get_all_headers(
118121
method,

bunq/sdk/context.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,20 @@ def _get_session_timeout_seconds(cls, session_server):
167167
else:
168168
return session_server.user_person.session_timeout
169169

170-
def ensure_session_active(self):
170+
def ensure_session_active(self) -> bool:
171171
"""
172172
Resets the session if it has expired.
173+
174+
:rtype: bool
173175
"""
174176

175177
if not self.is_session_active():
176178
self.reset_session()
177179

180+
return True
181+
182+
return False
183+
178184
def is_session_active(self):
179185
"""
180186
:rtype: bool
@@ -564,3 +570,11 @@ def user_context(cls):
564570
return cls._user_context
565571

566572
raise BunqException(cls._ERROR_USER_CONTEXT_HAS_NOT_BEEN_LOADED)
573+
574+
@classmethod
575+
def update_api_context(cls, api_context: ApiContext):
576+
"""
577+
:type api_context: ApiContext
578+
"""
579+
580+
cls._api_context = api_context

setup.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,11 @@
5656

5757
# Specify the Python versions you support here. In particular, ensure
5858
# that you indicate whether you support Python 2, Python 3 or both.
59-
'Programming Language :: Python :: 3',
60-
'Programming Language :: Python :: 3.3',
61-
'Programming Language :: Python :: 3.4',
62-
'Programming Language :: Python :: 3.5',
6359
'Programming Language :: Python :: 3.6',
6460
],
6561

66-
# Require Python version equal or more than Python 3.
67-
python_requires='>=3',
62+
# Require Python version equal or higher than Python 3.6.
63+
python_requires='>=3.6',
6864

6965
# Keywords related to the project
7066
keywords='open-banking sepa bunq finance api payment',

tests/http/test_api_context.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import json
12
import os
23

34
from bunq.sdk.context import ApiContext
5+
from bunq.sdk.context import BunqContext
46
from bunq.sdk.json import converter
57
from tests.bunq_test import BunqSdkTestCase
68

@@ -13,6 +15,10 @@ class TestApiContext(BunqSdkTestCase):
1315

1416
_TMP_FILE_PATH = '/context-save-test.conf'
1517

18+
__FIELD_SESSION_CONTEXT = 'session_context'
19+
__FIELD_EXPIRE_TIME = 'expiry_time'
20+
__TIME_STAMP_IN_PAST = '2000-04-07 19:50:43.839717'
21+
1622
@classmethod
1723
def setUpClass(cls):
1824
super().setUpClass()
@@ -84,3 +90,30 @@ def test_api_context_restore_json(self):
8490
api_context_restored = self._API_CONTEXT.from_json(context_json)
8591

8692
self.assertEqual(api_context_restored, self._API_CONTEXT)
93+
94+
def test_auto_bunq_context_update(self):
95+
"""
96+
Tests the auto update of BunqContext.
97+
"""
98+
99+
api_context: ApiContext = BunqContext.api_context()
100+
api_context_json: object = json.loads(api_context.to_json())
101+
102+
api_context_json[self.__FIELD_SESSION_CONTEXT][
103+
self.__FIELD_EXPIRE_TIME] = self.__TIME_STAMP_IN_PAST
104+
105+
expired_api_context = ApiContext.from_json(json.dumps(api_context_json))
106+
107+
self.assertNotEqual(api_context.session_context.expiry_time,
108+
expired_api_context.session_context.expiry_time)
109+
self.assertEqual(BunqContext.api_context().session_context.expiry_time,
110+
api_context.session_context.expiry_time)
111+
112+
BunqContext.update_api_context(expired_api_context)
113+
BunqContext.user_context().refresh_user_context()
114+
115+
self.assertNotEqual(
116+
BunqContext.api_context().session_context.expiry_time,
117+
api_context.session_context.expiry_time
118+
)
119+
self.assertFalse(BunqContext.api_context().ensure_session_active())

tests/model/generated/endpoint/test_attachment_public.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
31
from bunq.sdk.client import ApiClient
42
from bunq.sdk.model.generated import endpoint
53
from tests.bunq_test import BunqSdkTestCase
@@ -25,8 +23,10 @@ def test_file_upload_and_retrieval(self):
2523
self._ATTACHMENT_DESCRIPTION,
2624
}
2725

28-
attachment_uuid = endpoint.AttachmentPublic.create(self.attachment_contents,
29-
custom_headers).value
26+
attachment_uuid = endpoint.AttachmentPublic.create(
27+
self.attachment_contents,
28+
custom_headers
29+
).value
3030

3131
contents_from_response = endpoint.AttachmentPublicContent.list(
3232
attachment_uuid).value

0 commit comments

Comments
 (0)