1
+ import json
1
2
import os
2
3
3
4
from bunq .sdk .context import ApiContext
5
+ from bunq .sdk .context import BunqContext
4
6
from bunq .sdk .json import converter
5
7
from tests .bunq_test import BunqSdkTestCase
6
8
@@ -13,6 +15,10 @@ class TestApiContext(BunqSdkTestCase):
13
15
14
16
_TMP_FILE_PATH = '/context-save-test.conf'
15
17
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
+
16
22
@classmethod
17
23
def setUpClass (cls ):
18
24
super ().setUpClass ()
@@ -84,3 +90,26 @@ def test_api_context_restore_json(self):
84
90
api_context_restored = self ._API_CONTEXT .from_json (context_json )
85
91
86
92
self .assertEqual (api_context_restored , self ._API_CONTEXT )
93
+
94
+ def test_auto_bunq_context_update (self ):
95
+ api_context : ApiContext = BunqContext .api_context ()
96
+ api_context_json : object = json .loads (api_context .to_json ())
97
+
98
+ api_context_json [self .__FIELD_SESSION_CONTEXT ][
99
+ self .__FIELD_EXPIRE_TIME ] = self .__TIME_STAMP_IN_PAST
100
+
101
+ expired_api_context = ApiContext .from_json (json .dumps (api_context_json ))
102
+
103
+ self .assertNotEqual (api_context .session_context .expiry_time ,
104
+ expired_api_context .session_context .expiry_time )
105
+ self .assertEqual (BunqContext .api_context ().session_context .expiry_time ,
106
+ api_context .session_context .expiry_time )
107
+
108
+ BunqContext .update_api_context (expired_api_context )
109
+ BunqContext .user_context ().refresh_user_context ()
110
+
111
+ self .assertNotEqual (
112
+ BunqContext .api_context ().session_context .expiry_time ,
113
+ api_context .session_context .expiry_time
114
+ )
115
+ self .assertFalse (BunqContext .api_context ().ensure_session_active ())
0 commit comments