def test_auto_bunq_context_update(self): """ Tests the auto update of BunqContext. """ api_context: ApiContext = BunqContext.api_context() api_context_json: object = json.loads(api_context.to_json()) api_context_json[self.__FIELD_SESSION_CONTEXT][ self.__FIELD_EXPIRE_TIME] = self.__TIME_STAMP_IN_PAST expired_api_context = ApiContext.from_json(json.dumps(api_context_json)) self.assertNotEqual(api_context.session_context.expiry_time, expired_api_context.session_context.expiry_time) self.assertEqual(BunqContext.api_context().session_context.expiry_time, api_context.session_context.expiry_time) BunqContext.update_api_context(expired_api_context) BunqContext.user_context().refresh_user_context() self.assertNotEqual( BunqContext.api_context().session_context.expiry_time, api_context.session_context.expiry_time ) self.assertFalse(BunqContext.api_context().ensure_session_active())
def _request(self, method, uri_relative, request_bytes, params, custom_headers): """ :type method: str :type uri_relative: str :type request_bytes: bytes :type params: dict[str, str] :type custom_headers: dict[str, str] :return: BunqResponseRaw """ uri_relative_with_params = self._append_params_to_uri(uri_relative, params) if uri_relative not in self._URIS_NOT_REQUIRING_ACTIVE_SESSION: if self._api_context.ensure_session_active(): from bunq.sdk.context import BunqContext BunqContext.update_api_context(self._api_context) all_headers = self._get_all_headers( method, uri_relative_with_params, request_bytes, custom_headers ) response = requests.request( method, self._get_uri_full(uri_relative_with_params), data=request_bytes, headers=all_headers, proxies={self._FIELD_PROXY_HTTPS: self._api_context.proxy_url}, ) self._assert_response_success(response) if self._api_context.installation_context is not None: security.validate_response( self._api_context.installation_context.public_key_server, response.status_code, response.content, response.headers ) return self._create_bunq_response_raw(response)